Skip to content

Commit 721145b

Browse files
committed
Move EMIT_COMPILER_SOURCE_METADATA to a builtin macro
1 parent ff839fb commit 721145b

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed

Sources/SWBCore/Settings/BuiltinMacros.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ public final class BuiltinMacros {
639639
public static let EMBEDDED_CONTENT_CONTAINS_SWIFT = BuiltinMacros.declareBooleanMacro("EMBEDDED_CONTENT_CONTAINS_SWIFT")
640640
public static let EMBEDDED_PROFILE_NAME = BuiltinMacros.declareStringMacro("EMBEDDED_PROFILE_NAME")
641641
public static let EMBED_PACKAGE_RESOURCE_BUNDLE_NAMES = BuiltinMacros.declareStringListMacro("EMBED_PACKAGE_RESOURCE_BUNDLE_NAMES")
642+
public static let EMIT_COMPILER_SOURCE_METADATA = BuiltinMacros.declareBooleanMacro("EMIT_COMPILER_SOURCE_METADATA")
642643
public static let EMIT_FRONTEND_COMMAND_LINES = BuiltinMacros.declareBooleanMacro("EMIT_FRONTEND_COMMAND_LINES")
643644
public static let ENABLE_APPINTENTS_DEPLOYMENT_AWARE_PROCESSING = BuiltinMacros.declareBooleanMacro("ENABLE_APPINTENTS_DEPLOYMENT_AWARE_PROCESSING")
644645
public static let ENABLE_ADDITIONAL_CODESIGN_INPUT_TRACKING = BuiltinMacros.declareBooleanMacro("ENABLE_ADDITIONAL_CODESIGN_INPUT_TRACKING")
@@ -1717,6 +1718,7 @@ public final class BuiltinMacros {
17171718
EMBEDDED_CONTENT_CONTAINS_SWIFT,
17181719
EMBEDDED_PROFILE_NAME,
17191720
EMBED_PACKAGE_RESOURCE_BUNDLE_NAMES,
1721+
EMIT_COMPILER_SOURCE_METADATA,
17201722
EMIT_FRONTEND_COMMAND_LINES,
17211723
ENABLE_APPINTENTS_DEPLOYMENT_AWARE_PROCESSING,
17221724
ENABLE_ADDRESS_SANITIZER,

Sources/SWBCore/SpecImplementations/Tools/CCompiler.swift

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,7 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
836836
"-fmessage-length=",
837837
"-fmacro-backtrace-limit=",
838838
"-fbuild-session-timestamp=",
839+
"-fdiagnostics-add-output="
839840
])
840841

841842
static let outputAgnosticCompilerArgumentsWithValues = Set<ByteString>([
@@ -1220,7 +1221,7 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
12201221
dependencyData = nil
12211222
}
12221223

1223-
let extraOutputs: [any PlannedNode]
1224+
var extraOutputs: [any PlannedNode]
12241225
let moduleDependenciesContext = cbc.producer.moduleDependenciesContext
12251226
let headerDependenciesContext = cbc.producer.headerDependenciesContext
12261227
let dependencyValidationOutputPath: Path?
@@ -1337,6 +1338,8 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
13371338
}
13381339
}
13391340

1341+
commandLine += addCompilerMetadataFlags(cbc, outputFileDir.join(outputNode.path.str + ".source-metadata.json"), delegate, &extraOutputs)
1342+
13401343
// Handle explicit modules build.
13411344
let scanningOutput = delegate.createNode(outputNode.path.dirname.join(outputNode.path.basename + ".scan"))
13421345
let (action, usesExecutionInputs, explicitModulesPayload, explicitModulesSignatureData) = createExplicitModulesActionAndPayload(cbc, delegate, launcher, input, resolvedInputFileType.languageDialect, commandLine: commandLine, scanningOutputPath: scanningOutput.path, isForPCHTask: false, clangInfo: clangInfo)
@@ -1649,6 +1652,22 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
16491652
}
16501653
}
16511654

1655+
func addCompilerMetadataFlags(_ cbc: CommandBuildContext, _ outputPath: Path, _ delegate: any TaskGenerationDelegate, _ taskOutputs: inout [any PlannedNode]) -> [String] {
1656+
guard cbc.scope.evaluate(BuiltinMacros.EMIT_COMPILER_SOURCE_METADATA) else {
1657+
return []
1658+
}
1659+
1660+
guard let metadatatype = cbc.producer.lookupFileType(identifier: "text.json.compiler-metadata.source") else {
1661+
return []
1662+
}
1663+
1664+
let securityMetadataNode = delegate.createNode(outputPath)
1665+
let ftb = FileToBuild(absolutePath: securityMetadataNode.path, fileType: metadatatype)
1666+
taskOutputs.append(securityMetadataNode)
1667+
delegate.declareOutput(ftb)
1668+
return ["-fdiagnostics-add-output=sarif:file=" + securityMetadataNode.path.str]
1669+
}
1670+
16521671
/// Specialized function that creates a task for precompiling a particular header.
16531672
private func precompile(_ cbc: CommandBuildContext, _ delegate: any TaskGenerationDelegate, headerPath: Path, language: GCCCompatibleLanguageDialect, inputFileType: FileTypeSpec, extraArgs: [String], precompPath: Path, clangInfo: DiscoveredClangToolSpecInfo?) -> ClangPrefixInfo.PCHInfo {
16541673

Sources/SWBUniversalPlatform/Specs/Clang.xcspec

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -109,24 +109,6 @@
109109
NO = ();
110110
};
111111
},
112-
{
113-
Name = "EMIT_COMPILER_SOURCE_METADATA";
114-
Type = Boolean;
115-
DefaultValue = No;
116-
},
117-
{
118-
Name = "__CLANG_SOURCE_METADATA_PATH";
119-
Type = Path;
120-
Condition = "$(EMIT_COMPILER_SOURCE_METADATA)";
121-
DefaultValue = "$(OutputPath).source-metadata.json";
122-
CommandLinePrefixFlag = "-fdiagnostics-add-output=sarif:file=";
123-
OutputDependencies = (
124-
{
125-
Path = "$(__CLANG_SOURCE_METADATA_PATH)";
126-
FileType = "text.json.compiler-metadata.source";
127-
},
128-
);
129-
},
130112
{
131113
Name = "CLANG_MACRO_BACKTRACE_LIMIT";
132114
Type = String;

Tests/SWBTaskConstructionTests/TaskConstructionTests.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9543,8 +9543,7 @@ fileprivate struct TaskConstructionTests: CoreBasedTests {
95439543
"GENERATE_INFOPLIST_FILE": "YES",
95449544
"PRODUCT_NAME": "$(TARGET_NAME)",
95459545
"ARCHS": "x86_64 arm64",
9546-
"EMIT_COMPILER_SOURCE_METADATA": "YES",
9547-
"COMPILER_SOURCE_METADATA_LIST": "/tmp/test.json"
9546+
"EMIT_COMPILER_SOURCE_METADATA": "YES"
95489547
])
95499548
],
95509549
buildPhases: [

0 commit comments

Comments
 (0)