Skip to content
Open
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
4 changes: 4 additions & 0 deletions Sources/SWBCore/Settings/BuiltinMacros.swift
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ public final class BuiltinMacros {
public static let CLANG_CACHE_FINE_GRAINED_OUTPUTS_VERIFICATION = BuiltinMacros.declareEnumMacro("CLANG_CACHE_FINE_GRAINED_OUTPUTS_VERIFICATION") as EnumMacroDeclaration<FineGrainedCachingVerificationSetting>
public static let CLANG_DISABLE_DEPENDENCY_INFO_FILE = BuiltinMacros.declareBooleanMacro("CLANG_DISABLE_DEPENDENCY_INFO_FILE")
public static let CLANG_ENABLE_PREFIX_MAPPING = BuiltinMacros.declareBooleanMacro("CLANG_ENABLE_PREFIX_MAPPING")
public static let CLANG_ENABLE_COMPLETE_PREFIX_MAPPING = BuiltinMacros.declareBooleanMacro("CLANG_ENABLE_COMPLETE_PREFIX_MAPPING")
public static let CLANG_OTHER_PREFIX_MAPPINGS = BuiltinMacros.declareStringListMacro("CLANG_OTHER_PREFIX_MAPPINGS")
public static let CLANG_GENERATE_OPTIMIZATION_REMARKS = BuiltinMacros.declareBooleanMacro("CLANG_GENERATE_OPTIMIZATION_REMARKS")
public static let CLANG_GENERATE_OPTIMIZATION_REMARKS_FILTER = BuiltinMacros.declareStringMacro("CLANG_GENERATE_OPTIMIZATION_REMARKS_FILTER")
Expand Down Expand Up @@ -1120,6 +1121,7 @@ public final class BuiltinMacros {
public static let SWIFT_WHOLE_MODULE_OPTIMIZATION = BuiltinMacros.declareBooleanMacro("SWIFT_WHOLE_MODULE_OPTIMIZATION")
public static let SWIFT_ENABLE_COMPILE_CACHE = BuiltinMacros.declareBooleanMacro("SWIFT_ENABLE_COMPILE_CACHE")
public static let SWIFT_ENABLE_PREFIX_MAPPING = BuiltinMacros.declareBooleanMacro("SWIFT_ENABLE_PREFIX_MAPPING")
public static let SWIFT_ENABLE_COMPLETE_PREFIX_MAPPING = BuiltinMacros.declareBooleanMacro("SWIFT_ENABLE_COMPLETE_PREFIX_MAPPING")
public static let SWIFT_OTHER_PREFIX_MAPPINGS = BuiltinMacros.declareStringListMacro("SWIFT_OTHER_PREFIX_MAPPINGS")
public static let SYMBOL_GRAPH_EXTRACTOR_OUTPUT_DIR = BuiltinMacros.declareStringMacro("SYMBOL_GRAPH_EXTRACTOR_OUTPUT_DIR")
public static let SYMBOL_GRAPH_EXTRACTOR_MODULE_NAME = BuiltinMacros.declareStringMacro("SYMBOL_GRAPH_EXTRACTOR_MODULE_NAME")
Expand Down Expand Up @@ -1537,6 +1539,7 @@ public final class BuiltinMacros {
CLANG_CACHE_FINE_GRAINED_OUTPUTS_VERIFICATION,
CLANG_DISABLE_DEPENDENCY_INFO_FILE,
CLANG_ENABLE_PREFIX_MAPPING,
CLANG_ENABLE_COMPLETE_PREFIX_MAPPING,
CLANG_OTHER_PREFIX_MAPPINGS,
CLANG_DISABLE_SERIALIZED_DIAGNOSTICS,
CLANG_ENABLE_MODULES,
Expand Down Expand Up @@ -2370,6 +2373,7 @@ public final class BuiltinMacros {
SWIFT_WHOLE_MODULE_OPTIMIZATION,
SWIFT_ENABLE_COMPILE_CACHE,
SWIFT_ENABLE_PREFIX_MAPPING,
SWIFT_ENABLE_COMPLETE_PREFIX_MAPPING,
SWIFT_OTHER_PREFIX_MAPPINGS,
SYMBOL_GRAPH_EXTRACTOR_MODULE_NAME,
SYMBOL_GRAPH_EXTRACTOR_OUTPUT_DIR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,25 @@ final class CompilationCachingConfigFileTaskProducer: StandardTaskProducer, Task
encoder.outputFormatting = [.sortedKeys, .withoutEscapingSlashes]
let casConfigContent = try encoder.encode(CASConfig(CASPath: casOpts.casPath.str, PluginPath: casOpts.pluginPath?.str))

let prefixMapConfigContent: ByteString?
if !scope.evaluate(BuiltinMacros.CLANG_ENABLE_PREFIX_MAPPING) && !scope.evaluate(BuiltinMacros.SWIFT_ENABLE_PREFIX_MAPPING) && scope.evaluate(BuiltinMacros.CLANG_OTHER_PREFIX_MAPPINGS).isEmpty && scope.evaluate(BuiltinMacros.SWIFT_OTHER_PREFIX_MAPPINGS).isEmpty {
prefixMapConfigContent = nil
} else {
var prefixXcode = false
var prefixComplete = false
var extraMaps: [String: String] = [:]

func checkSettings(
enableCache: BooleanMacroDeclaration,
enablePrefix: BooleanMacroDeclaration,
enableCompletePrefix: BooleanMacroDeclaration,
otherMappings: StringListMacroDeclaration,
) {
guard scope.evaluate(enableCache) && scope.evaluate(enablePrefix) else {
return
}

prefixXcode = true
if scope.evaluate(enableCompletePrefix) {
prefixComplete = true
}

func rsplit(_ string: String, separator: Character) -> (String, String)? {
guard let splitIndex = string.lastIndex(of: separator) else {
return nil
Expand All @@ -76,27 +91,40 @@ final class CompilationCachingConfigFileTaskProducer: StandardTaskProducer, Task
let value = String(string[string.index(after: splitIndex)...])
return (key, value)
}
extraMaps.merge(
scope.evaluate(otherMappings).compactMap { entry in
rsplit(entry, separator: "=").map { (value, key) in (key, value) }
}, uniquingKeysWith: { _, new in new })
}
checkSettings(
enableCache: BuiltinMacros.CLANG_ENABLE_COMPILE_CACHE,
enablePrefix: BuiltinMacros.CLANG_ENABLE_PREFIX_MAPPING,
enableCompletePrefix: BuiltinMacros.CLANG_ENABLE_COMPLETE_PREFIX_MAPPING,
otherMappings: BuiltinMacros.CLANG_OTHER_PREFIX_MAPPINGS
)
checkSettings(
enableCache: BuiltinMacros.SWIFT_ENABLE_COMPILE_CACHE,
enablePrefix: BuiltinMacros.SWIFT_ENABLE_PREFIX_MAPPING,
enableCompletePrefix: BuiltinMacros.SWIFT_ENABLE_COMPLETE_PREFIX_MAPPING,
otherMappings: BuiltinMacros.SWIFT_OTHER_PREFIX_MAPPINGS
)

var prefixMaps: [String: String] = [:]
if scope.evaluate(BuiltinMacros.CLANG_ENABLE_PREFIX_MAPPING) || !scope.evaluate(BuiltinMacros.SWIFT_ENABLE_PREFIX_MAPPING) {
prefixMaps["/^sdk"] = scope.evaluate(BuiltinMacros.SDKROOT).str
prefixMaps["/^xcode"] = scope.evaluate(BuiltinMacros.DEVELOPER_DIR).str
prefixMaps["/^src"] = scope.evaluate(BuiltinMacros.PROJECT_DIR).str
prefixMaps["/^derived"] = scope.evaluate(BuiltinMacros.PROJECT_TEMP_DIR).str
prefixMaps["/^built"] = scope.evaluate(BuiltinMacros.BUILT_PRODUCTS_DIR).str
}
if scope.evaluate(BuiltinMacros.CLANG_ENABLE_COMPILE_CACHE) {
prefixMaps.merge(
scope.evaluate(BuiltinMacros.CLANG_OTHER_PREFIX_MAPPINGS).compactMap { entry in
rsplit(entry, separator: "=").map { (value, key) in (key, value) }
}, uniquingKeysWith: { _, new in new })
}
if scope.evaluate(BuiltinMacros.SWIFT_ENABLE_COMPILE_CACHE) {
prefixMaps.merge(
scope.evaluate(BuiltinMacros.SWIFT_OTHER_PREFIX_MAPPINGS).compactMap { entry in
rsplit(entry, separator: "=").map { (value, key) in (key, value) }
}, uniquingKeysWith: { _, new in new })
}
var prefixMaps: [String: String] = [:]
if prefixXcode {
prefixMaps["/^sdk"] = scope.evaluate(BuiltinMacros.SDKROOT).str
prefixMaps["/^xcode"] = scope.evaluate(BuiltinMacros.DEVELOPER_DIR).str
}
if prefixComplete {
prefixMaps["/^src"] = scope.evaluate(BuiltinMacros.PROJECT_DIR).str
prefixMaps["/^derived"] = scope.evaluate(BuiltinMacros.PROJECT_TEMP_DIR).str
prefixMaps["/^built"] = scope.evaluate(BuiltinMacros.BUILT_PRODUCTS_DIR).str
}
prefixMaps.merge(extraMaps, uniquingKeysWith: { _, new in new })

let prefixMapConfigContent: ByteString?
if prefixMaps.isEmpty {
prefixMapConfigContent = nil
} else {
prefixMapConfigContent = try ByteString(encoder.encode(prefixMaps))
}
return CompilationCachingConfigs(OutputDir: path, CASConfigContent: ByteString(casConfigContent), PrefixMapConfigContent: prefixMapConfigContent)
Expand Down
15 changes: 14 additions & 1 deletion Sources/SWBUniversalPlatform/Specs/Clang.xcspec
Original file line number Diff line number Diff line change
Expand Up @@ -3316,13 +3316,26 @@
"-fdepscan-prefix-map-sdk=/^sdk",
"-fdepscan-prefix-map-toolchain=/^toolchain",
"-fdepscan-prefix-map=$(DEVELOPER_DIR)=/^xcode",
);
NO = ();
};
Condition = "$(CLANG_ENABLE_COMPILE_CACHE)";
FeatureFlags = "depscan-prefix-map";
// Category is hidden.
},
{
Name = "CLANG_ENABLE_COMPLETE_PREFIX_MAPPING";
Type = Boolean;
// `DefaultValue` is not set to allow configuring the setting via an environment variable.
CommandLineArgs = {
YES = (
"-fdepscan-prefix-map=$(PROJECT_DIR)=/^src",
"-fdepscan-prefix-map=$(PROJECT_TEMP_DIR)=/^derived",
"-fdepscan-prefix-map=$(BUILT_PRODUCTS_DIR)=/^built",
);
NO = ();
};
Condition = "$(CLANG_ENABLE_COMPILE_CACHE)";
Condition = "$(CLANG_ENABLE_COMPILE_CACHE) && $(CLANG_ENABLE_PREFIX_MAPPING)";
FeatureFlags = "depscan-prefix-map";
// Category is hidden.
},
Expand Down
13 changes: 12 additions & 1 deletion Sources/SWBUniversalPlatform/Specs/Swift.xcspec
Original file line number Diff line number Diff line change
Expand Up @@ -1441,13 +1441,24 @@
"-scanner-prefix-map-sdk", "/^sdk",
"-scanner-prefix-map-toolchain", "/^toolchain",
"-scanner-prefix-map", "$(DEVELOPER_DIR)=/^xcode",
);
NO = ();
};
Condition = "$(SWIFT_ENABLE_COMPILE_CACHE)";
},
{
Name = "SWIFT_ENABLE_COMPLETE_PREFIX_MAPPING";
Type = Boolean;
// `DefaultValue` is not set to allow configuring the setting via an environment variable.
CommandLineArgs = {
YES = (
"-scanner-prefix-map", "$(PROJECT_DIR)=/^src",
"-scanner-prefix-map", "$(PROJECT_TEMP_DIR)=/^derived",
"-scanner-prefix-map", "$(BUILT_PRODUCTS_DIR)=/^built",
);
NO = ();
};
Condition = "$(SWIFT_ENABLE_COMPILE_CACHE)";
Condition = "$(SWIFT_ENABLE_COMPILE_CACHE) && $(SWIFT_ENABLE_PREFIX_MAPPING)";
},
{
Name = "SWIFT_OTHER_PREFIX_MAPPINGS";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,7 @@ fileprivate struct ClangCompilationCachingTests: CoreBasedTests {
"_EXPERIMENTAL_CLANG_EXPLICIT_MODULES": "YES",
"HEADER_SEARCH_PATHS": "\(moduleDir.str) $DERIVED_FILE_DIR",
"CLANG_ENABLE_PREFIX_MAPPING": "YES",
"CLANG_ENABLE_COMPLETE_PREFIX_MAPPING": "YES",
"CLANG_OTHER_PREFIX_MAPPINGS": "\(moduleDir.str)=/^mod",
"DSTROOT": tmpDirPath.join("dstroot").str,
"EMIT_FRONTEND_COMMAND_LINES": "YES",
Expand Down
Loading
Loading