Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust: extract sources of crates #18523

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust/tools/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ load("//misc/bazel:pkg.bzl", "codeql_pkg_files")

codeql_pkg_files(
name = "tools",
srcs = glob(["*.cmd"]),
srcs = glob(["*.cmd", "autobuild.py"]),
exes = glob(["*.sh"]),
visibility = ["//rust:__pkg__"],
)
27 changes: 27 additions & 0 deletions rust/tools/autobuild.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

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")
metadata = get_cargo_metadata()
for package in metadata['packages']:
for target in package['targets']:
if 'lib' in target['kind']:
src_path = target['src_path']
dir = os.path.dirname(src_path)
autobuild = "{root}/tools/{platform}/autobuild".format(
root=CODEQL_EXTRACTOR_RUST_ROOT, platform=CODEQL_PLATFORM)
subprocess.run([autobuild], cwd=dir)
4 changes: 3 additions & 1 deletion rust/tools/autobuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
set -eu

export RUST_BACKTRACE=1
exec "$CODEQL_EXTRACTOR_RUST_ROOT/tools/$CODEQL_PLATFORM/autobuild"
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

exec /usr/bin/env python "${SCRIPT_DIR}/autobuild.py"
Loading