Merge pull request #8939 from AlexDenisov/alexdenisov/swift-tracer-integration

Swift: tracer integration
This commit is contained in:
AlexDenisov
2022-04-28 19:20:55 +02:00
committed by GitHub
6 changed files with 60 additions and 2 deletions

View File

@@ -1,4 +1,3 @@
# -fno-rtti is required by LLVM/Swift
build --repo_env=CC=clang --repo_env=CXX=clang++ --copt="-std=c++17" --copt="-fno-rtti"
build --repo_env=CC=clang --repo_env=CXX=clang++ --copt="-std=c++17"
try-import %workspace%/local.bazelrc

View File

@@ -23,6 +23,12 @@ pkg_files(
prefix = "tools",
)
pkg_files(
name = "tracing-config",
srcs = ["tools/tracing-config.lua"],
prefix = "tools",
)
pkg_files(
name = "manifest",
srcs = ["codeql-extractor.yml"],
@@ -34,6 +40,7 @@ pkg_filegroup(
":dbscheme_files",
":manifest",
":qltest",
":tracing-config",
],
visibility = ["//visibility:public"],
)

View File

@@ -14,6 +14,10 @@ cc_binary(
"SwiftExtractorConfiguration.h",
"main.cpp",
],
copts = [
# Required by LLVM/Swift
"-fno-rtti",
],
features = ["-universal_binaries"],
target_compatible_with = select({
"@platforms//os:linux": [],

View File

@@ -54,6 +54,13 @@ static void extractFile(const SwiftExtractorConfiguration& config, swift::Source
llvm::SmallString<PATH_MAX> tempTrapPath(config.trapDir);
llvm::sys::path::append(tempTrapPath, tempTrapName);
llvm::StringRef trapParent = llvm::sys::path::parent_path(tempTrapPath);
if (std::error_code ec = llvm::sys::fs::create_directories(trapParent)) {
std::cerr << "Cannot create trap directory '" << trapParent.str() << "': " << ec.message()
<< "\n";
return;
}
std::ofstream trap(tempTrapPath.str().str());
if (!trap) {
std::error_code ec;

View File

@@ -16,6 +16,14 @@ class Observer : public swift::FrontendObserver {
public:
explicit Observer(const codeql::SwiftExtractorConfiguration& config) : config{config} {}
void parsedArgs(swift::CompilerInvocation& invocation) override {
// Original compiler and the extractor-compiler get into conflicts when
// both produce the same output files.
// TODO: change the final artifact destinations instead of disabling
// the artifact generation completely?
invocation.getFrontendOptions().RequestedAction = swift::FrontendOptions::ActionType::Typecheck;
}
void performedSemanticAnalysis(swift::CompilerInstance& compiler) override {
codeql::extractSwiftFiles(config, compiler);
}

View File

@@ -0,0 +1,33 @@
function RegisterExtractorPack(id)
local extractorDirectory = GetPlatformToolsDirectory()
local relativeSwiftExtractor = extractorDirectory .. 'extractor'
local swiftExtractor = AbsolutifyExtractorPath(id, relativeSwiftExtractor)
function SwiftMatcher(compilerName, compilerPath, compilerArguments, lang)
-- Only match binaries names `swift-frontend`
if compilerName ~= 'swift-frontend' then return nil end
-- Skip the invocation in case it's not called in `-frontend` mode
if compilerArguments.argv[1] ~= '-frontend' then return nil end
-- Drop the `-frontend` argument
table.remove(compilerArguments.argv, 1)
-- Skip "info" queries in case there is nothing to extract
if compilerArguments.argv[1] == '-print-target-info' then return nil end
if compilerArguments.argv[1] == '-emit-supported-features' then return nil end
-- Skip actions in which we cannot extract anything
if compilerArguments.argv[1] == '-merge-modules' then return nil end
return {
trace = true,
replace = false,
invocations = {{path = swiftExtractor, arguments = compilerArguments}}
}
end
return { SwiftMatcher }
end
-- Return a list of minimum supported versions of the configuration file format
-- return one entry per supported major version.
function GetCompatibleVersions() return {'1.0.0'} end