Commit Graph

75 Commits

Author SHA1 Message Date
Paolo Tranquilli
46c7ee0e4f Swift: refactor RUN_UNDER code 2022-10-31 09:51:20 +01:00
Paolo Tranquilli
80debe19e0 Swift: fix RUN_UNDER_FILTER check 2022-10-31 09:50:45 +01:00
Paolo Tranquilli
3dcdc739de Swift: add possibility to run the extractor under an env-specified tool
if `CODEQL_EXTRACTOR_SWIFT_RUN_UNDER` env variable is set, and either
* `CODEQL_EXTRACTOR_SWIFT_RUN_UNDER_FILTER` is not set, or
* it is set to a regexp matching any substring of the extractor call
then the extractor process is substituted with the command (and possibly
options) stated in `CODEQL_EXTRACTOR_SWIFT_RUN_UNDER`, followed by the
system arguments of the extractor itself (which should include the
extractor program itself at the start).

Before calling `exec`, `CODEQL_EXTRACTOR_SWIFT_RUN_UNDER` is unset to
avoid unpleasant loops.

An example usage is to run the extractor under `gdbserver :1234` when
the arguments match a given source file.
2022-10-28 14:12:27 +02:00
Paolo Tranquilli
521e6235b5 Swift: use std::filesystem and picoSHA2
This replaces usages of `llvm::fs` and string manipulation with
`std::filesystem`, also replacing `std::string` with
`std::filesystem::path` where it made sense.

Moreover MD5 hashing used in macOS file remapping was replaced by
SHA256 hashing using a small header-only SHA256 C++ library with an
MIT license, https://github.com/okdshin/PicoSHA2.

File contents hashing was relocated to the newly created `file` library
for later planned reuse.
2022-10-26 13:23:44 +02:00
Alex Denisov
c020bee529 Swift: remove VFS related code 2022-09-20 15:06:25 +02:00
Alex Denisov
3c12644ab1 Swift: add a guard around hashing to aboid use-after-destructor 2022-09-19 10:37:26 +02:00
Alex Denisov
c638789f3e Swift: open(2) interception 2022-09-16 12:02:16 +02:00
Paolo Tranquilli
daf1fa3c31 Swift: lock built swiftmodule traps in main
This should cover `-merge-modules` mode.

Dumping of the configuration to the target files was moved to a
separate pair of header/source files, as now it is also done in
`SwiftOutputRewrite.cpp`.
2022-07-29 16:27:55 +02:00
Paolo Tranquilli
065fecc57e Swift: extract precompiled swiftmodule files
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).
2022-07-29 11:10:03 +02:00
Alex Denisov
133a6caaa3 Swift: cleanup output rewriting code 2022-06-30 12:03:53 +02:00
Alex Denisov
35da75f685 Swift: rename method 2022-06-30 08:48:36 +02:00
Alex Denisov
4d81206a87 Swift: teach extractor to emit build artifacts for later consumption 2022-06-29 10:58:24 +02:00
Alex Denisov
488befb577 Swift: store TRAP files in a temporary folder until the extraction is complete
Currently, we have a number of assertions in the codebase and certain
assumptions about the AST. These don't always hold, sometimes leading to
a crash in the extractor.
The crashes leave incomplete TRAP files that cannot be imported into the
database.

With this change, we still get those incomplete TRAP files, but we also
get a database in the end (even thoough it is also incomplete as we
cannot import everything).
2022-06-29 07:17:06 +02:00
AlexDenisov
a59d7f6a85 Update swift/extractor/main.cpp 2022-04-28 16:52:34 +02:00
Alex Denisov
9c73ae5a97 Swift: teach extractor to not produce artifacts 2022-04-28 13:18:20 +02:00
Alex Denisov
5db18bb845 Swift: add a comment clarifying swift::FrontendObserver 2022-04-26 13:35:10 +02:00
Alex Denisov
e2332fc5ec Swift: Replace SwiftExtractor class with a function 2022-04-26 13:32:14 +02:00
Alex Denisov
ebd2ff4fc0 Swift: rename classes to reflect they belong to Swift 2022-04-26 11:33:35 +02:00
Alex Denisov
81e4f9165e Swift: remove -frontend option as we don't need it yet 2022-04-26 11:27:41 +02:00
Alex Denisov
5b20d580be Swift: use parenthesis instead of curly braces 2022-04-25 12:26:34 +02:00
Alex Denisov
8bcdfb2e4f Swift: initialize LLVM
No need to shutdown LLVM, it's done by the PROGRAM_START macro
2022-04-25 11:49:21 +02:00
Alex Denisov
462133e0f0 Swift: add more comments 2022-04-25 11:48:51 +02:00
Alex Denisov
62d36a29f7 Swift: Extract files 2022-04-22 08:48:38 +02:00
Paolo Tranquilli
e68172f4b0 Swift: fetch prebuilt swift and link against it
This is known to break linux integration in sembuild.
2022-04-13 16:22:27 +02:00
Paolo Tranquilli
95dbf2d666 Swift: first skeleton extractor
This adds a first dummy extractor for swift.

Running `bazel run //swift:install` will create an `extractor_pack`
directory in `swift`. From that moment providing `--search-path=swift`
will pick up the extractor.
2022-04-12 12:40:59 +02:00