codeql/swift
Paolo Tranquilli d7313082c9
Merge pull request #11466 from github/redsun82/cache
Swift: optimize bazel caching in CI
2022-11-29 14:31:16 +01:00
..
actions Swift: optimize bazel caching in CI 2022-11-29 11:43:54 +01:00
codegen Swift: reject uppercase acronyms in schema 2022-11-23 13:56:03 +01:00
downgrades Swift: add downgrades script to extractor pack 2022-11-23 12:15:29 +01:00
extractor Merge pull request #11382 from github/alexdenisov/swift-relax-file-archiving 2022-11-23 06:56:26 +01:00
integration-tests Merge pull request #11365 from github/redsun82/swift-integration-test-pack 2022-11-28 17:02:54 +01:00
ql Merge branch 'main' into constructor 2022-11-29 10:40:19 +00:00
third_party Swift: remove an `assert` from swift headers 2022-11-08 11:47:12 +01:00
tools Update qltest.sh 2022-11-04 13:04:24 +01:00
xcode-autobuilder Swift: make xcode-autobuilder tester work with several tests 2022-10-19 16:20:32 +02:00
.clang-format
.gitignore Swift: cmake generator for better IDE support 2022-10-13 15:25:24 +02:00
.pep8 Swift: implement python schema 2022-09-21 15:53:09 +02:00
.python-version Swift: bump actions/setup-python from 3 to 4 2022-10-19 18:10:42 +02:00
BUILD.bazel Swift: add downgrades script to extractor pack 2022-11-23 12:15:29 +01:00
CMakeLists.txt Swift: enable VSCode to build extractor via CMake 2022-11-03 11:16:48 +01:00
README.md Swift: remove unneeded trailing `/` in `README.md` 2022-10-31 09:55:03 +01:00
codeql-extractor.yml
create_extractor_pack.py Swift: add `qltest.sh` tests 2022-10-21 12:54:09 +02:00
prefix.dbscheme Swift: implement python schema 2022-09-21 15:53:09 +02:00
rules.bzl Swift: enable VSCode to build extractor via CMake 2022-11-03 11:16:48 +01:00
schema.py Swift: remove double newlines in schema 2022-11-15 15:00:30 +01:00

README.md

Swift on CodeQL

Warning

The Swift CodeQL package is an experimental and unsupported work in progress.

Building the Swift extractor

First ensure you have Bazel installed, for example with

brew install bazelisk

then from the ql directory run

bazel run //swift:create-extractor-pack    # --cpu=darwin_x86_64 # Uncomment on Arm-based Macs

which will install swift/extractor-pack.

Notice you can run bazel run :create-extractor-pack if you already are in the swift directory.

Using codeql ... --search-path=swift/extractor-pack will then pick up the Swift extractor. You can also use --search-path=., as the extractor pack is mentioned in the root codeql-workspace.yml. Alternatively, you can set up the search path in the per-user CodeQL configuration file .

Code generation

Run

bazel run //swift/codegen

to update generated files. This can be shortened to bazel run codegen if you are in the swift directory.

IDE setup

CLion and the native bazel plugin

You can use CLion with the official IntelliJ Bazel plugin, creating the project from scratch with default options. This is known to have issues on non-Linux platforms.

CMake project

The CMakeLists.txt file allows to load the Swift extractor as a CMake project, which allows integration into a wider variety of IDEs. Building with CMake also creates a compile_commands.json compilation database that can be picked up by even more IDEs. In particular, opening the swift directory in VSCode should work.

Debugging codeql database creation

If you want to debug a specific run of the extractor within an integration test or a complex codeql database create invocation, you can do so using gdbserver or lldb-server.

For example with gdbserver, you can

export CODEQL_EXTRACTOR_SWIFT_RUN_UNDER="gdbserver :1234"
export CODEQL_EXTRACTOR_SWIFT_RUN_UNDER_FILTER="SomeSwiftSource\.swift"  # can be any regex matching extractor args

before starting the database extraction, and when that source is encountered the extractor will be run under a gdbserver instance listening on port 1234. You can then attach to the running debugging server from gdb or your IDE. Please refer to your IDE's instructions for how to set up remote debugging.

In particular for breakpoints to work you might need to setup the following remote path mapping:

Remote Local
swift /absolute/path/to/codeql/swift
bazel-out /absolute/path/to/codeql/bazel-out