blob: 89ec5f08d2a1cabde51c0e22a249b275613735c6 [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
andybonsad92aa32015-08-31 02:27:4425* Download the distribution appropriate for your OS. For example, for Linux
26 64-bit/Java 64-bit, use the Linux 64 bit package from
27 http://www.eclipse.org/downloads/ (Eclipse Packages Tab -> Linux 64 bit
28 (link in bottom right)).
29 * Tip: The packaged version of eclipse in distros may not work correctly
30 with the latest CDT plugin (installed below). Best to get them all from
31 the same source.
32 * Googlers: The version installed on Goobuntu works fine. The UI will be
33 much more responsive if you do not install the google3 plug-ins. Just
34 uncheck all the boxes at first launch.
35* Unpack the distribution and edit the eclipse/eclipse.ini to increase the
36 heap available to java. For instance:
37 * Change `-Xms40m` to `-Xms1024m` (minimum heap) and `-Xmx256m` to
38 `-Xmx3072m` (maximum heap).
39 * Googlers: Edit `~/.eclipse/init.sh` to add this:
andybons3322f762015-08-24 21:37:0940
andybonsad92aa32015-08-31 02:27:4441 export ECLIPSE_MEM_START="1024M"
42 export ECLIPSE_MEM_MAX="3072M"
43
44The large heap size prevents out of memory errors if you include many Chrome
45subprojects that Eclipse is maintaining code indices for.
46
47* Turn off Hyperlink detection in the Eclipse preferences. (Window ->
48 Preferences, search for "Hyperlinking, and uncheck "Enable on demand
49 hyperlink style navigation").
50
51Pressing the control key on (for keyboard shortcuts such as copy/paste) can
52trigger the hyperlink detector. This occurs on the UI thread and can result in
53the reading of jar files on the Eclipse classpath, which can tie up the editor
54due to the size of the classpath in Chromium.
55
56### A short word about paths
andybons3322f762015-08-24 21:37:0957
58Before you start setting up your work space - here are a few hints:
andybons3322f762015-08-24 21:37:0959
andybonsad92aa32015-08-31 02:27:4460* Don't put your checkout on a remote file system (e.g. NFS filer). It's too
61 slow both for building and for Eclipse.
62* Make sure there is no file system link in your source path because Ninja
63 will resolve it for a faster build and Eclipse / GDB will get confused.
64 (Note: This means that the source will possibly not reside in your user
65 directory since it would require a link from filer to your local
66 repository.)
67* You may want to start Eclipse from the source root. To do this you can add
68 an icon to your task bar as launcher. It should point to a shell script
69 which will set the current path to your source base, and then start Eclipse.
70 The result would probably look like this:
andybons3322f762015-08-24 21:37:0971
andybonsad92aa32015-08-31 02:27:4472 ```shell
73 ~/.bashrc
74 cd /usr/local/google/chromium/src
75 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
76 /opt/eclipse/eclipse -vm /usr/bin/java
77 ```
andybons3322f762015-08-24 21:37:0978
andybonsad92aa32015-08-31 02:27:4479(Note: Things work fine for me without launching Eclipse from a special
80directory. [email protected] 2012-06-1)
andybons3322f762015-08-24 21:37:0981
andybonsad92aa32015-08-31 02:27:4482### Run Eclipse & Set your workspace
andybons3322f762015-08-24 21:37:0983
andybonsad92aa32015-08-31 02:27:4484Run eclipse/eclipse in a way that your regular build environment (export CC,
85CXX, etc...) will be visible to the eclipse process.
andybons3322f762015-08-24 21:37:0986
andybonsad92aa32015-08-31 02:27:4487Set the Workspace to be a directory on a local disk (e.g.
88`/work/workspaces/chrome`). Placing it on an NFS share is not recommended --
89it's too slow and Eclipse will block on access. Don't put the workspace in the
90same directory as your checkout.
andybons3322f762015-08-24 21:37:0991
andybonsad92aa32015-08-31 02:27:4492### Install the C Development Tools ("CDT")
andybons3322f762015-08-24 21:37:0993
andybonsad92aa32015-08-31 02:27:44941. From the Help menu, select Install New Software...
95 1. Select the URL for the CDT,
96 http://download.eclipse.org/tools/cdt/releases/kepler
97 1. If it's not there you can click Add... and add it.
98 1. Googlers: We have a local mirror, but be sure you run prodaccess before
99 trying to use it.
1001. Select & install the Main and Optional features.
1011. Restart Eclipse
1021. Go to Window > Open Perspective > Other... > C/C++ to switch to the C++
103 perspective (window layout).
1041. Right-click on the "Java" perspective in the top-right corner and select
105 "Close" to remove it.
andybons3322f762015-08-24 21:37:09106
andybonsad92aa32015-08-31 02:27:44107### Create your project(s)
108
109First, turn off automatic workspace refresh and automatic building, as Eclipse
110tries to do these too often and gets confused:
111
1121. Open Window > Preferences
1131. Search for "workspace"
1141. Turn off "Build automatically"
1151. Turn off "Refresh using native hooks or polling"
1161. Click "Apply"
andybons3322f762015-08-24 21:37:09117
118Create a single Eclipse project for everything:
119
andybonsad92aa32015-08-31 02:27:441201. From the File menu, select New > Project...
1211. Select C/C++ Project > Makefile Project with Existing Code
1221. Name the project the exact name of the directory: "src"
1231. Provide a path to the code, like /work/chromium/src
1241. Select toolchain: Linux GCC
1251. Click Finish.
andybons3322f762015-08-24 21:37:09126
andybonsad92aa32015-08-31 02:27:44127Chromium has a huge amount of code, enough that Eclipse can take a very long
128time to perform operations like "go to definition" and "open resource". You need
129to set it up to operate on a subset of the code.
andybons3322f762015-08-24 21:37:09130
131In the Project Explorer on the left side:
132
andybonsad92aa32015-08-31 02:27:441331. Right-click on "src" and select "Properties..."
1341. Open Resource > Resource Filters
1351. Click "Add..."
1361. Add the following filter:
137 * Include only
138 * Files, all children (recursive)
139 * Name matches
140 `.*\.(c|cc|cpp|h|mm|inl|idl|js|json|css|html|gyp|gypi|grd|grdp|gn)`
141 regular expression
1421. Add another filter:
143 * Exclude all
144 * Folders
145 * Name matches `out_.*|\.git|\.svn|LayoutTests` regular expression
146 * If you aren't working on WebKit, adding `|WebKit` will remove more
147 files
1481. Click "OK"
andybons3322f762015-08-24 21:37:09149
andybonsad92aa32015-08-31 02:27:44150Don't exclude the primary "out" directory, as it contains generated header files
151for things like string resources and Eclipse will miss a lot of symbols if you
152do.
andybons3322f762015-08-24 21:37:09153
andybonsad92aa32015-08-31 02:27:44154Eclipse will refresh the workspace and start indexing your code. It won't find
155most header files, however. Give it more help finding them:
andybons3322f762015-08-24 21:37:09156
andybonsad92aa32015-08-31 02:27:441571. Open Window > Preferences
1581. Search for "Indexer"
1591. Turn on "Allow heuristic resolution of includes"
1601. Select "Use active build configuration"
1611. Set Cache limits > Index database > Limit relative... to 20%
1621. Set Cache limits > Index database > Absolute limit to 256 MB
1631. Click "OK"
andybons3322f762015-08-24 21:37:09164
andybonsad92aa32015-08-31 02:27:44165Now the indexer will find many more include files, regardless of which approach
166you take below.
andybons3322f762015-08-24 21:37:09167
andybonsad92aa32015-08-31 02:27:44168#### Optional: Manual header paths and symbols
andybons3322f762015-08-24 21:37:09169
andybonsad92aa32015-08-31 02:27:44170You can manually tell Eclipse where to find header files, which will allow it to
171create the source code index before you do a real build.
172
1731. Right-click on "src" and select "Properties..."
andybons3322f762015-08-24 21:37:09174 * Open C++ General > Paths and Symbols > Includes
175 * Click "GNU C++"
176 * Click "Add..."
andybonsad92aa32015-08-31 02:27:44177 * Add `/path/to/chromium/src`
andybons3322f762015-08-24 21:37:09178 * Check "Add to all configurations" and "Add to all languages"
andybonsad92aa32015-08-31 02:27:441791. Repeat the above for:
180 * `/path/to/chromium/src/testing/gtest/include`
andybons3322f762015-08-24 21:37:09181
182You may also find it helpful to define some symbols.
183
andybonsad92aa32015-08-31 02:27:441841. Add `OS_LINUX`:
andybons3322f762015-08-24 21:37:09185 * Select the "Symbols" tab
186 * Click "GNU C++"
187 * Click "Add..."
andybonsad92aa32015-08-31 02:27:44188 * Add name `OS_LINUX` with value 1
andybons3322f762015-08-24 21:37:09189 * Click "Add to all configurations" and "Add to all languages"
andybonsad92aa32015-08-31 02:27:441901. Repeat for `ENABLE_EXTENSIONS 1`
1911. Repeat for `HAS_OUT_OF_PROC_TEST_RUNNER 1`
1921. Click "OK".
1931. Eclipse will ask if you want to rebuild the index. Click "Yes".
andybons3322f762015-08-24 21:37:09194
195Let the C++ indexer run. It will take a while (10s of minutes).
196
andybonsad92aa32015-08-31 02:27:44197### Optional: Building inside Eclipse
andybons3322f762015-08-24 21:37:09198
andybonsad92aa32015-08-31 02:27:44199This allows Eclipse to automatically discover include directories and symbols.
200If you use gold or ninja (both recommended) you'll need to tell Eclipse about
201your path.
202
2031. echo $PATH from a shell and copy it to the clipboard
2041. Open Window > Preferences > C/C++ > Build > Environment
2051. Select "Replace native environment with specified one" (since gold and ninja
206 must be at the start of your path)
2071. Click "Add..."
2081. For name, enter `PATH`
2091. For value, paste in your path with the ninja and gold directories.
2101. Click "OK"
andybons3322f762015-08-24 21:37:09211
212To create a Make target:
213
andybonsad92aa32015-08-31 02:27:442141. From the Window menu, select Show View > Make Target
2151. In the Make Target view, right-click on the project and select New...
2161. name the target (e.g. base\_unittests)
2171. Unclick the Build Command: Use builder Settings and type whatever build
218 command you would use to build this target (e.g.
219 `ninja -C out/Debug base_unittests`).
2201. Return to the project properties page a under the C/C++ Build, change the
221 Build Location/Build Directory to be /path/to/chromium/src
222 1. In theory `${workspace_loc}` should work, but it doesn't for me.
223 1. If you put your workspace in `/path/to/chromium`, then
224 `${workspace_loc:/src}` will work too.
2251. Now in the Make Targets view, select the target and click the hammer icon
226 (Build Make Target).
andybons3322f762015-08-24 21:37:09227
andybonsad92aa32015-08-31 02:27:44228You should see the build proceeding in the Console View and errors will be
229parsed and appear in the Problems View. (Note that sometimes multi-line compiler
230errors only show up partially in the Problems view and you'll want to look at
231the full error in the Console).
andybons3322f762015-08-24 21:37:09232
andybonsad92aa32015-08-31 02:27:44233(Eclipse 3.8 has a bug where the console scrolls too slowly if you're doing a
234fast build, e.g. with goma. To work around, go to Window > Preferences and
235search for "console". Under C/C++ console, set "Limit console output" to
2362147483647, the maximum value.)
andybons3322f762015-08-24 21:37:09237
andybonsad92aa32015-08-31 02:27:44238### Optional: Multiple build targets
andybons3322f762015-08-24 21:37:09239
andybonsad92aa32015-08-31 02:27:44240If you want to build multiple different targets in Eclipse (`chrome`,
241`unit_tests`, etc.):
andybons3322f762015-08-24 21:37:09242
andybonsad92aa32015-08-31 02:27:442431. Window > Show Toolbar (if you had it off)
2441. Turn on special toolbar menu item (hammer) or menu bar item (Project > Build
245 configurations > Set Active > ...)
246 1. Window > Customize Perspective... > "Command Groups Availability"
247 1. Check "Build configuration"
2481. Add more Build targets
249 1. Project > Properties > C/C++ Build > Manage Configurations
250 1. Select "New..."
251 1. Duplicate from current and give it a name like "Unit tests".
252 1. Change under “Behavior” > Build > the target to e.g. `unit_tests`.
andybons3322f762015-08-24 21:37:09253
andybonsad92aa32015-08-31 02:27:44254You can also drag the toolbar to the bottom of your window to save vertical
255space.
andybons3322f762015-08-24 21:37:09256
andybonsad92aa32015-08-31 02:27:44257### Optional: Debugging
andybons3322f762015-08-24 21:37:09258
andybonsad92aa32015-08-31 02:27:442591. From the toolbar at the top, click the arrow next to the debug icon and
260 select Debug Configurations...
2611. Select C/C++ Application and click the New Launch Configuration icon. This
262 will create a new run/debug con figuration under the C/C++ Application header.
2631. Name it something useful (e.g. `base_unittests`).
2641. Under the Main Tab, enter the path to the executable (e.g.
265 `.../out/Debug/base_unittests`)
2661. Select the Debugger Tab, select Debugger: gdb and unclick "Stop on startup
267 in (main)" unless you want this.
2681. Set a breakpoint somewhere in your code and click the debug icon to start
269 debugging.
andybons3322f762015-08-24 21:37:09270
andybonsad92aa32015-08-31 02:27:44271### Optional: Accurate symbol information
andybons3322f762015-08-24 21:37:09272
andybonsad92aa32015-08-31 02:27:44273If setup properly, Eclipse can do a great job of semantic navigation of C++ code
274(showing type hierarchies, finding all references to a particular method even
275when other classes have methods of the same name, etc.). But doing this well
276requires the Eclipse knows correct include paths and pre-processor definitions.
277After fighting with with a number of approaches, I've found the below to work
278best for me.
andybons3322f762015-08-24 21:37:09279
andybonsad92aa32015-08-31 02:27:442801. From a shell in your src directory, run
281 `GYP_GENERATORS=ninja,eclipse build/gyp_chromium`
282 1. This generates <project root>/out/Debug/eclipse-cdt-settings.xml which
283 is used below.
284 1. This creates a single list of include directories and preprocessor
285 definitions to be used for all source files, and so is a little
286 inaccurate. Here are some tips for compensating for the limitations:
287 1. Use `-R <target>` to restrict the output to considering only certain
288 targets (avoiding unnecessary includes that are likely to cause
289 trouble). Eg. for a blink project, use `-R blink`.
290 1. If you care about blink, move 'third\_party/Webkit/Source' to the
291 top of the list to better resolve ambiguous include paths (eg.
292 `config.h`).
2931. Import paths and symbols
294 1. Right click on the project and select Properties > C/C++ General > Paths
295 and Symbols
296 1. Click Restore Defaults to clear any old settings
297 1. Click Import Settings... > Browse... and select
298 `<project root>/out/Debug/eclipse-cdt-settings.xml`
299 1. Click the Finish button. The entire preferences dialog should go away.
300 1. Right click on the project and select Index > Rebuild
andybons3322f762015-08-24 21:37:09301
andybonsad92aa32015-08-31 02:27:44302### Alternative: Per-file accurate include/pre-processor information
andybons3322f762015-08-24 21:37:09303
andybonsad92aa32015-08-31 02:27:44304Instead of generating a fixed list of include paths and pre-processor
305definitions for a project (above), it is also possible to have Eclipse determine
306the correct setting on a file-by-file basis using a built output parser. I
307(rbyers) used this successfully for a long time, but it doesn't seem much better
308in practice than the simpler (and less bug-prone) approach above.
andybons3322f762015-08-24 21:37:09309
andybonsad92aa32015-08-31 02:27:443101. Install the latest version of Eclipse IDE for C/C++ developers
311 ([Juno SR1](http://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers/junosr1)
312 at the time of this writing)
3131. Setup build to generate a build log that includes the g++ command lines for
314 the files you want to index:
315 1. Project Properties -> C/C++ Build
316 1. Uncheck "Use default build command"
317 1. Enter your build command, eg: `ninja -v`
318 1. Note that for better performance, you can use a command that
319 doesn't actually builds, just prints the commands that would be
320 run. For ninja/make this means adding -n. This only prints the
321 compile commands for changed files (so be sure to move your
322 existing out directory out of the way temporarily to force a
323 full "build"). ninja also supports "-t commands" which will
324 print all build commands for the specified target and runs even
325 faster as it doesn't have to check file timestamps.
326 1. Build directory: your build path including out/Debug
327 1. Note that for the relative paths to be parsed correctly you
328 can't use ninja's `-C <dir>` to change directories as you might
329 from the command line.
330 1. Build: potentially change `all` to the target you want to analyze,
331 eg. `chrome`
332 1. Deselect 'clean'
333 1. If you're using Ninja, you need to teach eclipse to ignore the prefix it
334 adds (eg. `[10/1234]` to each line in build output):
335 1. Project properties -> C/C++ General -> Preprocessor includes
336 1. Providers -> CDT GCC Build Output Parser -> Compiler command pattern
337 1. `(\[.*\] )?((gcc)|([gc]\+\+)|(clang(\+\+)?))`
338 1. Note that there appears to be a bug with "Share setting entries
339 between projects" - it will keep resetting to off. I suggest using
340 per-project settings and using the "folder" as the container to keep
341 discovered entries ("file" may work as well).
342 1. Eclipse / GTK has bugs where lots of output to the build console can
343 slow down the UI dramatically and cause it to hang (basically spends all
344 it's time trying to position the cursor correctly in the build console
345 window). To avoid this, close the console window and disable
346 automatically opening it on build:
347 1. Preferences->C/C++->Build->Console -> Uncheck "Open console when
348 building"
349 1. note you can still see the build log in
350 `<workspace>/.metadata/.plugins/org.eclipse.cdt.ui`
3511. Now build the project (select project, click on hammer). If all went well:
352 1. Right click on a cpp file -> properties -> C/C++ general -> Preprocessor
353 includes -> GNU C++ -> CDT GCC Build output Parser
354 1. You will be able to expand and see all the include paths and
355 pre-processor definitions used for this file
3561. Rebuild index (right-click on project, index, rebuild). If all went well:
357 1. Open a CPP file and look at problems windows
358 1. Should be no (or very few) errors
359 1. Should be able to hit F3 on most symbols and jump to their definitioin
360 1. CDT has some issues with complex C++ syntax like templates (eg.
361 `PassOwnPtr` functions)
362 1. See
363 [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)
364 for more information.
andybons3322f762015-08-24 21:37:09365
andybonsad92aa32015-08-31 02:27:44366### Optional: static code and style guide analysis using cpplint.py
andybons3322f762015-08-24 21:37:09367
andybonsad92aa32015-08-31 02:27:443681. From the toolbar at the top, click the Project -> Properties and go to
369 C/C++Build.
370 1. Click on the right side of the pop up windows, "Manage
371 Configurations...", then on New, and give it a name, f.i. "Lint current
372 file", and close the small window, then select it in the Configuration
373 drop down list.
374 1. Under Builder settings tab, unclick "Use default build command" and type
375 as build command the full path to your `depot_tools/cpplint.py`
376 1. Under behaviour tab, unselect Clean, select Build(incremental build) and
377 in Make build target, add `--verbose=0 ${selected_resource_loc}`
378 1. Go back to the left side of the current window, and to C/C++Build ->
379 Settings, and click on error parsers tab, make sure CDT GNU C/C++ Error
380 Parser, CDT pushd/popd CWD Locator are set, then click Apply and OK.
3811. Select a file and click on the hammer icon drop down triangle next to it,
382 and make sure the build configuration is selected "Lint current file", then
383 click on the hammer.
3841. Note: If you get the `cpplint.py help` output, make sure you have selected a
385 file, by clicking inside the editor window or on its tab header, and make
386 sure the editor is not maximized inside Eclipse, i.e. you should see more
387 subwindows around.
388
389### Additional tips
390
3911. Mozilla's
392 [Eclipse CDT guide](https://developer.mozilla.org/en-US/docs/Eclipse_CDT)
393 is helpful:
3941. For improved performance, I use medium-granularity projects (eg. one for
395 WebKit/Source) instead of putting all of 'src/' in one project.
3961. For working in Blink (which uses WebKit code style), feel free to use
397 [this](https://drive.google.com/file/d/0B2LVVIKSxUVYM3R6U0tUa1dmY0U/view?usp=sharing)
398 code-style formatter XML profile