Rust: make ql tests extract files together

For the moment this removes the possibility to set custom flags or env
variables for the extractor via comments, but that can be added back
easily if needed with a different mechanism (like an `env` file).
This commit is contained in:
Paolo Tranquilli
2024-09-12 09:13:29 +02:00
parent 076dd07cdc
commit aeae922ef3
3 changed files with 14 additions and 18 deletions

View File

@@ -1,3 +1,4 @@
Cargo.toml
Cargo.lock
lib.rs
target/

View File

@@ -1 +1,2 @@
| lib.rs:0:0:0:0 | lib.rs | DbFile | getName: | lib.rs |
| test.rs:0:0:0:0 | test.rs | DbFile | getName: | test.rs |

View File

@@ -7,26 +7,20 @@ export RUST_BACKTRACE=full
QLTEST_LOG="$CODEQL_EXTRACTOR_RUST_LOG_DIR"/qltest.log
EXTRACTOR="$CODEQL_EXTRACTOR_RUST_ROOT/tools/$CODEQL_PLATFORM/extractor"
echo > lib.rs
for src in *.rs; do
echo -e "[workspace]\n\n[package]\nname = \"test\"\nversion=\"0.0.1\"\n[lib]\npath=\"$src\"\n" > Cargo.toml
env=()
opts=("$src")
opts+=($(sed -n '1 s=//codeql-extractor-options:==p' $src))
expected_status=$(sed -n 's=//codeql-extractor-expected-status:[[:space:]]*==p' $src)
expected_status=${expected_status:-0}
env+=($(sed -n '1 s=//codeql-extractor-env:==p' $src))
echo >> $QLTEST_LOG
echo "env ${env[@]} $EXTRACTOR ${opts[@]}" >> "$QLTEST_LOG"
env "${env[@]}" "$EXTRACTOR" "${opts[@]}" >> $QLTEST_LOG 2>&1
actual_status=$?
if [[ $actual_status != $expected_status ]]; then
FAILED=1
fi
echo "mod ${src%.rs};" >> lib.rs
done
rm -rf Cargo.*
if [ -n "$FAILED" ]; then
cat > Cargo.toml << EOF
[workspace]
[package]
name = "test"
version="0.0.1"
[lib]
path="lib.rs"
EOF
"$EXTRACTOR" *.rs >> "$QLTEST_LOG"
if [[ "$?" != 0 ]]; then
cat "$QLTEST_LOG" # Show compiler errors on extraction failure
exit 1
fi