Skip to content

Commit 5ffd41e

Browse files
docs: Add more docs on cross-repo (#365)
1 parent 9dc3044 commit 5ffd41e

File tree

4 files changed

+96
-8
lines changed

4 files changed

+96
-8
lines changed

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@ scip-clang is a precise code indexer based on Clang 16,
44
which supports cross-repository code navigation for C and C++
55
in Sourcegraph.
66

7-
Here are some code navigation examples in [llvm/llvm-project](https://sourcegraph.com/github.com/llvm/llvm-project):
8-
- [Find references for #include](https://sourcegraph.com/github.com/llvm/llvm-project@97a03eb2eb5acf269db6253fe540626b52950f97/-/blob/llvm/include/llvm/ADT/SmallSet.h?L1:1-1:81#tab=references)
9-
- [Find references for macros](https://sourcegraph.com/github.com/llvm/llvm-project@daad48d6b236d74c6b29daebba46289b98104241/-/blob/llvm/include/llvm/Support/Debug.h?L101:9-101:19#tab=references)
10-
- [Find references for types](https://sourcegraph.com/github.com/llvm/llvm-project@daad48d6b236d74c6b29daebba46289b98104241/-/blob/clang/include/clang/AST/ASTContext.h?L1472:34-1472:45#tab=references)
7+
Here are some code navigation examples:
8+
- [Cross-repository navigation in Boost](https://sourcegraph.com/github.com/boostorg/assert@f10ddd608e087a89ee5bfc41cf2987cc5ef61473/-/blob/include/boost/assert.hpp?L60:10-60:22#tab=references)
9+
- In [Chromium](https://sourcegraph.com/github.com/chromium/chromium@b21c706/-/blob/base/atomic_ref_count.h?L19:7-19:21#tab=references).
10+
- In [llvm/llvm-project](https://sourcegraph.com/github.com/llvm/llvm-project):
11+
- [Find references for #include](https://sourcegraph.com/github.com/llvm/llvm-project@97a03eb2eb5acf269db6253fe540626b52950f97/-/blob/llvm/include/llvm/ADT/SmallSet.h?L1:1-1:81#tab=references)
12+
- [Find references for macros](https://sourcegraph.com/github.com/llvm/llvm-project@daad48d6b236d74c6b29daebba46289b98104241/-/blob/llvm/include/llvm/Support/Debug.h?L101:9-101:19#tab=references)
13+
- [Find references for types](https://sourcegraph.com/github.com/llvm/llvm-project@daad48d6b236d74c6b29daebba46289b98104241/-/blob/clang/include/clang/AST/ASTContext.h?L1472:34-1472:45#tab=references)
1114

12-
You can also test out [code navigation in Chromium](https://sourcegraph.com/github.com/chromium/chromium@b21c706/-/blob/base/atomic_ref_count.h?L19:7-19:21#tab=references).
15+
<picture>
16+
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/sourcegraph/scip-clang/assets/93103176/08b3aa95-c3ee-4c56-9920-20dfa4a7070d">
17+
<img alt="Boost cross-repository Find References screenshot" src="https://github.com/sourcegraph/scip-clang/assets/93103176/1baf9a40-37ac-4896-bd1b-dc453730f91b">
18+
</picture>
1319

1420
<picture>
1521
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/sourcegraph/scip-clang/assets/93103176/54cc557e-16c8-4890-b9d1-b40d6e215084">

docs/CrossRepo.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ The package map JSON file contains a list of objects in the following format:
2424
]
2525
```
2626

27+
As an example, you can see [scip-clang's own package map file](/tools/package-map.json).
28+
2729
1. The `path` key may be an absolute path, or a path relative to the current directory
28-
(which must be the project root).
30+
(which must be the project root). For example:
31+
- For projects using Bazel, these paths will generally look like:
32+
`./bazel-myproject/external/com_company_libcool`.
2933
2. The `package` key consists of a `name` followed by an `@` separator and a `version`.
30-
- The name and version must only contain characters belonging to `[a-zA-Z0-9_\-.]`.
34+
- The name and version must only contain characters belonging to `[a-zA-Z0-9_\-\.]`.
3135
- The version should be chosen based on release information.
3236
For example, if you use git tags to mark releases in repos,
3337
and repositories only depend on tagged releases (instead of arbitrary commits),
@@ -44,7 +48,10 @@ Files under the directories `path/to/package1_root`
4448
will be treated as belonging to `package1`'s `v1` version.
4549

4650
If one package root is a prefix of another, package information
47-
is assigned based on the longest match.
51+
is assigned based on the longest match. For example, if you're
52+
using git submodules, then packages in subdirectories will be
53+
recognized correctly if there is a package map entry
54+
pointing to the subdirectory.
4855

4956
For cross-repository navigation to work,
5057
`package1` must also be indexed with the same version information:

docs/IndexingProjects.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
For the sake of this example, I'll only describe how
66
to index scip-clang with cross-repo code navigation support
77
for [Abseil](https://github.com/abseil/abseil-cpp/).
8+
See [tools/package-map.json](/tools/package-map.json) for more entries
9+
10+
> Aside: For a full index, one also needs to run `sed -e 's|$(STACK_FRAME_UNLIMITED)||'` on
11+
> the compilation database due to the unexpanded Make variable used
12+
> in compilation commands for LLVM which prevents type-checking from running.
813
914
First, index Abseil.
1015

@@ -28,6 +33,8 @@ jq '[.[] | select(.file | (contains("indexer/") or startswith("test/") or contai
2833
./bazel-bin/indexer/scip-clang --compdb-path=min.json --package-map-path=package-map.json
2934
```
3035

36+
> Aside: If indexing `scip-clang` along with
37+
3138
Here, the `package-map.json` is as follows:
3239

3340
```json
@@ -40,6 +47,11 @@ Here, the `package-map.json` is as follows:
4047
The exact versions need to be determined based on current tag
4148
or hashes provided to Bazel.
4249

50+
Other notes:
51+
- Indexing rapidjson requires a recursive clone since it uses GTest
52+
via a submodule.
53+
- Indexing spdlog requires pass `-DSPDLOG_ENABLE_TESTING=ON` to cmake.
54+
4355
## LLVM
4456

4557
Tested environments: Ubuntu 18.04, Ubuntu 22.04, macOS 13.
@@ -130,3 +142,54 @@ meson setup ../postgres-build .
130142
ninja -C ../postgres-build
131143
scip-clang --compdb-path=../postgres-build/compile_commands.json
132144
```
145+
146+
## Boost
147+
148+
Here are the steps for a cross-repo indexing setup.
149+
150+
> CAVEAT: At the time of writing, scip-clang doesn't have explicit support
151+
> for indexing multiple projects at once (see https://github.com/sourcegraph/scip-clang/issues/360)
152+
> so the instructions below will end up duplicating a lot of work,
153+
> since the compilation database is not pruned based on dependencies.
154+
>
155+
> The overall indexing will take about 96 core hours on a GCP N2 instance.
156+
157+
First, do a recursive clone of the boost monorepo.
158+
159+
```bash
160+
git clone https://github.com/boostorg/boost --recursive
161+
cd boost
162+
git checkout boost-1.82.0
163+
cmake -B build -DENABLE_TESTING=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
164+
```
165+
166+
Invoke the indexer for each project with this Python script:
167+
168+
```python
169+
import json
170+
import os
171+
import subprocess
172+
173+
cwd = os.getcwd()
174+
175+
dirs = []
176+
pmap = []
177+
for dirname in os.listdir("./libs"):
178+
abs_path = "{}/libs/{}".format(cwd, dirname)
179+
if not os.path.isdir(abs_path):
180+
continue
181+
dirs.append(abs_path)
182+
pmap.append({"path": abs_path, "package": "boost-{}@boost-1.82.0".format(dirname)})
183+
184+
with open('package-map.json', 'w') as f:
185+
json.dump(pmap, f)
186+
187+
for d in dirs:
188+
if os.path.isfile(d + "/index.scip"):
189+
continue
190+
print("Indexing {}".format(d))
191+
res = subprocess.run(["scip-clang --package-map-path=../../package-map.json --compdb-path=../../build/compile_commands.json"], cwd=d, shell=True)
192+
if res.returncode != 0:
193+
continue
194+
subprocess.run(["src code-intel upload"], cwd=d, shell=True, env={"SRC_ACCESS_TOKEN": os.getenv("SRC_ACCESS_TOKEN"), "PATH": os.getenv("PATH")})
195+
```

tools/package-map.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{"path": ".", "package": "scip-clang@134a873"},
3+
{"path": "./bazel-scip-clang/external/com_google_absl", "package": "abseil-cpp@4ffaea74"},
4+
{"path": "/home/varun/.cache/bazel/_bazel_varun/e45ff3cfa68a557b274978dc134d6467/external/llvm-raw", "package": "llvm-project@e0f3110b854a"},
5+
{"path": "./bazel-scip-clang/external/boost/libs/date_time", "package": "boost-date_time@boost-1.82.0"},
6+
{"path": "./bazel-scip-clang/external/boost/libs/interprocess", "package": "boost-interprocess@boost-1.82.0"},
7+
{"path": "./bazel-scip-clang/external/boost/libs/process", "package": "boost-process@boost-1.82.0"},
8+
{"path": "./bazel-scip-clang/external/rapidjson", "package": "rapidjson@a98e9999"},
9+
{"path": "./bazel-scip-clang/external/cxxopts", "package": "cxxopts@3.0.0"},
10+
{"path": "./bazel-scip-clang/external/spdlog", "package": "spdlog@edc51df1"},
11+
{"path": "./bazel-scip-clang/external/doctest", "package": "doctest@2.4.9"}
12+
]

0 commit comments

Comments
 (0)