|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Build a local Python extractor pack from source. |
| 4 | +# |
| 5 | +# Usage with the CodeQL CLI (run from the repository root): |
| 6 | +# |
| 7 | +# codeql database create <db> -l python -s <src> --search-path . |
| 8 | +# codeql test run --search-path . python/ql/test/<test-dir> |
| 9 | +# |
| 10 | +set -eux |
| 11 | + |
| 12 | +if [[ "$OSTYPE" == "linux-gnu"* ]]; then |
| 13 | + platform="linux64" |
| 14 | +elif [[ "$OSTYPE" == "darwin"* ]]; then |
| 15 | + platform="osx64" |
| 16 | +else |
| 17 | + echo "Unknown OS" |
| 18 | + exit 1 |
| 19 | +fi |
| 20 | + |
| 21 | +cd "$(dirname "$0")/.." |
| 22 | + |
| 23 | +# Build the tsg-python Rust binary |
| 24 | +(cd extractor/tsg-python && cargo build --release) |
| 25 | +tsg_bin="extractor/tsg-python/target/release/tsg-python" |
| 26 | + |
| 27 | +# Generate python3src.zip from the Python extractor source. |
| 28 | +# make_zips.py creates the zip in the source directory and then copies it to the |
| 29 | +# given output directory. We use a temporary directory to avoid a same-file copy |
| 30 | +# error, then move the zip back. |
| 31 | +tmpdir=$(mktemp -d) |
| 32 | +trap 'rm -rf "$tmpdir"' EXIT |
| 33 | +(cd extractor && python3 make_zips.py "$tmpdir") |
| 34 | +cp "$tmpdir/python3src.zip" extractor/python3src.zip |
| 35 | + |
| 36 | +# Assemble the extractor pack |
| 37 | +rm -rf extractor-pack |
| 38 | +mkdir -p extractor-pack/tools/${platform} |
| 39 | + |
| 40 | +# Root-level metadata and schema files |
| 41 | +cp codeql-extractor.yml extractor-pack/ |
| 42 | +cp ql/lib/semmlecode.python.dbscheme extractor-pack/ |
| 43 | +cp ql/lib/semmlecode.python.dbscheme.stats extractor-pack/ |
| 44 | + |
| 45 | +# Python extractor engine files (into tools/) |
| 46 | +cp extractor/python_tracer.py extractor-pack/tools/ |
| 47 | +cp extractor/index.py extractor-pack/tools/ |
| 48 | +cp extractor/setup.py extractor-pack/tools/ |
| 49 | +cp extractor/convert_setup.py extractor-pack/tools/ |
| 50 | +cp extractor/get_venv_lib.py extractor-pack/tools/ |
| 51 | +cp extractor/imp.py extractor-pack/tools/ |
| 52 | +cp extractor/LICENSE-PSF.md extractor-pack/tools/ |
| 53 | +cp extractor/python3src.zip extractor-pack/tools/ |
| 54 | +cp -r extractor/data extractor-pack/tools/ |
| 55 | + |
| 56 | +# Shell tool scripts (autobuild, pre-finalize, lgtm-scripts) |
| 57 | +cp tools/autobuild.sh extractor-pack/tools/ |
| 58 | +cp tools/autobuild.cmd extractor-pack/tools/ |
| 59 | +cp tools/pre-finalize.sh extractor-pack/tools/ |
| 60 | +cp tools/pre-finalize.cmd extractor-pack/tools/ |
| 61 | +cp -r tools/lgtm-scripts extractor-pack/tools/ |
| 62 | + |
| 63 | +# Downgrades |
| 64 | +cp -r downgrades extractor-pack/ |
| 65 | + |
| 66 | +# Platform-specific Rust binary |
| 67 | +cp "${tsg_bin}" extractor-pack/tools/${platform}/tsg-python |
0 commit comments