forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
20 changed files
with
216 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 |
Empty file.
This file contains 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,45 @@ | ||
# Please notice that any bazel targets and definitions in this repository are currently experimental | ||
# and for internal use only. | ||
|
||
workspace(name = "ql") | ||
|
||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
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", | ||
], | ||
) | ||
|
||
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") | ||
|
||
rules_pkg_dependencies() | ||
|
||
http_archive( | ||
name = "platforms", | ||
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", | ||
], | ||
) | ||
|
||
http_archive( | ||
name = "bazel_skylib", | ||
sha256 = "c6966ec828da198c5d9adbaa94c05e3a1c7f21bd012a0b29ba8ddbccb2c93b0d", | ||
urls = [ | ||
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz", | ||
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz", | ||
], | ||
) | ||
|
||
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") | ||
|
||
bazel_skylib_workspace() | ||
|
||
load("@ql//:defs.bzl", "ql_utils") | ||
|
||
ql_utils(name = "utils") |
This file contains 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
This file contains 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,19 @@ | ||
codeql_platform = select({ | ||
"@platforms//os:linux": "linux64", | ||
"@platforms//os:macos": "osx64", | ||
"@platforms//os:windows": "win64", | ||
}) | ||
|
||
_paths_bzl = """ | ||
def source_dir(): | ||
return '%s/' + native.package_name() | ||
""" | ||
|
||
def _ql_utils_impl(repository_ctx): | ||
root = repository_ctx.path(Label("@ql//:WORKSPACE.bazel")).realpath.dirname | ||
repository_ctx.file("BUILD.bazel") | ||
repository_ctx.file("paths.bzl", content = _paths_bzl % root) | ||
|
||
ql_utils = repository_rule( | ||
implementation = _ql_utils_impl, | ||
) |
This file contains 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 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 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 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,66 @@ | ||
load("@rules_pkg//:mappings.bzl", "pkg_attributes", "pkg_filegroup", "pkg_files") | ||
load("@rules_pkg//:install.bzl", "pkg_install") | ||
load("@ql//:defs.bzl", "codeql_platform") | ||
load("@bazel_skylib//rules:native_binary.bzl", "native_binary") | ||
load("@utils//:paths.bzl", "source_dir") | ||
|
||
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( | ||
name = "install", | ||
srcs = [":extractor-pack"], | ||
args = [ | ||
"--destdir", | ||
source_dir() + "/extractor_pack", | ||
], | ||
) |
This file contains 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,8 @@ | ||
## Warning | ||
|
||
The Swift codeql package is an experimental and unsupported work in progress. | ||
|
||
## Usage | ||
|
||
Run `bazel run //swift:install-extractor`, which will install `swift/extractor_pack`. Using `--search-path=swift` will | ||
then pick up the Swift extractor. |
This file contains 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 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 @@ | ||
cc_binary( | ||
name = "extractor", | ||
srcs = ["main.cpp"], | ||
visibility = ["//swift:__pkg__"], | ||
) |
This file contains 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 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 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 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 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 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 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-tests | ||
version: 0.0.0 | ||
libraryPathDependencies: | ||
- codeql/swift-all | ||
extractor: swift |
This file contains 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" |