-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathautobuild.py
More file actions
46 lines (37 loc) · 1.46 KB
/
autobuild.py
File metadata and controls
46 lines (37 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import os
import json
import subprocess
"""
run "cargo metadata --format-version=1"
"""
def get_cargo_metadata():
metadata = json.loads(subprocess.check_output(
["cargo", "metadata", "--format-version=1"]))
return metadata
CODEQL_EXTRACTOR_RUST_ROOT = os.environ.get("CODEQL_EXTRACTOR_RUST_ROOT")
CODEQL_PLATFORM = os.environ.get("CODEQL_PLATFORM")
database = os.environ.get("CODEQL_EXTRACTOR_RUST_WIP_DATABASE")
scratch_dir = os.environ.get("CODEQL_EXTRACTOR_RUST_SCRATCH_DIR")
metadata = get_cargo_metadata()
metadata_file = os.path.join(scratch_dir, "metadata_file.yaml")
os.makedirs(scratch_dir, exist_ok=True)
with open(metadata_file, "w") as f:
f.write("---\n")
f.write(json.dumps(metadata, indent=4))
subprocess.run(["codeql", "database", "index-files", database,
"-lyaml", "--working-dir", scratch_dir, "--include", "metadata_file.yaml"])
paths = set()
for package in metadata['packages']:
for target in package['targets']:
if 'lib' in target['kind'] or 'bin' in target['kind']:
src_path = target['src_path']
paths.add(os.path.dirname(src_path))
autobuild = "{root}/tools/{platform}/autobuild".format(
root=CODEQL_EXTRACTOR_RUST_ROOT, platform=CODEQL_PLATFORM)
for path in paths:
if not path.startswith(os.getcwd()):
env = os.environ.copy()
env['CODEQL_EXTRACTOR_RUST_OPTION_EXCLUDE_BODIES'] = "true"
else:
env = None
subprocess.run([autobuild], cwd=path, env=env)