mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
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.
This commit is contained in:
3
.bazelrc
Normal file
3
.bazelrc
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
build --copt="-std=c++17"
|
||||||
|
|
||||||
|
try-import %workspace%/local.bazelrc
|
||||||
0
BUILD.bazel
Normal file
0
BUILD.bazel
Normal file
@@ -1,2 +1,45 @@
|
|||||||
# Please notice that any bazel targets and definitions in this repository are currently experimental
|
# Please notice that any bazel targets and definitions in this repository are currently experimental
|
||||||
# and for internal use only.
|
# 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")
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ load("@rules_pkg//:mappings.bzl", "pkg_filegroup")
|
|||||||
|
|
||||||
alias(
|
alias(
|
||||||
name = "dbscheme",
|
name = "dbscheme",
|
||||||
actual = "//cpp/ql/lib:dbscheme",
|
actual = "@ql//cpp/ql/lib:dbscheme",
|
||||||
)
|
)
|
||||||
|
|
||||||
pkg_filegroup(
|
pkg_filegroup(
|
||||||
name = "db-files",
|
name = "db-files",
|
||||||
srcs = [
|
srcs = [
|
||||||
":dbscheme",
|
":dbscheme",
|
||||||
"//cpp/downgrades",
|
"@ql//cpp/downgrades",
|
||||||
"//cpp/ql/lib:dbscheme-stats",
|
"@ql//cpp/ql/lib:dbscheme-stats",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|||||||
19
defs.bzl
Normal file
19
defs.bzl
Normal file
@@ -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,
|
||||||
|
)
|
||||||
7
swift/.clang-format
Normal file
7
swift/.clang-format
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
BasedOnStyle: Chromium
|
||||||
|
ColumnLimit: 100
|
||||||
|
IndentWidth: 2
|
||||||
|
SortIncludes: false
|
||||||
|
AllowShortIfStatementsOnASingleLine: WithoutElse
|
||||||
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
|
Standard: c++17
|
||||||
7
swift/.codeqlmanifest.json
Normal file
7
swift/.codeqlmanifest.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"provide": [
|
||||||
|
"ql/lib/qlpack.yml",
|
||||||
|
"ql/test/qlpack.yml",
|
||||||
|
"extractor_pack/codeql-extractor.yml"
|
||||||
|
]
|
||||||
|
}
|
||||||
1
swift/.gitignore
vendored
Normal file
1
swift/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
extractor_pack
|
||||||
66
swift/BUILD.bazel
Normal file
66
swift/BUILD.bazel
Normal file
@@ -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",
|
||||||
|
],
|
||||||
|
)
|
||||||
8
swift/README.md
Normal file
8
swift/README.md
Normal file
@@ -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.
|
||||||
10
swift/codeql-extractor.yml
Normal file
10
swift/codeql-extractor.yml
Normal file
@@ -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
|
||||||
5
swift/extractor/BUILD.bazel
Normal file
5
swift/extractor/BUILD.bazel
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
cc_binary(
|
||||||
|
name = "extractor",
|
||||||
|
srcs = ["main.cpp"],
|
||||||
|
visibility = ["//swift:__pkg__"],
|
||||||
|
)
|
||||||
14
swift/extractor/main.cpp
Normal file
14
swift/extractor/main.cpp
Normal file
@@ -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;
|
||||||
|
}
|
||||||
5
swift/ql/lib/qlpack.yml
Normal file
5
swift/ql/lib/qlpack.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
name: codeql/swift-all
|
||||||
|
version: 0.0.0
|
||||||
|
dbscheme: swift.dbscheme
|
||||||
|
extractor: swift
|
||||||
|
library: true
|
||||||
7
swift/ql/lib/swift.dbscheme
Normal file
7
swift/ql/lib/swift.dbscheme
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
sourceLocationPrefix(
|
||||||
|
string prefix: string ref
|
||||||
|
);
|
||||||
|
|
||||||
|
answer_to_life_the_universe_and_everything(
|
||||||
|
int answer: int ref
|
||||||
|
)
|
||||||
4
swift/ql/lib/swift.dbscheme.stats
Normal file
4
swift/ql/lib/swift.dbscheme.stats
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<dbstats>
|
||||||
|
<typesizes />
|
||||||
|
<stats />
|
||||||
|
</dbstats>
|
||||||
1
swift/ql/test/answer.expected
Normal file
1
swift/ql/test/answer.expected
Normal file
@@ -0,0 +1 @@
|
|||||||
|
| 42 |
|
||||||
3
swift/ql/test/answer.ql
Normal file
3
swift/ql/test/answer.ql
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from int answer
|
||||||
|
where answer_to_life_the_universe_and_everything(answer)
|
||||||
|
select answer
|
||||||
5
swift/ql/test/qlpack.yml
Normal file
5
swift/ql/test/qlpack.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
name: codeql-swift-tests
|
||||||
|
version: 0.0.0
|
||||||
|
libraryPathDependencies:
|
||||||
|
- codeql/swift-all
|
||||||
|
extractor: swift
|
||||||
5
swift/tools/qltest.sh
Executable file
5
swift/tools/qltest.sh
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
mkdir -p "$CODEQL_EXTRACTOR_SWIFT_TRAP_DIR"
|
||||||
|
|
||||||
|
exec "$CODEQL_EXTRACTOR_SWIFT_ROOT/tools/$CODEQL_PLATFORM/extractor"
|
||||||
Reference in New Issue
Block a user