Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build --copt="-std=c++17"

try-import %workspace%/local.bazelrc
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.0.0
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@ csharp/extractor/Semmle.Extraction.CSharp.Driver/Properties/launchSettings.json
# Compiled class file
*.class

# links create by bazel
# links created by bazel
/bazel-*

# CLion project files
/.clwb
Empty file added BUILD.bazel
Empty file.
10 changes: 10 additions & 0 deletions WORKSPACE.bazel
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()
5 changes: 5 additions & 0 deletions defs.bzl
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 added misc/bazel/BUILD.bazel
Empty file.
23 changes: 23 additions & 0 deletions misc/bazel/workspace.bzl
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",
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",
],
)
4 changes: 4 additions & 0 deletions misc/bazel/workspace_deps.bzl
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()
7 changes: 7 additions & 0 deletions swift/.clang-format
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
7 changes: 7 additions & 0 deletions swift/.codeqlmanifest.json
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"
]
}
1 change: 1 addition & 0 deletions swift/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extractor-pack
67 changes: 67 additions & 0 deletions swift/BUILD.bazel
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(
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"],
)
9 changes: 9 additions & 0 deletions swift/README.md
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.

## 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`.
10 changes: 10 additions & 0 deletions swift/codeql-extractor.yml
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
10 changes: 10 additions & 0 deletions swift/extractor/BUILD.bazel
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({
"@platforms//os:linux": [],
"@platforms//os:macos": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
visibility = ["//swift:__pkg__"],
)
14 changes: 14 additions & 0 deletions swift/extractor/main.cpp
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;
}
5 changes: 5 additions & 0 deletions swift/ql/lib/qlpack.yml
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
7 changes: 7 additions & 0 deletions swift/ql/lib/swift.dbscheme
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
)
4 changes: 4 additions & 0 deletions swift/ql/lib/swift.dbscheme.stats
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<dbstats>
<typesizes />
<stats />
</dbstats>
1 change: 1 addition & 0 deletions swift/ql/test/answer.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
| 42 |
3 changes: 3 additions & 0 deletions swift/ql/test/answer.ql
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
6 changes: 6 additions & 0 deletions swift/ql/test/qlpack.yml
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
16 changes: 16 additions & 0 deletions swift/tools/create_extractor_pack.py
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)
5 changes: 5 additions & 0 deletions swift/tools/qltest.sh
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"