Please update your usage of the GN --export-compile-commands switch

779 views
Skip to first unread message

Brett Wilson

unread,
Sep 16, 2022, 5:57:18 PM9/16/22
to Chromium-dev
A small number of Chromium developers may be using the --export-compile-commands switch to GN in their builds. This generates a Clang compilation database normally used for editor integration or Clang refactoring tools. If this doesn't sound familiar to you, you can ignore this email.

GN is deprecating this switch in favor of a new one --add-export-compile-commands with slightly different semantics. Currently they both work, but I'll remove --export-compile-commands in a few weeks and it will be silently ignored (✻).

The old switch had unusual matching rules where it matched any targets with the "name" (the part after the colon in the label) in any directory and toolchain. The new switch uses GN "label patterns" (see "gn help label_pattern") which is more flexible and matches related syntax in GN. For most users of this flag, you'll just give the normal label of the target you care about. This target and all of its dependencies (recursively) will be included in the compilation database.

Old (matches everything)
gn gen --export-compile-commands out/default
New
gn gen --add-export-compile-commands="*" out/default

Old (matches anything named "chrome")
gn gen --export-compile-commands=chrome out/default
New (matches this particular target which is probably what you wanted)
gn gen --add-export-compile-commands="//chrome" out/default

Old (matches anything named "chrome" and "browser_tests")
gn gen --export-compile-commands=chrome,browser_tests out/default
New (specify multiple labels with multiple switches)
gn gen --add-export-compile-commands="//chrome" --add-export-compile-commands=//chrome/test:browser_tests out/default

You can also just edit the GN command-line without re-invoking GN manually by editing out/default/build.ninja. The command line is "  command = ..." on line 4 of the file.

Brett

(✻) The silent ignore is due to a long story migrating Fuchsia's use of this flag. Sorry for the inconvenience.

Brett Wilson

unread,
Sep 16, 2022, 6:15:01 PM9/16/22
to Chromium-dev
Actually, I found a few more references to this flag than I was expecting in different docs. Rather than removing --export-compile-commands, I'll make it match everything (the default if you specify no value) but remove the weird target name matching code (the yucky part). This seems to be what most uses of the flag wanted anyway.

Brett
Reply all
Reply to author
Forward
0 new messages