blob: 9582294b4a3071d5eb03b3ef2d5340cac8204cb5 [file] [log] [blame] [view]
manukh080b47e2019-12-19 22:06:191# CLion Dev
2
3CLion is an IDE
4
5Prerequisite:
6[Checking out and building the chromium code base](README.md#Checking-Out-and-Building)
7
8[TOC]
9
10## Setting up CLion
Etienne Noel835d6d52022-08-23 15:30:2011
manukh080b47e2019-12-19 22:06:19121. Install CLion
13 - Googlers only: See
14 [go/intellij-getting-started](https://goto.google.com/intellij-getting-started)
15 for installation and license authentication instructions
16
171. Run CLion
181. Increase CLion's memory allocation
19
Etienne Noel835d6d52022-08-23 15:30:2020 This step will help performance with large projects
manukh080b47e2019-12-19 22:06:1921 1. Option 1
Etienne Noel835d6d52022-08-23 15:30:2022 1. At the startup dialog, in the bottom left corner, click on the Cog
23 icon and then click on `Edit Custom VM Options`:
24 1. In the textbox, you will see different flags. Add or replace the
25 following flags (to learn
26 more: [Advanced configuration | IntelliJ IDEA](https://www.jetbrains.com/help/idea/tuning-the-ide.html#common-jvm-options)):
manukh080b47e2019-12-19 22:06:1927 ```
28 -Xss2m
29 -Xms1g
Etienne Noel835d6d52022-08-23 15:30:2030 -Xmx31g
manukh080b47e2019-12-19 22:06:1931 ...
32 ```
Etienne Noel835d6d52022-08-23 15:30:2033 1. Close the `Edit Custom VM Options` dialog.
34 1. Again, at the startup dialogue, in the bottom left corner, click on
35 the Cog icon and then click on `Edit Custom Properties`:
36 1. Add or replace the following flags (to learn
37 more: [Platform Properties | IntelliJ IDEA](https://www.jetbrains.com/help/idea/tuning-the-ide.html#configure-platform-properties)):
manukh080b47e2019-12-19 22:06:1938 ```
39 idea.max.intellisense.filesize=12500
40 ```
41 1. Option 2; 2017 and prior versions may not include the options to setup
Etienne Noel835d6d52022-08-23 15:30:2042 your `VM Options` and `Properties` in the `configure` menu. Instead:
manukh080b47e2019-12-19 22:06:1943 1. `Create New Project`
44 1. `Help` > `Edit Custom VM Options`
Etienne Noel835d6d52022-08-23 15:30:2045 1. `Help` > `Edit Custom Properties`
manukh080b47e2019-12-19 22:06:1946
Etienne Noel835d6d52022-08-23 15:30:2047## Creating a new CLion project
48
manukh080b47e2019-12-19 22:06:19491. Import project
50 - At the startup dialog, select `Import Project` and select your `chromium`
51 directory; this should be the parent directory to `src`. Selecting `src`
52 instead would result in some CLion IDE files appearing in your repository.
Etienne Noel835d6d52022-08-23 15:30:2053
54## Building, Running, and Debugging within CLion
55
56Configure CLion to use ninja for building
57(see [Linux Build Instructions](https://g3doc.corp.google.com/company/teams/chrome/linux_build_instructions.md))
58
59### Custom Build Targets
60
61A custom Build Target allows CLion to compile Chromium similarly to running
62ninja in the command line.
63
64#### Add a Custom Build Target
65
66The first step is to add Ninja (specifically autoninja) as an external tool
67that will be used to create the build targets.
68
691. Go to `Settings`
701. Then, to `Build, Execution, Deployment > Custom Build Targets`
711. Click on the `+` sign to add a new build target.
721. Fill the Name: `Default`
731. Next to `Build`, click on the three dots (`...`)
741. Click on `+` to add an External Tool
751. Fill the form:
76 1. Name: `autoninja - Default`
77 1. Program: `<absolute path to depot_tools/autoninja>`
Etienne Noel870b0792022-09-14 01:12:3678 1. Arguments: `-C out/Default chrome`
Etienne Noel835d6d52022-08-23 15:30:2079 1. Working Directory: `<absolute path to chromium/src>`
801. Click `Ok` to close the dialog.
81
82#### Run/Debug configuration
83
84The build target configured in the previous section was necessary to configure
85the Run/Debug configuration.
86
871. Click on the `Run` menu and then on `Edit Configurations`.
881. Click on the `+` sign then on `Custom Build Application`
891. Fill the form:
90 1. Name: `Default`
91 1. Target: Select the `Default` build target that was created previously.
92 1. Executable: Click the three dots (`...`) and select
93 `src/out/Default/chrome`
941. Click `Ok` to close the dialog.
95
can liub9da1812024-04-10 18:17:0996### Configure `~/.gdbinit`
Etienne Noel835d6d52022-08-23 15:30:2097
98Before being able to debug, you need to configure `~/.gdbinit`. Open it with a
99text editor and enter:
100
101```
102source <path to chromium>/src/tools/gdb/gdbinit
103```
104
105### Set the local gdb executable
106
107There have been some reports of slowness while debugging using CLion.
108It seems that using that CLion's bundled gdb executable is the culprit. To use
109the local one:
1101. Open `Settings`
1111. Search for `Toolchains`
1121. Next to `Debugger`, select `/usr/bin/gdb`
113
114#### Run Chrome!
115
116You can now run chrome directly from CLion. You can also debug and add a
117breakpoint. Try it!
118
119`Run` > `Run` (`shift+f10`) or `Run` > `Debug` (`shift+f9`) (screenshot)
120![debugging screenshot](images/clion_gui_debugging.png)
121
122## Autocompletion
123
124### Approach 1: Using CMakeLists
125**Note**: It's possible that when you open the project, CLion created one for you.
126
1271. Create or Modify the `chromium/CMakeLists.txt` file
128 1. Open `chromium/CMakeLists.txt`
129 1. Add or Replace the content with:
manukh080b47e2019-12-19 22:06:19130 ```
131 cmake_minimum_required(VERSION 3.10)
132 project(chromium)
133
134 set(CMAKE_CXX_STANDARD 14)
135
136 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
manuk hovanesianb2953e42021-03-20 00:14:04137 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/out/Default/gen)
manukh38a8b742022-08-03 22:25:52138 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/protobuf/src)
manuk hovanesianb2953e42021-03-20 00:14:04139 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/googletest/src/googletest/include)
manukh38a8b742022-08-03 22:25:52140 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/googletest/src/googlemock/include)
141 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/abseil-cpp)
Etienne Noel835d6d52022-08-23 15:30:20142
143 # The following file used is irrelevant, it's only to improve CLion
144 # performance. Leaving at least 1 file is required in order for CLion
145 # to provide code completion, navigation, etc.
manukh080b47e2019-12-19 22:06:19146 add_executable(chromium src/components/omnibox/browser/document_provider.cc)
147 ```
148
Etienne Noel835d6d52022-08-23 15:30:20149### Approach 2: Compilation database
150
151Since Chromium does not use CMake to build, to “benefit from the advanced IDE
152features that CLion provides”, a
153[Compilation database](https://www.jetbrains.com/help/clion/compilation-database.html)
154must be created to expose to CLion how Chromium is built.
155
156In the Chromium code source, there’s a python script
157`src/tools/clang/scripts/generate_compdb.py` that will generate
158the Compilation Database.
159
160**Note**: The two approaches are not currently compatible and switching between
161one and the other is cumbersome. To go from approach 1 to 2, the
162`CMakeWorkspace` line from `.idea/misc.xml` must be removed first.
163
1641. Run from your `chromium` folder:
165
166 ```
167 python3 src/tools/clang/scripts/generate_compdb.py -p src/out/Default -o ./compile_commands.json --target_os=linux
168 ```
169
170 This generates the compilation database at `chromium/compile_commands.json`.
171
1721. In CLion, select the `compile_commands.json` file in the project navigator,
173 right-click on it, then click on `Load Compilation Database Project`.
174
175 **Note:** This step will produce a few hundred errors but it doesn't cause
176 any issues. It's simply because some files are not compiled. To remove some
177 errors, these flags can be added in `src/out/Default/args.gn`:
178 ```
179 enable_nocompile_tests=true
180 ```
181
1821. CLion will start processing the files and will start indexing the symbols.
183This step can take a few hours. To expedite this process, see the section
184[Exclude irrelevant folders from indexing to speed up CLion](#exclude-irrelevant-folders-from-indexing-to-speed-up-clion)
185below.
manukh080b47e2019-12-19 22:06:19186
187## Optional Steps
188
189### Create terminal cli or desktop entry
Etienne Noel835d6d52022-08-23 15:30:20190
manukh080b47e2019-12-19 22:06:19191To make it easier to startup CLion or open individual files:
Etienne Noel835d6d52022-08-23 15:30:20192
manukh080b47e2019-12-19 22:06:191931. Open the actions menu (`ctrl+shift+a`)
1941. Type `create desktop entry` and press `enter`
1951. Open the actions menu and enter `create command-line launcher`
196
Etienne Noel835d6d52022-08-23 15:30:20197### Exclude irrelevant folders from indexing to speed up CLion
198
199Exclude folders that are irrelevant to your work from the indexing. Exclude at
200first the following folders and manually include the ones relevant to you. Open
201`chromium/.idea/misc.xml` and under `<project>` add or edit the following
202XML component:
203
204**Note**: This step can be done from the UI in the Project view by selecting
205all the folders to exclude, right-clicking on them, selecting
206`Mark Directory As` and then selecting `Excluded`.
207
208```
209<component name="CidrRootsConfiguration">
210 <excludeRoots>
211 <file path="$PROJECT_DIR$/src/android_webview" />
212 <file path="$PROJECT_DIR$/src/apps" />
213 <file path="$PROJECT_DIR$/src/ash" />
214 <file path="$PROJECT_DIR$/src/build" />
215 <file path="$PROJECT_DIR$/src/build_overrides" />
216 <file path="$PROJECT_DIR$/src/buildtools" />
217 <file path="$PROJECT_DIR$/src/cc" />
218 <file path="$PROJECT_DIR$/src/chromecast" />
219 <file path="$PROJECT_DIR$/src/chromeos" />
220 <file path="$PROJECT_DIR$/src/codelabs" />
221 <file path="$PROJECT_DIR$/src/content" />
222 <file path="$PROJECT_DIR$/src/courgette" />
223 <file path="$PROJECT_DIR$/src/crypto" />
224 <file path="$PROJECT_DIR$/src/dbus" />
225 <file path="$PROJECT_DIR$/src/device" />
226 <file path="$PROJECT_DIR$/src/docs" />
227 <file path="$PROJECT_DIR$/src/extensions" />
228 <file path="$PROJECT_DIR$/src/fuchsia_web" />
229 <file path="$PROJECT_DIR$/src/gin" />
230 <file path="$PROJECT_DIR$/src/google_apis" />
231 <file path="$PROJECT_DIR$/src/google_update" />
232 <file path="$PROJECT_DIR$/src/gpu" />
233 <file path="$PROJECT_DIR$/src/headless" />
234 <file path="$PROJECT_DIR$/src/infra" />
235 <file path="$PROJECT_DIR$/src/ios" />
236 <file path="$PROJECT_DIR$/src/ipc" />
237 <file path="$PROJECT_DIR$/src/media" />
238 <file path="$PROJECT_DIR$/src/mojo" />
239 <file path="$PROJECT_DIR$/src/native_client" />
240 <file path="$PROJECT_DIR$/src/native_client_sdk" />
241 <file path="$PROJECT_DIR$/src/net" />
242 <file path="$PROJECT_DIR$/src/out" />
243 <file path="$PROJECT_DIR$/src/pdf" />
244 <file path="$PROJECT_DIR$/src/ppapi" />
245 <file path="$PROJECT_DIR$/src/printing" />
246 <file path="$PROJECT_DIR$/src/remoting" />
247 <file path="$PROJECT_DIR$/src/rlz" />
248 <file path="$PROJECT_DIR$/src/sandbox" />
249 <file path="$PROJECT_DIR$/src/services" />
250 <file path="$PROJECT_DIR$/src/skia" />
251 <file path="$PROJECT_DIR$/src/sql" />
252 <file path="$PROJECT_DIR$/src/storage" />
253 <file path="$PROJECT_DIR$/src/styleguide" />
254 <file path="$PROJECT_DIR$/src/testing" />
255 <file path="$PROJECT_DIR$/src/third_party" />
256 <file path="$PROJECT_DIR$/src/tools" />
257 <file path="$PROJECT_DIR$/src/ui" />
258 <file path="$PROJECT_DIR$/src/url" />
259 <file path="$PROJECT_DIR$/src/v8" />
260 <file path="$PROJECT_DIR$/src/venv" />
261 <file path="$PROJECT_DIR$/src/weblayer" />
262 </excludeRoots>
263 </component>
264```
265
manukh080b47e2019-12-19 22:06:19266### Mark directories as `Library Files`
Etienne Noel835d6d52022-08-23 15:30:20267
manukh080b47e2019-12-19 22:06:19268To speed up CLion, optionally mark directories such as `src/third_party` as
269`Library Files`
Etienne Noel835d6d52022-08-23 15:30:20270
manukh080b47e2019-12-19 22:06:192711. Open the `Project` navigation (`alt+1`)
Etienne Noel835d6d52022-08-23 15:30:202721. Select and right-click the directories > `Mark directory as` >
manukh080b47e2019-12-19 22:06:19273 `Library Files`
2741. See `https://blog.jetbrains.com/clion/2015/12/mark-dir-as/` for more details