Skip to content

Commit 45369f2

Browse files
committed
docs: explain when and how to use canonicalize_compile_command_paths.py
1 parent 5bd9e03 commit 45369f2

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

docs/usage.md

+16
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,22 @@ want to generate and use a `compile_commands.json` to ensure the rewriter
2626
preprocesses each source file with the same command-line arguments as when it is
2727
compiled.
2828

29+
### Compile Command Paths
30+
31+
Note that `libclangTooling`, which `ia2-rewriter` uses, is very finicky
32+
about relative paths, so we suggest making all relative paths absolute.
33+
Furthermore, `ia2-rewriter` itself sometimes uses paths as keys,
34+
so we suggest making all paths canonical. We have a script,
35+
[`canonicalize_compile_command_paths.py`](../tools/rewriter/canonicalize_compile_command_paths.py),
36+
that does this automatically (doing its best to detect paths embedded in args).
37+
`libclangTooling` also requires compilation databases to be named exactly
38+
`compile_commands.json`, so this script assumes that as well,
39+
and must be run in the directory of the `compile_commands.json`, like this:
40+
41+
```sh
42+
(cd $build_directory && $ia2_dir/tools/rewriter/canonicalize_compile_command_paths.py)
43+
```
44+
2945
## Manual source changes
3046

3147
### Defining compartments

tools/rewriter/canonicalize_compile_command_paths.py

+10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@
1111
from pathlib import Path
1212

1313
def main():
14+
"""
15+
Assuming we're in a build directory containing a `compile_commands.json`,
16+
canonicalize (including making absolute) all paths in every compile command,
17+
including as part of arguments (detect as a best effort).
18+
19+
libclangTooling is finicky with relative paths,
20+
and it and other tools don't always handle non-canonical paths well,
21+
so making all paths in a `compile_commands.json` canonical is helpful.
22+
"""
23+
1424
cc_db = Path("compile_commands.json")
1525
cc_text = cc_db.read_text()
1626
cmds = json.loads(cc_text)

0 commit comments

Comments
 (0)