-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Swift: first skeleton extractor #8700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
95dbf2d
Swift: first skeleton extractor
redsun82 664d5ba
Swift: moved install to a separate package
redsun82 13b2442
Bazel: code reorganization
redsun82 a205b46
Bazel: reorganization
redsun82 f2f9961
.gitignore CLion project files
redsun82 6440242
Swift+Bazel: apply review comments
redsun82 8ef2878
Swift: do not fail pack creation if dir does not exist
redsun82 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
build --copt="-std=c++17" | ||
|
||
try-import %workspace%/local.bazelrc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
5.0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,12 @@ | ||
# Please notice that any bazel targets and definitions in this repository are currently experimental | ||
# and for internal use only. | ||
|
||
workspace(name = "ql") | ||
|
||
load("//misc/bazel:workspace.bzl", "ql_workspace") | ||
|
||
ql_workspace() | ||
|
||
load("//misc/bazel:workspace_deps.bzl", "ql_workspace_deps") | ||
|
||
ql_workspace_deps() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
codeql_platform = select({ | ||
"@platforms//os:linux": "linux64", | ||
"@platforms//os:macos": "osx64", | ||
"@platforms//os:windows": "win64", | ||
}) |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") | ||
|
||
def ql_workspace(): | ||
maybe( | ||
repo_rule = http_archive, | ||
name = "rules_pkg", | ||
sha256 = "62eeb544ff1ef41d786e329e1536c1d541bb9bcad27ae984d57f18f314018e66", | ||
urls = [ | ||
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.6.0/rules_pkg-0.6.0.tar.gz", | ||
"https://github.com/bazelbuild/rules_pkg/releases/download/0.6.0/rules_pkg-0.6.0.tar.gz", | ||
], | ||
) | ||
|
||
maybe( | ||
repo_rule = http_archive, | ||
name = "platforms", | ||
redsun82 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
sha256 = "460caee0fa583b908c622913334ec3c1b842572b9c23cf0d3da0c2543a1a157d", | ||
urls = [ | ||
"https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.3/platforms-0.0.3.tar.gz", | ||
"https://github.com/bazelbuild/platforms/releases/download/0.0.3/platforms-0.0.3.tar.gz", | ||
], | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") | ||
|
||
def ql_workspace_deps(): | ||
rules_pkg_dependencies() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
BasedOnStyle: Chromium | ||
ColumnLimit: 100 | ||
IndentWidth: 2 | ||
SortIncludes: false | ||
AllowShortIfStatementsOnASingleLine: WithoutElse | ||
AlwaysBreakBeforeMultilineStrings: false | ||
Standard: c++17 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"provide": [ | ||
"ql/lib/qlpack.yml", | ||
"ql/test/qlpack.yml", | ||
"extractor-pack/codeql-extractor.yml" | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
extractor-pack |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
load("@rules_pkg//:mappings.bzl", "pkg_attributes", "pkg_filegroup", "pkg_files") | ||
load("@rules_pkg//:install.bzl", "pkg_install") | ||
load("//:defs.bzl", "codeql_platform") | ||
|
||
pkg_files( | ||
name = "dbscheme", | ||
srcs = [ | ||
"ql/lib/swift.dbscheme", | ||
"ql/lib/swift.dbscheme.stats", | ||
], | ||
) | ||
|
||
pkg_files( | ||
name = "qltest", | ||
srcs = ["tools/qltest.sh"], | ||
attributes = pkg_attributes(mode = "0755"), | ||
prefix = "tools", | ||
) | ||
|
||
pkg_files( | ||
name = "manifest", | ||
srcs = ["codeql-extractor.yml"], | ||
) | ||
|
||
pkg_filegroup( | ||
name = "extractor-pack-generic", | ||
srcs = [ | ||
":dbscheme", | ||
":manifest", | ||
":qltest", | ||
], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
pkg_files( | ||
name = "extractor", | ||
srcs = ["//swift/extractor"], | ||
attributes = pkg_attributes(mode = "0755"), | ||
prefix = "tools/" + codeql_platform, | ||
) | ||
|
||
pkg_filegroup( | ||
name = "extractor-pack-arch", | ||
srcs = [":extractor"], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
pkg_filegroup( | ||
name = "extractor-pack", | ||
srcs = [ | ||
":extractor-pack-arch", | ||
":extractor-pack-generic", | ||
], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
pkg_install( | ||
redsun82 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
name = "_create_extractor_pack", | ||
srcs = ["//swift:extractor-pack"], | ||
) | ||
|
||
py_binary( | ||
name = "create-extractor-pack", | ||
srcs = ["tools/create_extractor_pack.py"], | ||
main = "tools/create_extractor_pack.py", | ||
deps = [":_create_extractor_pack"], | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## Warning | ||
|
||
The Swift codeql package is an experimental and unsupported work in progress. | ||
redsun82 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Usage | ||
|
||
Run `bazel run //swift:create-extractor-pack`, which will install `swift/extractor-pack`. | ||
Using `--search-path=swift/extractor-pack` will then pick up the Swift extractor. You can also use | ||
`--search-path=swift`, as the extractor pack is mentioned in `swift/.codeqlmanifest.json`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name: "swift" | ||
display_name: "Swift" | ||
version: 0.0.1 | ||
column_kind: "utf8" | ||
legacy_qltest_extraction: true | ||
file_types: | ||
- name: swift | ||
display_name: Swift files | ||
extensions: | ||
- .swift |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
cc_binary( | ||
name = "extractor", | ||
srcs = ["main.cpp"], | ||
target_compatible_with = select({ | ||
redsun82 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"@platforms//os:linux": [], | ||
"@platforms//os:macos": [], | ||
"//conditions:default": ["@platforms//:incompatible"], | ||
}), | ||
visibility = ["//swift:__pkg__"], | ||
redsun82 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <fstream> | ||
#include <iomanip> | ||
#include <stdlib.h> | ||
|
||
int main() { | ||
if (auto trapDir = getenv("CODEQL_EXTRACTOR_SWIFT_TRAP_DIR")) { | ||
std::string file = trapDir; | ||
file += "/my_first.trap"; | ||
if (std::ofstream out{file}) { | ||
out << "answer_to_life_the_universe_and_everything(42)\n"; | ||
} | ||
} | ||
return 0; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name: codeql/swift-all | ||
version: 0.0.0 | ||
dbscheme: swift.dbscheme | ||
extractor: swift | ||
library: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
sourceLocationPrefix( | ||
string prefix: string ref | ||
); | ||
|
||
answer_to_life_the_universe_and_everything( | ||
int answer: int ref | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<dbstats> | ||
<typesizes /> | ||
<stats /> | ||
</dbstats> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
| 42 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from int answer | ||
where answer_to_life_the_universe_and_everything(answer) | ||
select answer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name: codeql-swift-tests | ||
version: 0.0.0 | ||
dependencies: | ||
codeql/swift-all: "*" | ||
tests: . | ||
extractor: swift |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import os | ||
import pathlib | ||
import shutil | ||
import sys | ||
from swift._create_extractor_pack_install_script import main | ||
|
||
try: | ||
workspace_dir = pathlib.Path(os.environ['BUILD_WORKSPACE_DIRECTORY']) | ||
except KeyError: | ||
print("this should be run with bazel run", file=sys.stderr) | ||
sys.exit(1) | ||
|
||
dest_dir = workspace_dir / 'swift' / 'extractor-pack' | ||
shutil.rmtree(dest_dir, ignore_errors=True) | ||
os.environ['DESTDIR'] = str(dest_dir) | ||
main(sys.argv) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
|
||
mkdir -p "$CODEQL_EXTRACTOR_SWIFT_TRAP_DIR" | ||
|
||
exec "$CODEQL_EXTRACTOR_SWIFT_ROOT/tools/$CODEQL_PLATFORM/extractor" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.