3 Eclipse can be used on Linux (and probably Windows and Mac) as an IDE for
4 developing Chromium. It's unpolished, but here's what works:
6 * 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
21 ### Get & Configure Eclipse
23 Eclipse 4.3 (Kepler) is known to work with Chromium for Linux.
25 * [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)).
28 * 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
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:
41 export ECLIPSE_MEM_START="1024M"
42 export ECLIPSE_MEM_MAX="3072M"
45 The large heap size prevents out of memory errors if you include many Chrome
46 subprojects that Eclipse is maintaining code indices for.
48 * Turn off Hyperlink detection in the Eclipse preferences. (Window ->
49 Preferences, search for "Hyperlinking, and uncheck "Enable on demand
50 hyperlink style navigation").
52 Pressing the control key on (for keyboard shortcuts such as copy/paste) can
53 trigger the hyperlink detector. This occurs on the UI thread and can result in
54 the reading of jar files on the Eclipse classpath, which can tie up the editor
55 due to the size of the classpath in Chromium.
57 ### A short word about paths
59 Before you start setting up your work space - here are a few hints:
61 * 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
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:
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
80 (Note: Things work fine for me without launching Eclipse from a special
81 directory. jamescook@chromium.org 2012-06-1)
83 ### Run Eclipse & Set your workspace
85 Run eclipse/eclipse in a way that your regular build environment (export CC,
86 CXX, etc...) will be visible to the eclipse process.
88 Set 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 --
90 it's too slow and Eclipse will block on access. Don't put the workspace in the
91 same directory as your checkout.
93 ### Install the C Development Tools ("CDT")
95 1. From the Help menu, select Install New Software...
96 1. Select the 'Workd with' URL for the CDT
97 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
101 1. Googlers: We have a local mirror, but be sure you run prodaccess before
103 1. Select & install the Main and Optional features.
105 1. Go to Window > Open Perspective > Other... > C/C++ to switch to the C++
106 perspective (window layout).
107 1. Right-click on the "Java" perspective in the top-right corner and select
108 "Close" to remove it.
110 ### Create your project(s)
112 First, turn off automatic workspace refresh and automatic building, as Eclipse
113 tries to do these too often and gets confused:
115 1. Open Window > Preferences
116 1. Search for "workspace"
117 1. Turn off "Build automatically"
118 1. Turn off "Refresh using native hooks or polling"
121 Create a single Eclipse project for everything:
123 1. From the File menu, select New > Project...
124 1. Select C/C++ Project > Makefile Project with Existing Code
125 1. Name the project the exact name of the directory: "src"
126 1. Provide a path to the code, like /work/chromium/src
127 1. Select toolchain: Linux GCC
130 Chromium has a huge amount of code, enough that Eclipse can take a very long
131 time to perform operations like "go to definition" and "open resource". You need
132 to set it up to operate on a subset of the code.
134 In the Project Explorer on the left side:
136 1. Right-click on "src" and select "Properties..."
137 1. Open Resource > Resource Filters
139 1. Add the following filter:
141 * Files, all children (recursive)
143 `.*\.(c|cc|cpp|h|mm|inl|idl|js|json|css|html|gyp|gypi|grd|grdp|gn)`
145 1. Add another filter:
148 * Name matches `out_.*|\.git|\.svn|LayoutTests` regular expression
149 * If you aren't working on WebKit, adding `|WebKit` will remove more
153 Don't exclude the primary "out" directory, as it contains generated header files
154 for things like string resources and Eclipse will miss a lot of symbols if you
157 Eclipse will refresh the workspace and start indexing your code. It won't find
158 most header files, however. Give it more help finding them:
160 1. Open Window > Preferences
161 1. Search for "Indexer"
162 1. Turn on "Allow heuristic resolution of includes"
163 1. Select "Use active build configuration"
164 1. Set Cache limits > Index database > Limit relative... to 20%
165 1. Set Cache limits > Index database > Absolute limit to 256 MB
168 Now the indexer will find many more include files, regardless of which approach
171 #### Optional: Manual header paths and symbols
173 You can manually tell Eclipse where to find header files, which will allow it to
174 create the source code index before you do a real build.
176 1. Right-click on "src" and select "Properties..."
177 * Open C++ General > Paths and Symbols > Includes
180 * Add `/path/to/chromium/src`
181 * Check "Add to all configurations" and "Add to all languages"
182 1. Repeat the above for:
183 * `/path/to/chromium/src/testing/gtest/include`
185 You may also find it helpful to define some symbols.
188 * Select the "Symbols" tab
191 * Add name `OS_LINUX` with value 1
192 * Click "Add to all configurations" and "Add to all languages"
193 1. Repeat for `ENABLE_EXTENSIONS 1`
194 1. Repeat for `HAS_OUT_OF_PROC_TEST_RUNNER 1`
196 1. Eclipse will ask if you want to rebuild the index. Click "Yes".
198 Let the C++ indexer run. It will take a while (10s of minutes).
200 ### Optional: Building inside Eclipse
202 This allows Eclipse to automatically discover include directories and symbols.
203 If you use gold or ninja (both recommended) you'll need to tell Eclipse about
206 1. echo $PATH from a shell and copy it to the clipboard
207 1. Open Window > Preferences > C/C++ > Build > Environment
208 1. Select "Replace native environment with specified one" (since gold and ninja
209 must be at the start of your path)
211 1. For name, enter `PATH`
212 1. For value, paste in your path with the ninja and gold directories.
215 To create a Make target:
217 1. From the Window menu, select Show View > Make Target
218 1. In the Make Target view, right-click on the project and select New...
219 1. name the target (e.g. base\_unittests)
220 1. Unclick the Build Command: Use builder Settings and type whatever build
221 command you would use to build this target (e.g.
222 `ninja -C out/Debug base_unittests`).
223 1. Return to the project properties page a under the C/C++ Build, change the
224 Build Location/Build Directory to be /path/to/chromium/src
225 1. In theory `${workspace_loc}` should work, but it doesn't for me.
226 1. If you put your workspace in `/path/to/chromium`, then
227 `${workspace_loc:/src}` will work too.
228 1. Now in the Make Targets view, select the target and click the hammer icon
231 You should see the build proceeding in the Console View and errors will be
232 parsed and appear in the Problems View. (Note that sometimes multi-line compiler
233 errors only show up partially in the Problems view and you'll want to look at
234 the full error in the Console).
236 (Eclipse 3.8 has a bug where the console scrolls too slowly if you're doing a
237 fast build, e.g. with goma. To work around, go to Window > Preferences and
238 search for "console". Under C/C++ console, set "Limit console output" to
239 2147483647, the maximum value.)
241 ### Optional: Multiple build targets
243 If you want to build multiple different targets in Eclipse (`chrome`,
246 1. Window > Show Toolbar (if you had it off)
247 1. Turn on special toolbar menu item (hammer) or menu bar item (Project > Build
248 configurations > Set Active > ...)
249 1. Window > Customize Perspective... > "Command Groups Availability"
250 1. Check "Build configuration"
251 1. Add more Build targets
252 1. Project > Properties > C/C++ Build > Manage Configurations
254 1. Duplicate from current and give it a name like "Unit tests".
255 1. Change under “Behavior” > Build > the target to e.g. `unit_tests`.
257 You can also drag the toolbar to the bottom of your window to save vertical
260 ### Optional: Debugging
262 1. From the toolbar at the top, click the arrow next to the debug icon and
263 select Debug Configurations...
264 1. Select C/C++ Application and click the New Launch Configuration icon. This
265 will create a new run/debug con figuration under the C/C++ Application header.
266 1. Name it something useful (e.g. `base_unittests`).
267 1. Under the Main Tab, enter the path to the executable (e.g.
268 `.../out/Debug/base_unittests`)
269 1. Select the Debugger Tab, select Debugger: gdb and unclick "Stop on startup
270 in (main)" unless you want this.
271 1. Set a breakpoint somewhere in your code and click the debug icon to start
274 ### Optional: Accurate symbol information
276 If setup properly, Eclipse can do a great job of semantic navigation of C++ code
277 (showing type hierarchies, finding all references to a particular method even
278 when other classes have methods of the same name, etc.). But doing this well
279 requires the Eclipse knows correct include paths and pre-processor definitions.
280 After fighting with with a number of approaches, I've found the below to work
283 1. From a shell in your src directory, run
284 `GYP_GENERATORS=ninja,eclipse build/gyp_chromium`
285 1. This generates <project root>/out/Debug/eclipse-cdt-settings.xml which
287 1. This creates a single list of include directories and preprocessor
288 definitions to be used for all source files, and so is a little
289 inaccurate. Here are some tips for compensating for the limitations:
290 1. Use `-R <target>` to restrict the output to considering only certain
291 targets (avoiding unnecessary includes that are likely to cause
292 trouble). Eg. for a blink project, use `-R blink`.
293 1. If you care about blink, move 'third\_party/Webkit/Source' to the
294 top of the list to better resolve ambiguous include paths (eg.
296 1. Import paths and symbols
297 1. Right click on the project and select Properties > C/C++ General > Paths
299 1. Click Restore Defaults to clear any old settings
300 1. Click Import Settings... > Browse... and select
301 `<project root>/out/Debug/eclipse-cdt-settings.xml`
302 1. Click the Finish button. The entire preferences dialog should go away.
303 1. Right click on the project and select Index > Rebuild
305 ### Alternative: Per-file accurate include/pre-processor information
307 Instead of generating a fixed list of include paths and pre-processor
308 definitions for a project (above), it is also possible to have Eclipse determine
309 the correct setting on a file-by-file basis using a built output parser. I
310 (rbyers) used this successfully for a long time, but it doesn't seem much better
311 in practice than the simpler (and less bug-prone) approach above.
313 1. Install the latest version of Eclipse IDE for C/C++ developers
314 ([Juno SR1](http://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers/junosr1)
315 at the time of this writing)
316 1. Setup build to generate a build log that includes the g++ command lines for
317 the files you want to index:
318 1. Project Properties -> C/C++ Build
319 1. Uncheck "Use default build command"
320 1. Enter your build command, eg: `ninja -v`
321 1. Note that for better performance, you can use a command that
322 doesn't actually builds, just prints the commands that would be
323 run. For ninja/make this means adding -n. This only prints the
324 compile commands for changed files (so be sure to move your
325 existing out directory out of the way temporarily to force a
326 full "build"). ninja also supports "-t commands" which will
327 print all build commands for the specified target and runs even
328 faster as it doesn't have to check file timestamps.
329 1. Build directory: your build path including out/Debug
330 1. Note that for the relative paths to be parsed correctly you
331 can't use ninja's `-C <dir>` to change directories as you might
332 from the command line.
333 1. Build: potentially change `all` to the target you want to analyze,
336 1. If you're using Ninja, you need to teach eclipse to ignore the prefix it
337 adds (eg. `[10/1234]` to each line in build output):
338 1. Project properties -> C/C++ General -> Preprocessor includes
339 1. Providers -> CDT GCC Build Output Parser -> Compiler command pattern
340 1. `(\[.*\] )?((gcc)|([gc]\+\+)|(clang(\+\+)?))`
341 1. Note that there appears to be a bug with "Share setting entries
342 between projects" - it will keep resetting to off. I suggest using
343 per-project settings and using the "folder" as the container to keep
344 discovered entries ("file" may work as well).
345 1. Eclipse / GTK has bugs where lots of output to the build console can
346 slow down the UI dramatically and cause it to hang (basically spends all
347 it's time trying to position the cursor correctly in the build console
348 window). To avoid this, close the console window and disable
349 automatically opening it on build:
350 1. Preferences->C/C++->Build->Console -> Uncheck "Open console when
352 1. note you can still see the build log in
353 `<workspace>/.metadata/.plugins/org.eclipse.cdt.ui`
354 1. Now build the project (select project, click on hammer). If all went well:
355 1. Right click on a cpp file -> properties -> C/C++ general -> Preprocessor
356 includes -> GNU C++ -> CDT GCC Build output Parser
357 1. You will be able to expand and see all the include paths and
358 pre-processor definitions used for this file
359 1. Rebuild index (right-click on project, index, rebuild). If all went well:
360 1. Open a CPP file and look at problems windows
361 1. Should be no (or very few) errors
362 1. Should be able to hit F3 on most symbols and jump to their definitioin
363 1. CDT has some issues with complex C++ syntax like templates (eg.
364 `PassOwnPtr` functions)
366 [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)
367 for more information.
369 ### Optional: static code and style guide analysis using cpplint.py
371 1. From the toolbar at the top, click the Project -> Properties and go to
373 1. Click on the right side of the pop up windows, "Manage
374 Configurations...", then on New, and give it a name, f.i. "Lint current
375 file", and close the small window, then select it in the Configuration
377 1. Under Builder settings tab, unclick "Use default build command" and type
378 as build command the full path to your `depot_tools/cpplint.py`
379 1. Under behaviour tab, unselect Clean, select Build(incremental build) and
380 in Make build target, add `--verbose=0 ${selected_resource_loc}`
381 1. Go back to the left side of the current window, and to C/C++Build ->
382 Settings, and click on error parsers tab, make sure CDT GNU C/C++ Error
383 Parser, CDT pushd/popd CWD Locator are set, then click Apply and OK.
384 1. Select a file and click on the hammer icon drop down triangle next to it,
385 and make sure the build configuration is selected "Lint current file", then
387 1. Note: If you get the `cpplint.py help` output, make sure you have selected a
388 file, by clicking inside the editor window or on its tab header, and make
389 sure the editor is not maximized inside Eclipse, i.e. you should see more
395 [Eclipse CDT guide](https://developer.mozilla.org/en-US/docs/Eclipse_CDT)
397 1. For improved performance, I use medium-granularity projects (eg. one for
398 WebKit/Source) instead of putting all of 'src/' in one project.
399 1. For working in Blink (which uses WebKit code style), feel free to use
400 [this](https://drive.google.com/file/d/0B2LVVIKSxUVYM3R6U0tUa1dmY0U/view?usp=sharing)
401 code-style formatter XML profile