Skip to content

Commit 830d4c5

Browse files
committed
Rust: extract sources of crates
1 parent e6eaf5e commit 830d4c5

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

rust/tools/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ load("//misc/bazel:pkg.bzl", "codeql_pkg_files")
22

33
codeql_pkg_files(
44
name = "tools",
5-
srcs = glob(["*.cmd"]),
5+
srcs = glob(["*.cmd", "autobuild.py"]),
66
exes = glob(["*.sh"]),
77
visibility = ["//rust:__pkg__"],
88
)

rust/tools/autobuild.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
import os
3+
import json
4+
import subprocess
5+
6+
"""
7+
run "cargo metadata --format-version=1"
8+
"""
9+
10+
11+
def get_cargo_metadata():
12+
metadata = json.loads(subprocess.check_output(
13+
["cargo", "metadata", "--format-version=1"]))
14+
return metadata
15+
16+
17+
CODEQL_EXTRACTOR_RUST_ROOT = os.environ.get("CODEQL_EXTRACTOR_RUST_ROOT")
18+
CODEQL_PLATFORM = os.environ.get("CODEQL_PLATFORM")
19+
metadata = get_cargo_metadata()
20+
for package in metadata['packages']:
21+
for target in package['targets']:
22+
if 'lib' in target['kind']:
23+
src_path = target['src_path']
24+
dir = os.path.dirname(src_path)
25+
autobuild = "{root}/tools/{platform}/autobuild".format(
26+
root=CODEQL_EXTRACTOR_RUST_ROOT, platform=CODEQL_PLATFORM)
27+
subprocess.run([autobuild], cwd=dir)

rust/tools/autobuild.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
set -eu
44

55
export RUST_BACKTRACE=1
6-
exec "$CODEQL_EXTRACTOR_RUST_ROOT/tools/$CODEQL_PLATFORM/autobuild"
6+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
7+
8+
exec /usr/bin/env python "${SCRIPT_DIR}/autobuild.py"

0 commit comments

Comments
 (0)