README.md
1# Private Code Test
2
3This directory provides a mechanism for testing that native does not link in
4object files from unwanted directories. The test finds all linker inputs, and
5checks that none live inside a list of internal paths.
6
7Original bug: https://bugs.chromium.org/p/chromium/issues/detail?id=1266989
8
9## Determining Internal Directories
10
11This is done by parsing the `.gclient_entries` file for all paths coming from
12https://chrome-internal.googlesource.com. I chose this approach since it is
13simple.
14
15The main alternative I found was to use `gclient flatten`. Example output:
16
17```
18 # src -> src/internal
19 "src/internal": {
20 "url": "https://chrome-internal.googlesource.com/chrome/src-internal.git@c649c6a155fe65c3730e2d663d7d2058d33bf1f9",
21 "condition": 'checkout_src_internal',
22 },
23```
24
25* Paths could be found in this way by looking for `checkout_src_internal`
26 within `condition`, and by looking for the comment line for `recurse_deps`
27 that went through an internal repo.
28
29## Determining Linker Inputs
30
31This is done by parsing `build.ninja` to find all inputs to an executable. This
32approach is pretty fast & simple, but does not catch the case where a public
33`.cc` file has an `#include` a private `.h` file.
34
35Alternatives considered:
36
371) Dump paths found in debug information.
38 * Hard to do cross-platform.
392) Scan a linker map file for input paths.
40 * LTO causes paths in linker map to be inaccurate.
413) Use a fake link step to capture all object file inputs
42 * Object files paths are relative to GN target, so this does not catch
43 internal sources referenced by public GN targets.
444) Query GN / Ninja for transitive inputs
45 * This ends up listing non-linker inputs as well, which we do not want.
465) Parse depfiles to find all headers, and add them to the list of inputs
47 * Additional work, but would give us full coverage.
48