blob: a3fe4090e798d45130364cbb0d45228dfdc3ce1c [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.)
andybons3322f762015-08-24 21:37:0968
andybonsad92aa32015-08-31 02:27:4469### Run Eclipse & Set your workspace
andybons3322f762015-08-24 21:37:0970
andybonsad92aa32015-08-31 02:27:4471Run eclipse/eclipse in a way that your regular build environment (export CC,
72CXX, etc...) will be visible to the eclipse process.
andybons3322f762015-08-24 21:37:0973
andybonsad92aa32015-08-31 02:27:4474Set the Workspace to be a directory on a local disk (e.g.
75`/work/workspaces/chrome`). Placing it on an NFS share is not recommended --
76it's too slow and Eclipse will block on access. Don't put the workspace in the
77same directory as your checkout.
andybons3322f762015-08-24 21:37:0978
andybonsad92aa32015-08-31 02:27:4479### Install the C Development Tools ("CDT")
andybons3322f762015-08-24 21:37:0980
andybonsad92aa32015-08-31 02:27:44811. From the Help menu, select Install New Software...
dgroganfbd6de92017-05-05 18:06:0682 1. Select the 'Work with' URL for the CDT
nodira6074d4c2015-09-01 04:26:4583 If it's not there you can click Add... and add it.
84 See https://eclipse.org/cdt/downloads.php for up to date versions,
85 e.g. with CDT 8.7.0 for Eclipse Mars, use
86 http://download.eclipse.org/tools/cdt/releases/8.7
andybonsad92aa32015-08-31 02:27:4487 1. Googlers: We have a local mirror, but be sure you run prodaccess before
88 trying to use it.
891. Select & install the Main and Optional features.
901. Restart Eclipse
911. Go to Window > Open Perspective > Other... > C/C++ to switch to the C++
92 perspective (window layout).
931. Right-click on the "Java" perspective in the top-right corner and select
94 "Close" to remove it.
andybons3322f762015-08-24 21:37:0995
andybonsad92aa32015-08-31 02:27:4496### Create your project(s)
97
98First, turn off automatic workspace refresh and automatic building, as Eclipse
99tries to do these too often and gets confused:
100
1011. Open Window > Preferences
1021. Search for "workspace"
1031. Turn off "Build automatically"
1041. Turn off "Refresh using native hooks or polling"
1051. Click "Apply"
andybons3322f762015-08-24 21:37:09106
107Create a single Eclipse project for everything:
108
andybonsad92aa32015-08-31 02:27:441091. From the File menu, select New > Project...
1101. Select C/C++ Project > Makefile Project with Existing Code
dgroganfbd6de92017-05-05 18:06:061111. Name the project the exact name of the directory: "src" (or "WebKit" if you
112 mainly work in Blink and want a faster experience)
1131. Provide a path to the code, like /work/chromium/src (or
114 /work/chromium/src/third_party/WebKit)
andybonsad92aa32015-08-31 02:27:441151. Select toolchain: Linux GCC
1161. Click Finish.
andybons3322f762015-08-24 21:37:09117
dgroganfbd6de92017-05-05 18:06:06118Chromium uses C++11, so tell the indexer about it. Otherwise it will get
119confused about things like std::unique_ptr.
120
1211. Right-click on "src" and select "Properties..."
1221. Navigate to C/C++ General > Preprocess Include Paths, Macros etc. >
123 Providers
1241. Select CDT GCC Built-in Compiler Settings
1251. In the text box entitled Command to get compiler specs append "-std=c++11"
126 (leaving out the quotes)
127
andybonsad92aa32015-08-31 02:27:44128Chromium has a huge amount of code, enough that Eclipse can take a very long
129time to perform operations like "go to definition" and "open resource". You need
130to set it up to operate on a subset of the code.
andybons3322f762015-08-24 21:37:09131
132In the Project Explorer on the left side:
133
andybonsad92aa32015-08-31 02:27:441341. Right-click on "src" and select "Properties..."
1351. Open Resource > Resource Filters
dgroganfbd6de92017-05-05 18:06:061361. Click "Add Filter..."
andybonsad92aa32015-08-31 02:27:441371. Add the following filter:
138 * Include only
139 * Files, all children (recursive)
140 * Name matches
mfomitchev95f20f12016-06-09 17:37:34141 `.*\.(c|cc|cpp|h|mm|inl|idl|js|json|css|html|gyp|gypi|grd|grdp|gn|gni|mojom)`
andybonsad92aa32015-08-31 02:27:44142 regular expression
1431. Add another filter:
144 * Exclude all
145 * Folders
Kent Tamura59ffb022018-11-27 05:30:56146 * Name matches `out_.*|\.git|web_tests` regular expression
147 * If you aren't working on WebKit, adding `|blink` will remove more
andybonsad92aa32015-08-31 02:27:44148 files
dgroganfbd6de92017-05-05 18:06:061491. Click "Apply and Close"
andybons3322f762015-08-24 21:37:09150
andybonsad92aa32015-08-31 02:27:44151Don't exclude the primary "out" directory, as it contains generated header files
152for things like string resources and Eclipse will miss a lot of symbols if you
153do.
andybons3322f762015-08-24 21:37:09154
andybonsad92aa32015-08-31 02:27:44155Eclipse will refresh the workspace and start indexing your code. It won't find
156most header files, however. Give it more help finding them:
andybons3322f762015-08-24 21:37:09157
andybonsad92aa32015-08-31 02:27:441581. Open Window > Preferences
1591. Search for "Indexer"
1601. Turn on "Allow heuristic resolution of includes"
1611. Select "Use active build configuration"
1621. Set Cache limits > Index database > Limit relative... to 20%
1631. Set Cache limits > Index database > Absolute limit to 256 MB
dgroganfbd6de92017-05-05 18:06:061641. Click "Apply and Close"
andybons3322f762015-08-24 21:37:09165
andybonsad92aa32015-08-31 02:27:44166Now the indexer will find many more include files, regardless of which approach
167you take below.
andybons3322f762015-08-24 21:37:09168
andybonsad92aa32015-08-31 02:27:44169#### Optional: Manual header paths and symbols
andybons3322f762015-08-24 21:37:09170
andybonsad92aa32015-08-31 02:27:44171You can manually tell Eclipse where to find header files, which will allow it to
172create the source code index before you do a real build.
173
1741. Right-click on "src" and select "Properties..."
andybons3322f762015-08-24 21:37:09175 * Open C++ General > Paths and Symbols > Includes
176 * Click "GNU C++"
177 * Click "Add..."
andybonsad92aa32015-08-31 02:27:44178 * Add `/path/to/chromium/src`
andybons3322f762015-08-24 21:37:09179 * Check "Add to all configurations" and "Add to all languages"
andybonsad92aa32015-08-31 02:27:441801. Repeat the above for:
181 * `/path/to/chromium/src/testing/gtest/include`
andybons3322f762015-08-24 21:37:09182
183You may also find it helpful to define some symbols.
184
andybonsad92aa32015-08-31 02:27:441851. Add `OS_LINUX`:
andybons3322f762015-08-24 21:37:09186 * Select the "Symbols" tab
187 * Click "GNU C++"
188 * Click "Add..."
andybonsad92aa32015-08-31 02:27:44189 * Add name `OS_LINUX` with value 1
andybons3322f762015-08-24 21:37:09190 * Click "Add to all configurations" and "Add to all languages"
andybonsad92aa32015-08-31 02:27:441911. Repeat for `ENABLE_EXTENSIONS 1`
1921. Repeat for `HAS_OUT_OF_PROC_TEST_RUNNER 1`
1931. Click "OK".
1941. Eclipse will ask if you want to rebuild the index. Click "Yes".
andybons3322f762015-08-24 21:37:09195
196Let the C++ indexer run. It will take a while (10s of minutes).
197
andybonsad92aa32015-08-31 02:27:44198### Optional: Building inside Eclipse
andybons3322f762015-08-24 21:37:09199
andybonsad92aa32015-08-31 02:27:44200This allows Eclipse to automatically discover include directories and symbols.
201If you use gold or ninja (both recommended) you'll need to tell Eclipse about
202your path.
203
2041. echo $PATH from a shell and copy it to the clipboard
2051. Open Window > Preferences > C/C++ > Build > Environment
2061. Select "Replace native environment with specified one" (since gold and ninja
207 must be at the start of your path)
2081. Click "Add..."
2091. For name, enter `PATH`
2101. For value, paste in your path with the ninja and gold directories.
2111. Click "OK"
andybons3322f762015-08-24 21:37:09212
213To create a Make target:
214
andybonsad92aa32015-08-31 02:27:442151. From the Window menu, select Show View > Make Target
2161. In the Make Target view, right-click on the project and select New...
2171. name the target (e.g. base\_unittests)
2181. Unclick the Build Command: Use builder Settings and type whatever build
219 command you would use to build this target (e.g.
220 `ninja -C out/Debug base_unittests`).
2211. Return to the project properties page a under the C/C++ Build, change the
222 Build Location/Build Directory to be /path/to/chromium/src
223 1. In theory `${workspace_loc}` should work, but it doesn't for me.
224 1. If you put your workspace in `/path/to/chromium`, then
225 `${workspace_loc:/src}` will work too.
2261. Now in the Make Targets view, select the target and click the hammer icon
227 (Build Make Target).
andybons3322f762015-08-24 21:37:09228
andybonsad92aa32015-08-31 02:27:44229You should see the build proceeding in the Console View and errors will be
230parsed and appear in the Problems View. (Note that sometimes multi-line compiler
231errors only show up partially in the Problems view and you'll want to look at
232the full error in the Console).
andybons3322f762015-08-24 21:37:09233
andybonsad92aa32015-08-31 02:27:44234(Eclipse 3.8 has a bug where the console scrolls too slowly if you're doing a
235fast build, e.g. with goma. To work around, go to Window > Preferences and
236search for "console". Under C/C++ console, set "Limit console output" to
2372147483647, the maximum value.)
andybons3322f762015-08-24 21:37:09238
andybonsad92aa32015-08-31 02:27:44239### Optional: Multiple build targets
andybons3322f762015-08-24 21:37:09240
andybonsad92aa32015-08-31 02:27:44241If you want to build multiple different targets in Eclipse (`chrome`,
242`unit_tests`, etc.):
andybons3322f762015-08-24 21:37:09243
andybonsad92aa32015-08-31 02:27:442441. Window > Show Toolbar (if you had it off)
2451. Turn on special toolbar menu item (hammer) or menu bar item (Project > Build
246 configurations > Set Active > ...)
247 1. Window > Customize Perspective... > "Command Groups Availability"
248 1. Check "Build configuration"
2491. Add more Build targets
250 1. Project > Properties > C/C++ Build > Manage Configurations
251 1. Select "New..."
252 1. Duplicate from current and give it a name like "Unit tests".
253 1. Change under “Behavior” > Build > the target to e.g. `unit_tests`.
andybons3322f762015-08-24 21:37:09254
andybonsad92aa32015-08-31 02:27:44255You can also drag the toolbar to the bottom of your window to save vertical
256space.
andybons3322f762015-08-24 21:37:09257
andybonsad92aa32015-08-31 02:27:44258### Optional: Debugging
andybons3322f762015-08-24 21:37:09259
andybonsad92aa32015-08-31 02:27:442601. From the toolbar at the top, click the arrow next to the debug icon and
261 select Debug Configurations...
2621. Select C/C++ Application and click the New Launch Configuration icon. This
263 will create a new run/debug con figuration under the C/C++ Application header.
2641. Name it something useful (e.g. `base_unittests`).
2651. Under the Main Tab, enter the path to the executable (e.g.
266 `.../out/Debug/base_unittests`)
2671. Select the Debugger Tab, select Debugger: gdb and unclick "Stop on startup
268 in (main)" unless you want this.
2691. Set a breakpoint somewhere in your code and click the debug icon to start
270 debugging.
andybons3322f762015-08-24 21:37:09271
andybonsad92aa32015-08-31 02:27:44272### Optional: Accurate symbol information
andybons3322f762015-08-24 21:37:09273
andybonsad92aa32015-08-31 02:27:44274If setup properly, Eclipse can do a great job of semantic navigation of C++ code
275(showing type hierarchies, finding all references to a particular method even
276when other classes have methods of the same name, etc.). But doing this well
277requires the Eclipse knows correct include paths and pre-processor definitions.
278After fighting with with a number of approaches, I've found the below to work
279best for me.
andybons3322f762015-08-24 21:37:09280
andybonsad92aa32015-08-31 02:27:442811. From a shell in your src directory, run
dgroganfbd6de92017-05-05 18:06:06282 `gn gen --ide=eclipse out/Debug/` (replacing Debug with the output directory you normally use when building).
283 1. This generates <project root>/out/Debug/eclipse-cdt-settings.xml which
andybonsad92aa32015-08-31 02:27:44284 is used below.
285 1. This creates a single list of include directories and preprocessor
286 definitions to be used for all source files, and so is a little
287 inaccurate. Here are some tips for compensating for the limitations:
qyearsleyc0dc6f42016-12-02 22:13:39288 1. If you care about blink, move 'third\_party/WebKit/Source' to the
andybonsad92aa32015-08-31 02:27:44289 top of the list to better resolve ambiguous include paths (eg.
290 `config.h`).
2911. Import paths and symbols
292 1. Right click on the project and select Properties > C/C++ General > Paths
293 and Symbols
294 1. Click Restore Defaults to clear any old settings
295 1. Click Import Settings... > Browse... and select
296 `<project root>/out/Debug/eclipse-cdt-settings.xml`
297 1. Click the Finish button. The entire preferences dialog should go away.
298 1. Right click on the project and select Index > Rebuild
andybons3322f762015-08-24 21:37:09299
andybonsad92aa32015-08-31 02:27:44300### Alternative: Per-file accurate include/pre-processor information
andybons3322f762015-08-24 21:37:09301
andybonsad92aa32015-08-31 02:27:44302Instead of generating a fixed list of include paths and pre-processor
303definitions for a project (above), it is also possible to have Eclipse determine
304the correct setting on a file-by-file basis using a built output parser. I
305(rbyers) used this successfully for a long time, but it doesn't seem much better
306in practice than the simpler (and less bug-prone) approach above.
andybons3322f762015-08-24 21:37:09307
andybonsad92aa32015-08-31 02:27:443081. Install the latest version of Eclipse IDE for C/C++ developers
309 ([Juno SR1](http://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers/junosr1)
310 at the time of this writing)
3111. Setup build to generate a build log that includes the g++ command lines for
312 the files you want to index:
313 1. Project Properties -> C/C++ Build
314 1. Uncheck "Use default build command"
315 1. Enter your build command, eg: `ninja -v`
316 1. Note that for better performance, you can use a command that
317 doesn't actually builds, just prints the commands that would be
318 run. For ninja/make this means adding -n. This only prints the
319 compile commands for changed files (so be sure to move your
320 existing out directory out of the way temporarily to force a
321 full "build"). ninja also supports "-t commands" which will
322 print all build commands for the specified target and runs even
323 faster as it doesn't have to check file timestamps.
324 1. Build directory: your build path including out/Debug
325 1. Note that for the relative paths to be parsed correctly you
326 can't use ninja's `-C <dir>` to change directories as you might
327 from the command line.
328 1. Build: potentially change `all` to the target you want to analyze,
329 eg. `chrome`
330 1. Deselect 'clean'
331 1. If you're using Ninja, you need to teach eclipse to ignore the prefix it
332 adds (eg. `[10/1234]` to each line in build output):
333 1. Project properties -> C/C++ General -> Preprocessor includes
334 1. Providers -> CDT GCC Build Output Parser -> Compiler command pattern
335 1. `(\[.*\] )?((gcc)|([gc]\+\+)|(clang(\+\+)?))`
336 1. Note that there appears to be a bug with "Share setting entries
337 between projects" - it will keep resetting to off. I suggest using
338 per-project settings and using the "folder" as the container to keep
339 discovered entries ("file" may work as well).
340 1. Eclipse / GTK has bugs where lots of output to the build console can
341 slow down the UI dramatically and cause it to hang (basically spends all
342 it's time trying to position the cursor correctly in the build console
343 window). To avoid this, close the console window and disable
344 automatically opening it on build:
345 1. Preferences->C/C++->Build->Console -> Uncheck "Open console when
346 building"
347 1. note you can still see the build log in
348 `<workspace>/.metadata/.plugins/org.eclipse.cdt.ui`
3491. Now build the project (select project, click on hammer). If all went well:
350 1. Right click on a cpp file -> properties -> C/C++ general -> Preprocessor
351 includes -> GNU C++ -> CDT GCC Build output Parser
352 1. You will be able to expand and see all the include paths and
353 pre-processor definitions used for this file
3541. Rebuild index (right-click on project, index, rebuild). If all went well:
355 1. Open a CPP file and look at problems windows
356 1. Should be no (or very few) errors
357 1. Should be able to hit F3 on most symbols and jump to their definitioin
358 1. CDT has some issues with complex C++ syntax like templates (eg.
359 `PassOwnPtr` functions)
360 1. See
361 [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)
362 for more information.
andybons3322f762015-08-24 21:37:09363
andybonsad92aa32015-08-31 02:27:44364### Optional: static code and style guide analysis using cpplint.py
andybons3322f762015-08-24 21:37:09365
andybonsad92aa32015-08-31 02:27:443661. From the toolbar at the top, click the Project -> Properties and go to
367 C/C++Build.
368 1. Click on the right side of the pop up windows, "Manage
369 Configurations...", then on New, and give it a name, f.i. "Lint current
370 file", and close the small window, then select it in the Configuration
371 drop down list.
372 1. Under Builder settings tab, unclick "Use default build command" and type
373 as build command the full path to your `depot_tools/cpplint.py`
374 1. Under behaviour tab, unselect Clean, select Build(incremental build) and
375 in Make build target, add `--verbose=0 ${selected_resource_loc}`
376 1. Go back to the left side of the current window, and to C/C++Build ->
377 Settings, and click on error parsers tab, make sure CDT GNU C/C++ Error
378 Parser, CDT pushd/popd CWD Locator are set, then click Apply and OK.
3791. Select a file and click on the hammer icon drop down triangle next to it,
380 and make sure the build configuration is selected "Lint current file", then
381 click on the hammer.
3821. Note: If you get the `cpplint.py help` output, make sure you have selected a
383 file, by clicking inside the editor window or on its tab header, and make
384 sure the editor is not maximized inside Eclipse, i.e. you should see more
385 subwindows around.
386
387### Additional tips
388
3891. Mozilla's
390 [Eclipse CDT guide](https://developer.mozilla.org/en-US/docs/Eclipse_CDT)
391 is helpful:
3921. For improved performance, I use medium-granularity projects (eg. one for
393 WebKit/Source) instead of putting all of 'src/' in one project.