mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Previously we were not extracting any `swiftmodule` file that was not a system or a built-in one. This was done to avoid re-extracting `swiftmodule` files that were built previously in the same build, but it turned out to be too eager, as there are legitimate cases where a non-system, non-built-in precompiled swift module can be used. An example of that is the `PackageDescription` module used in Swift Package Manager manifest files (`Package.swift`). We now relax the test and trigger module extraction on all loaded modules that do not have source files (we trigger source file extraction for those). The catch, is that we also create empty trap files for current output `swiftmodule` files (including possible alias locations set up by XCode). This means that if a following extractor run loads a previously built `swiftmodule` file, although it will trigger module extraction, this will however be skipped as it will find its target file already present (this is done via the `TargetFile` semantics).
83 lines
2.3 KiB
Python
Executable File
83 lines
2.3 KiB
Python
Executable File
#!/bin/env python3
|
|
"""
|
|
recreation of internal `integration-tests-runner.py` to run the tests locally, with minimal
|
|
and swift-specialized functionality.
|
|
|
|
This runner requires:
|
|
* a codeql CLI binary in PATH
|
|
* `bazel run //swift:create_extractor_pack` to have been run
|
|
"""
|
|
|
|
import pathlib
|
|
import os
|
|
import sys
|
|
import subprocess
|
|
import argparse
|
|
import shutil
|
|
import platform
|
|
|
|
this_dir = pathlib.Path(__file__).parent
|
|
|
|
|
|
def options():
|
|
p = argparse.ArgumentParser()
|
|
p.add_argument("--test-dir", "-d", type=pathlib.Path, action="append")
|
|
#FIXME: the following should be the default
|
|
p.add_argument("--check-databases", action="store_true")
|
|
p.add_argument("--learn", action="store_true")
|
|
p.add_argument("--threads", "-j", type=int, default=0)
|
|
return p.parse_args()
|
|
|
|
|
|
def execute_test(path):
|
|
shutil.rmtree(path.parent / "db", ignore_errors=True)
|
|
return subprocess.run([sys.executable, "-u", path.name], cwd=path.parent).returncode == 0
|
|
|
|
def skipped(test):
|
|
return platform.system() != "Darwin" and "osx-only" in test.parts
|
|
|
|
|
|
def main(opts):
|
|
test_dirs = opts.test_dir or [this_dir]
|
|
tests = [t for d in test_dirs for t in d.rglob("test.py") if not skipped(t)]
|
|
|
|
if not tests:
|
|
print("No tests found", file=sys.stderr)
|
|
return False
|
|
|
|
os.environ["PYTHONPATH"] = str(this_dir)
|
|
failed_db_creation = []
|
|
succesful_db_creation = []
|
|
for t in tests:
|
|
(succesful_db_creation if execute_test(t) else failed_db_creation).append(t)
|
|
|
|
if succesful_db_creation:
|
|
codeql_root = this_dir.parents[1]
|
|
cmd = [
|
|
"codeql", "test", "run",
|
|
f"--search-path={codeql_root}",
|
|
"--keep-databases",
|
|
"--dataset=db/db-swift",
|
|
f"--threads={opts.threads}",
|
|
]
|
|
if opts.check_databases:
|
|
cmd.append("--check-databases")
|
|
else:
|
|
cmd.append("--no-check-databases")
|
|
if opts.learn:
|
|
cmd.append("--learn")
|
|
cmd.extend(str(t.parent) for t in succesful_db_creation)
|
|
ql_test_success = subprocess.run(cmd).returncode == 0
|
|
|
|
if failed_db_creation:
|
|
print("Database creation failed:", file=sys.stderr)
|
|
for t in failed_db_creation:
|
|
print(" ", t.parent, file=sys.stderr)
|
|
return False
|
|
|
|
return ql_test_success
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(0 if main(options()) else 1)
|