blob: 78cee842f3db3da4f6240898a25383b62d2d3fc3 [file] [log] [blame] [view]
andybonsad92aa32015-08-31 02:27:441# Linux Eclipse Dev
andybons3322f762015-08-24 21:37:092
andybonsad92aa32015-08-31 02:27:443Eclipse can be used on Linux (and probably Windows and Mac) as an IDE for
4developing Chromium. It's unpolished, but here's what works:
andybons3322f762015-08-24 21:37:095
andybonsad92aa32015-08-31 02:27:446* Editing code works well (especially if you're used to it or Visual Studio).
7* Navigating around the code works well. There are multiple ways to do this
8 (F3, control-click, outlines).
9* Building works fairly well and it does a decent job of parsing errors so
10 that you can click and jump to the problem spot.
11* Debugging is hit & miss. You can set breakpoints and view variables. STL
12 containers give it (and gdb) a bit of trouble. Also, the debugger can get
13 into a bad state occasionally and eclipse will need to be restarted.
14* Refactoring seems to work in some instances, but be afraid of refactors that
15 touch a lot of files.
andybons3322f762015-08-24 21:37:0916
andybonsad92aa32015-08-31 02:27:4417[TOC]
andybons3322f762015-08-24 21:37:0918
andybonsad92aa32015-08-31 02:27:4419## Setup
20
21### Get & Configure Eclipse
andybons3322f762015-08-24 21:37:0922
23Eclipse 4.3 (Kepler) is known to work with Chromium for Linux.
andybons3322f762015-08-24 21:37:0924
nodira6074d4c2015-09-01 04:26:4525* [Download](http://www.eclipse.org/downloads/) the distribution appropriate
26 for your OS. For example, for Linux 64-bit/Java 64-bit, use the Linux 64 bit
27 package (Eclipse Packages Tab -> Linux 64 bit (link in bottom right)).
andybonsad92aa32015-08-31 02:27:4428 * Tip: The packaged version of eclipse in distros may not work correctly
29 with the latest CDT plugin (installed below). Best to get them all from
30 the same source.
31 * Googlers: The version installed on Goobuntu works fine. The UI will be
32 much more responsive if you do not install the google3 plug-ins. Just
33 uncheck all the boxes at first launch.
34* Unpack the distribution and edit the eclipse/eclipse.ini to increase the
35 heap available to java. For instance:
36 * Change `-Xms40m` to `-Xms1024m` (minimum heap) and `-Xmx256m` to
37 `-Xmx3072m` (maximum heap).
38 * Googlers: Edit `~/.eclipse/init.sh` to add this:
andybons3322f762015-08-24 21:37:0939
nodira6074d4c2015-09-01 04:26:4540```
41export ECLIPSE_MEM_START="1024M"
42export ECLIPSE_MEM_MAX="3072M"
43```
andybonsad92aa32015-08-31 02:27:4444
45The large heap size prevents out of memory errors if you include many Chrome
46subprojects that Eclipse is maintaining code indices for.
47
48* Turn off Hyperlink detection in the Eclipse preferences. (Window ->
49 Preferences, search for "Hyperlinking, and uncheck "Enable on demand
50 hyperlink style navigation").
51
52Pressing the control key on (for keyboard shortcuts such as copy/paste) can
53trigger the hyperlink detector. This occurs on the UI thread and can result in
54the reading of jar files on the Eclipse classpath, which can tie up the editor
55due to the size of the classpath in Chromium.
56
57### A short word about paths
andybons3322f762015-08-24 21:37:0958
59Before you start setting up your work space - here are a few hints:
andybons3322f762015-08-24 21:37:0960
andybonsad92aa32015-08-31 02:27:4461* Don't put your checkout on a remote file system (e.g. NFS filer). It's too
62 slow both for building and for Eclipse.
63* Make sure there is no file system link in your source path because Ninja
64 will resolve it for a faster build and Eclipse / GDB will get confused.
65 (Note: This means that the source will possibly not reside in your user
66 directory since it would require a link from filer to your local
67 repository.)
68* You may want to start Eclipse from the source root. To do this you can add
69 an icon to your task bar as launcher. It should point to a shell script
70 which will set the current path to your source base, and then start Eclipse.
71 The result would probably look like this:
andybons3322f762015-08-24 21:37:0972
andybonsad92aa32015-08-31 02:27:4473 ```shell
74 ~/.bashrc
75 cd /usr/local/google/chromium/src
76 export PATH=/home/skuhne/depot_tools:/usr/local/google/goma/goma:/opt/eclipse:/usr/local/symlinks:/usr/local/scripts:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
77 /opt/eclipse/eclipse -vm /usr/bin/java
78 ```
andybons3322f762015-08-24 21:37:0979
andybonsad92aa32015-08-31 02:27:4480(Note: Things work fine for me without launching Eclipse from a special
81directory. [email protected] 2012-06-1)
andybons3322f762015-08-24 21:37:0982
andybonsad92aa32015-08-31 02:27:4483### Run Eclipse & Set your workspace
andybons3322f762015-08-24 21:37:0984
andybonsad92aa32015-08-31 02:27:4485Run eclipse/eclipse in a way that your regular build environment (export CC,
86CXX, etc...) will be visible to the eclipse process.
andybons3322f762015-08-24 21:37:0987
andybonsad92aa32015-08-31 02:27:4488Set the Workspace to be a directory on a local disk (e.g.
89`/work/workspaces/chrome`). Placing it on an NFS share is not recommended --
90it's too slow and Eclipse will block on access. Don't put the workspace in the
91same directory as your checkout.
andybons3322f762015-08-24 21:37:0992
andybonsad92aa32015-08-31 02:27:4493### Install the C Development Tools ("CDT")
andybons3322f762015-08-24 21:37:0994
andybonsad92aa32015-08-31 02:27:44951. From the Help menu, select Install New Software...
andybons10c162b2015-08-31 15:37:4096 1. Select the 'Workd with' URL for the CDT
nodira6074d4c2015-09-01 04:26:4597 If it's not there you can click Add... and add it.
98 See https://eclipse.org/cdt/downloads.php for up to date versions,
99 e.g. with CDT 8.7.0 for Eclipse Mars, use
100 http://download.eclipse.org/tools/cdt/releases/8.7
andybonsad92aa32015-08-31 02:27:44101 1. Googlers: We have a local mirror, but be sure you run prodaccess before
102 trying to use it.
1031. Select & install the Main and Optional features.
1041. Restart Eclipse
1051. Go to Window > Open Perspective > Other... > C/C++ to switch to the C++
106 perspective (window layout).
1071. Right-click on the "Java" perspective in the top-right corner and select
108 "Close" to remove it.
andybons3322f762015-08-24 21:37:09109
andybonsad92aa32015-08-31 02:27:44110### Create your project(s)
111
112First, turn off automatic workspace refresh and automatic building, as Eclipse
113tries to do these too often and gets confused:
114
1151. Open Window > Preferences
1161. Search for "workspace"
1171. Turn off "Build automatically"
1181. Turn off "Refresh using native hooks or polling"
1191. Click "Apply"
andybons3322f762015-08-24 21:37:09120
jamescook3950e082016-05-06 22:13:45121Chromium uses C++11, so tell the indexer about it. Otherwise it will get
122confused about things like std::unique_ptr.
123
1241. Open Window > Preferences > C/C++ > Build > Settings > Discovery >
125 CDT GCC Build-in Compiler Settings
1261. In the text box entitled Command to get compiler specs append "-std=c++11"
127
andybons3322f762015-08-24 21:37:09128Create a single Eclipse project for everything:
129
andybonsad92aa32015-08-31 02:27:441301. From the File menu, select New > Project...
1311. Select C/C++ Project > Makefile Project with Existing Code
1321. Name the project the exact name of the directory: "src"
1331. Provide a path to the code, like /work/chromium/src
1341. Select toolchain: Linux GCC
1351. Click Finish.
andybons3322f762015-08-24 21:37:09136
andybonsad92aa32015-08-31 02:27:44137Chromium has a huge amount of code, enough that Eclipse can take a very long
138time to perform operations like "go to definition" and "open resource". You need
139to set it up to operate on a subset of the code.
andybons3322f762015-08-24 21:37:09140
141In the Project Explorer on the left side:
142
andybonsad92aa32015-08-31 02:27:441431. Right-click on "src" and select "Properties..."
1441. Open Resource > Resource Filters
1451. Click "Add..."
1461. Add the following filter:
147 * Include only
148 * Files, all children (recursive)
149 * Name matches
mfomitchev95f20f12016-06-09 17:37:34150 `.*\.(c|cc|cpp|h|mm|inl|idl|js|json|css|html|gyp|gypi|grd|grdp|gn|gni|mojom)`
andybonsad92aa32015-08-31 02:27:44151 regular expression
1521. Add another filter:
153 * Exclude all
154 * Folders
155 * Name matches `out_.*|\.git|\.svn|LayoutTests` regular expression
156 * If you aren't working on WebKit, adding `|WebKit` will remove more
157 files
1581. Click "OK"
andybons3322f762015-08-24 21:37:09159
andybonsad92aa32015-08-31 02:27:44160Don't exclude the primary "out" directory, as it contains generated header files
161for things like string resources and Eclipse will miss a lot of symbols if you
162do.
andybons3322f762015-08-24 21:37:09163
andybonsad92aa32015-08-31 02:27:44164Eclipse will refresh the workspace and start indexing your code. It won't find
165most header files, however. Give it more help finding them:
andybons3322f762015-08-24 21:37:09166
andybonsad92aa32015-08-31 02:27:441671. Open Window > Preferences
1681. Search for "Indexer"
1691. Turn on "Allow heuristic resolution of includes"
1701. Select "Use active build configuration"
1711. Set Cache limits > Index database > Limit relative... to 20%
1721. Set Cache limits > Index database > Absolute limit to 256 MB
1731. Click "OK"
andybons3322f762015-08-24 21:37:09174
andybonsad92aa32015-08-31 02:27:44175Now the indexer will find many more include files, regardless of which approach
176you take below.
andybons3322f762015-08-24 21:37:09177
andybonsad92aa32015-08-31 02:27:44178#### Optional: Manual header paths and symbols
andybons3322f762015-08-24 21:37:09179
andybonsad92aa32015-08-31 02:27:44180You can manually tell Eclipse where to find header files, which will allow it to
181create the source code index before you do a real build.
182
1831. Right-click on "src" and select "Properties..."
andybons3322f762015-08-24 21:37:09184 * Open C++ General > Paths and Symbols > Includes
185 * Click "GNU C++"
186 * Click "Add..."
andybonsad92aa32015-08-31 02:27:44187 * Add `/path/to/chromium/src`
andybons3322f762015-08-24 21:37:09188 * Check "Add to all configurations" and "Add to all languages"
andybonsad92aa32015-08-31 02:27:441891. Repeat the above for:
190 * `/path/to/chromium/src/testing/gtest/include`
andybons3322f762015-08-24 21:37:09191
192You may also find it helpful to define some symbols.
193
andybonsad92aa32015-08-31 02:27:441941. Add `OS_LINUX`:
andybons3322f762015-08-24 21:37:09195 * Select the "Symbols" tab
196 * Click "GNU C++"
197 * Click "Add..."
andybonsad92aa32015-08-31 02:27:44198 * Add name `OS_LINUX` with value 1
andybons3322f762015-08-24 21:37:09199 * Click "Add to all configurations" and "Add to all languages"
andybonsad92aa32015-08-31 02:27:442001. Repeat for `ENABLE_EXTENSIONS 1`
2011. Repeat for `HAS_OUT_OF_PROC_TEST_RUNNER 1`
2021. Click "OK".
2031. Eclipse will ask if you want to rebuild the index. Click "Yes".
andybons3322f762015-08-24 21:37:09204
205Let the C++ indexer run. It will take a while (10s of minutes).
206
andybonsad92aa32015-08-31 02:27:44207### Optional: Building inside Eclipse
andybons3322f762015-08-24 21:37:09208
andybonsad92aa32015-08-31 02:27:44209This allows Eclipse to automatically discover include directories and symbols.
210If you use gold or ninja (both recommended) you'll need to tell Eclipse about
211your path.
212
2131. echo $PATH from a shell and copy it to the clipboard
2141. Open Window > Preferences > C/C++ > Build > Environment
2151. Select "Replace native environment with specified one" (since gold and ninja
216 must be at the start of your path)
2171. Click "Add..."
2181. For name, enter `PATH`
2191. For value, paste in your path with the ninja and gold directories.
2201. Click "OK"
andybons3322f762015-08-24 21:37:09221
222To create a Make target:
223
andybonsad92aa32015-08-31 02:27:442241. From the Window menu, select Show View > Make Target
2251. In the Make Target view, right-click on the project and select New...
2261. name the target (e.g. base\_unittests)
2271. Unclick the Build Command: Use builder Settings and type whatever build
228 command you would use to build this target (e.g.
229 `ninja -C out/Debug base_unittests`).
2301. Return to the project properties page a under the C/C++ Build, change the
231 Build Location/Build Directory to be /path/to/chromium/src
232 1. In theory `${workspace_loc}` should work, but it doesn't for me.
233 1. If you put your workspace in `/path/to/chromium`, then
234 `${workspace_loc:/src}` will work too.
2351. Now in the Make Targets view, select the target and click the hammer icon
236 (Build Make Target).
andybons3322f762015-08-24 21:37:09237
andybonsad92aa32015-08-31 02:27:44238You should see the build proceeding in the Console View and errors will be
239parsed and appear in the Problems View. (Note that sometimes multi-line compiler
240errors only show up partially in the Problems view and you'll want to look at
241the full error in the Console).
andybons3322f762015-08-24 21:37:09242
andybonsad92aa32015-08-31 02:27:44243(Eclipse 3.8 has a bug where the console scrolls too slowly if you're doing a
244fast build, e.g. with goma. To work around, go to Window > Preferences and
245search for "console". Under C/C++ console, set "Limit console output" to
2462147483647, the maximum value.)
andybons3322f762015-08-24 21:37:09247
andybonsad92aa32015-08-31 02:27:44248### Optional: Multiple build targets
andybons3322f762015-08-24 21:37:09249
andybonsad92aa32015-08-31 02:27:44250If you want to build multiple different targets in Eclipse (`chrome`,
251`unit_tests`, etc.):
andybons3322f762015-08-24 21:37:09252
andybonsad92aa32015-08-31 02:27:442531. Window > Show Toolbar (if you had it off)
2541. Turn on special toolbar menu item (hammer) or menu bar item (Project > Build
255 configurations > Set Active > ...)
256 1. Window > Customize Perspective... > "Command Groups Availability"
257 1. Check "Build configuration"
2581. Add more Build targets
259 1. Project > Properties > C/C++ Build > Manage Configurations
260 1. Select "New..."
261 1. Duplicate from current and give it a name like "Unit tests".
262 1. Change under “Behavior” > Build > the target to e.g. `unit_tests`.
andybons3322f762015-08-24 21:37:09263
andybonsad92aa32015-08-31 02:27:44264You can also drag the toolbar to the bottom of your window to save vertical
265space.
andybons3322f762015-08-24 21:37:09266
andybonsad92aa32015-08-31 02:27:44267### Optional: Debugging
andybons3322f762015-08-24 21:37:09268
andybonsad92aa32015-08-31 02:27:442691. From the toolbar at the top, click the arrow next to the debug icon and
270 select Debug Configurations...
2711. Select C/C++ Application and click the New Launch Configuration icon. This
272 will create a new run/debug con figuration under the C/C++ Application header.
2731. Name it something useful (e.g. `base_unittests`).
2741. Under the Main Tab, enter the path to the executable (e.g.
275 `.../out/Debug/base_unittests`)
2761. Select the Debugger Tab, select Debugger: gdb and unclick "Stop on startup
277 in (main)" unless you want this.
2781. Set a breakpoint somewhere in your code and click the debug icon to start
279 debugging.
andybons3322f762015-08-24 21:37:09280
andybonsad92aa32015-08-31 02:27:44281### Optional: Accurate symbol information
andybons3322f762015-08-24 21:37:09282
andybonsad92aa32015-08-31 02:27:44283If setup properly, Eclipse can do a great job of semantic navigation of C++ code
284(showing type hierarchies, finding all references to a particular method even
285when other classes have methods of the same name, etc.). But doing this well
286requires the Eclipse knows correct include paths and pre-processor definitions.
287After fighting with with a number of approaches, I've found the below to work
288best for me.
andybons3322f762015-08-24 21:37:09289
brettw20d800c2016-04-12 00:10:49290*The instrcutions below are out-of-date since it references GYP. Please see
291`gn help gen` for how to generate an Eclipse CDT file in GN. If you use
292Eclipse and make it work, please update this documentation.*
293
andybonsad92aa32015-08-31 02:27:442941. From a shell in your src directory, run
295 `GYP_GENERATORS=ninja,eclipse build/gyp_chromium`
296 1. This generates <project root>/out/Debug/eclipse-cdt-settings.xml which
297 is used below.
298 1. This creates a single list of include directories and preprocessor
299 definitions to be used for all source files, and so is a little
300 inaccurate. Here are some tips for compensating for the limitations:
301 1. Use `-R <target>` to restrict the output to considering only certain
302 targets (avoiding unnecessary includes that are likely to cause
303 trouble). Eg. for a blink project, use `-R blink`.
304 1. If you care about blink, move 'third\_party/Webkit/Source' to the
305 top of the list to better resolve ambiguous include paths (eg.
306 `config.h`).
3071. Import paths and symbols
308 1. Right click on the project and select Properties > C/C++ General > Paths
309 and Symbols
310 1. Click Restore Defaults to clear any old settings
311 1. Click Import Settings... > Browse... and select
312 `<project root>/out/Debug/eclipse-cdt-settings.xml`
313 1. Click the Finish button. The entire preferences dialog should go away.
314 1. Right click on the project and select Index > Rebuild
andybons3322f762015-08-24 21:37:09315
andybonsad92aa32015-08-31 02:27:44316### Alternative: Per-file accurate include/pre-processor information
andybons3322f762015-08-24 21:37:09317
andybonsad92aa32015-08-31 02:27:44318Instead of generating a fixed list of include paths and pre-processor
319definitions for a project (above), it is also possible to have Eclipse determine
320the correct setting on a file-by-file basis using a built output parser. I
321(rbyers) used this successfully for a long time, but it doesn't seem much better
322in practice than the simpler (and less bug-prone) approach above.
andybons3322f762015-08-24 21:37:09323
andybonsad92aa32015-08-31 02:27:443241. Install the latest version of Eclipse IDE for C/C++ developers
325 ([Juno SR1](http://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers/junosr1)
326 at the time of this writing)
3271. Setup build to generate a build log that includes the g++ command lines for
328 the files you want to index:
329 1. Project Properties -> C/C++ Build
330 1. Uncheck "Use default build command"
331 1. Enter your build command, eg: `ninja -v`
332 1. Note that for better performance, you can use a command that
333 doesn't actually builds, just prints the commands that would be
334 run. For ninja/make this means adding -n. This only prints the
335 compile commands for changed files (so be sure to move your
336 existing out directory out of the way temporarily to force a
337 full "build"). ninja also supports "-t commands" which will
338 print all build commands for the specified target and runs even
339 faster as it doesn't have to check file timestamps.
340 1. Build directory: your build path including out/Debug
341 1. Note that for the relative paths to be parsed correctly you
342 can't use ninja's `-C <dir>` to change directories as you might
343 from the command line.
344 1. Build: potentially change `all` to the target you want to analyze,
345 eg. `chrome`
346 1. Deselect 'clean'
347 1. If you're using Ninja, you need to teach eclipse to ignore the prefix it
348 adds (eg. `[10/1234]` to each line in build output):
349 1. Project properties -> C/C++ General -> Preprocessor includes
350 1. Providers -> CDT GCC Build Output Parser -> Compiler command pattern
351 1. `(\[.*\] )?((gcc)|([gc]\+\+)|(clang(\+\+)?))`
352 1. Note that there appears to be a bug with "Share setting entries
353 between projects" - it will keep resetting to off. I suggest using
354 per-project settings and using the "folder" as the container to keep
355 discovered entries ("file" may work as well).
356 1. Eclipse / GTK has bugs where lots of output to the build console can
357 slow down the UI dramatically and cause it to hang (basically spends all
358 it's time trying to position the cursor correctly in the build console
359 window). To avoid this, close the console window and disable
360 automatically opening it on build:
361 1. Preferences->C/C++->Build->Console -> Uncheck "Open console when
362 building"
363 1. note you can still see the build log in
364 `<workspace>/.metadata/.plugins/org.eclipse.cdt.ui`
3651. Now build the project (select project, click on hammer). If all went well:
366 1. Right click on a cpp file -> properties -> C/C++ general -> Preprocessor
367 includes -> GNU C++ -> CDT GCC Build output Parser
368 1. You will be able to expand and see all the include paths and
369 pre-processor definitions used for this file
3701. Rebuild index (right-click on project, index, rebuild). If all went well:
371 1. Open a CPP file and look at problems windows
372 1. Should be no (or very few) errors
373 1. Should be able to hit F3 on most symbols and jump to their definitioin
374 1. CDT has some issues with complex C++ syntax like templates (eg.
375 `PassOwnPtr` functions)
376 1. See
377 [this page](http://wiki.eclipse.org/CDT/User/FAQ#Why_does_Open_Declaration_.28F3.29_not_work.3F_.28also_applies_to_other_functions_using_the_indexer.29)
378 for more information.
andybons3322f762015-08-24 21:37:09379
andybonsad92aa32015-08-31 02:27:44380### Optional: static code and style guide analysis using cpplint.py
andybons3322f762015-08-24 21:37:09381
andybonsad92aa32015-08-31 02:27:443821. From the toolbar at the top, click the Project -> Properties and go to
383 C/C++Build.
384 1. Click on the right side of the pop up windows, "Manage
385 Configurations...", then on New, and give it a name, f.i. "Lint current
386 file", and close the small window, then select it in the Configuration
387 drop down list.
388 1. Under Builder settings tab, unclick "Use default build command" and type
389 as build command the full path to your `depot_tools/cpplint.py`
390 1. Under behaviour tab, unselect Clean, select Build(incremental build) and
391 in Make build target, add `--verbose=0 ${selected_resource_loc}`
392 1. Go back to the left side of the current window, and to C/C++Build ->
393 Settings, and click on error parsers tab, make sure CDT GNU C/C++ Error
394 Parser, CDT pushd/popd CWD Locator are set, then click Apply and OK.
3951. Select a file and click on the hammer icon drop down triangle next to it,
396 and make sure the build configuration is selected "Lint current file", then
397 click on the hammer.
3981. Note: If you get the `cpplint.py help` output, make sure you have selected a
399 file, by clicking inside the editor window or on its tab header, and make
400 sure the editor is not maximized inside Eclipse, i.e. you should see more
401 subwindows around.
402
403### Additional tips
404
4051. Mozilla's
406 [Eclipse CDT guide](https://developer.mozilla.org/en-US/docs/Eclipse_CDT)
407 is helpful:
4081. For improved performance, I use medium-granularity projects (eg. one for
409 WebKit/Source) instead of putting all of 'src/' in one project.
4101. For working in Blink (which uses WebKit code style), feel free to use
411 [this](https://drive.google.com/file/d/0B2LVVIKSxUVYM3R6U0tUa1dmY0U/view?usp=sharing)
412 code-style formatter XML profile