The Swift front-end shelled out to a separate `swift-syntax-parse` executable
and read a JSON syntax tree back over a pipe. That kept the Swift toolchain off
the extractor's build path, so working on the other (tree-sitter based)
languages needed no Swift -- but it meant the extractor had to *find* that
executable at run time, and everything downstream of that was a workaround:
- the binary is a shell wrapper that sets `LD_LIBRARY_PATH` and execs
`swift-syntax-parse.real`, because the Swift runtime libraries have to sit
beside it;
- that only works in a flattened layout, so packaging went through
`codeql_pkg_runfiles` and the runtime libraries reached the pack only as a
side effect of shipping the parser;
- and the corpus tests skipped themselves when they could not find the binary.
A skip still prints `test result: ok`, so the suite silently tested nothing.
Supporting Swift is the current priority, so the extractor may now depend on
building the Swift half. Link `swift-syntax-rs` in and call `parse_to_json`
directly: `parse.rs` loses ~100 lines of process plumbing, and the tree is
necessarily produced by the swift-syntax build this extractor was built
against, so it cannot silently run a stale parser.
The parser survives as a debugging aid for looking at raw swift-syntax JSON:
echo 'let x = 1' | bazel run //unified/swift-syntax-rs:swift-syntax-parse
It is no longer shipped, so the wrapper, the `.real` split and the runfiles
packaging all go; the Swift runtime libraries are now packaged explicitly.
Linking Swift means the dynamic loader must resolve those libraries before
`main` runs. Bazel links against them through the toolchain's own directory,
which does not exist in an installed pack, so `swift_syntax_rs` now carries an
`$ORIGIN` runpath and the executable finds them beside itself. It arrives
through `CcInfo` rather than `rustc_flags` because `experimental_use_cc_common_link`
makes the link a `cc_common.link` action that `rustc_flags` never reaches.
`cargo test` can no longer build the tests without a local Swift toolchain, so
they run through Bazel, whose toolchain is hermetic on Linux. That also fixes
two things the old arrangement hid: `//unified/extractor:all_tests` covers all
three test files rather than only the corpus, and `test_corpus` now fails
instead of passing vacuously when it finds no cases at all.
`scripts/update-corpus.sh` drops the sandbox so the test can write the
regenerated `.output` files back through the runfiles symlinks. Passing that on
the command line rather than tagging the target keeps the ordinary test run
hermetic.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 297ff885-7c13-4202-a9d0-bc0b17f68d8e
CodeQL
This open source repository contains the standard CodeQL libraries and queries that power GitHub Advanced Security and the other application security products that GitHub makes available to its customers worldwide.
How do I learn CodeQL and run queries?
There is extensive documentation about the CodeQL language, writing CodeQL using the CodeQL extension for Visual Studio Code and using the CodeQL CLI.
Contributing
We welcome contributions to our standard library and standard checks. Do you have an idea for a new check, or how to improve an existing query? Then please go ahead and open a pull request! Before you do, though, please take the time to read our contributing guidelines. You can also consult our style guides to learn how to format your code for consistency and clarity, how to write query metadata, and how to write query help documentation for your query.
For information on contributing to CodeQL documentation, see the "contributing guide" for docs.
License
The code in this repository is licensed under the MIT License by GitHub.
The CodeQL CLI (including the CodeQL engine) is hosted in a different repository and is licensed separately. If you'd like to use the CodeQL CLI to analyze closed-source code, you will need a separate commercial license; please contact us for further help.
Visual Studio Code integration
If you use Visual Studio Code to work in this repository, there are a few integration features to make development easier.
CodeQL for Visual Studio Code
You can install the CodeQL for Visual Studio Code extension to get syntax highlighting, IntelliSense, and code navigation for the QL language, as well as unit test support for testing CodeQL libraries and queries.
Tasks
The .vscode/tasks.json file defines custom tasks specific to working in this repository. To invoke one of these tasks, select the Terminal | Run Task... menu option, and then select the desired task from the dropdown. You can also invoke the Tasks: Run Task command from the command palette.