codeql/swift
Paolo Tranquilli 81de500301 Swift: fix import not working in all python versions 2023-02-14 10:40:05 +01:00
..
actions use the new actions/cache@v3 instead of my own fork 2022-12-21 21:10:55 +01:00
codegen Swift: fix import not working in all python versions 2023-02-14 10:40:05 +01:00
downgrades Swift: remove query predicates in upgrade/downgrade scripts 2023-02-09 17:24:27 +01:00
extractor Swift: extract availability info 2023-02-07 14:26:39 +01:00
integration-tests Swift: move regex test to integration tests 2023-02-07 10:21:37 +01:00
ql Merge pull request #12124 from hvitved/dataflow/stage1-dispatch 2023-02-13 13:13:43 +01:00
third_party Swift: remove header patch which is not needed any more 2022-12-20 15:28:52 +01:00
tools Swift: ignore sandbox-exec 2023-01-30 15:10:30 +01:00
xcode-autobuilder Swift: make xcode-autobuilder tester work with several tests 2022-10-19 16:20:32 +02:00
.clang-format Swift: first skeleton extractor 2022-04-12 12:40:59 +02:00
.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: wrap extractor with shell script 2022-12-13 09:07:37 +01:00
CMakeLists.txt Swift: enable VSCode to build extractor via CMake 2022-11-03 11:16:48 +01:00
README.md Update CodeQL CLI articles with migration message 2023-02-02 14:11:02 -05:00
codeql-extractor.yml Specify language names in extractor packs 2022-12-23 13:15:04 +00:00
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: some restructuring of codegen 2023-02-14 09:53:02 +01:00
schema_documentation.md Swift: tweaks to the schema doc documentation 2023-02-10 08:58:07 +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