Improve debugging support for (Obj)C(++)
Note: This requires Bazel 0.17.1 or later since it relies on the debug_prefix_map_pwd_is_dot
CROSSTOOL feature from https://github.com/bazelbuild/bazel/commit/3f46dd0f6d5a042fc28d265411a6014f666a40c1
which was first released in Bazel 0.17.1.
This fixes #54 by remapping debug information (e.g. OSO stabs) to be relative to the PWD of each action,
effectively making the debug information relative to the workspace root / bazel execution root. With this
fix, users can re-enable sandboxing for Obj-C actions (remove --strategy= ObjcCompile=standalone) and still
be able to debug Objective-C sources.
Later on, Tulsi remaps `./` -> `<workspace root>` for Xcode's lldb as Xcode does not support invoking
lldb from a specific directory (it launches lldb from `/`, the root directory).
PiperOrigin-RevId: 216716521
diff --git a/src/Tulsi/TulsiGeneratorConfigDocument.swift b/src/Tulsi/TulsiGeneratorConfigDocument.swift
index fced6dc..4b70a4b 100644
--- a/src/Tulsi/TulsiGeneratorConfigDocument.swift
+++ b/src/Tulsi/TulsiGeneratorConfigDocument.swift
@@ -442,11 +442,7 @@
}
private func enabledFeatures(options: TulsiOptionSet) -> Set<BazelSettingFeature> {
- let workspaceRoot = infoExtractor.workspaceRootURL.path
- let bazelExecroot = infoExtractor.bazelExecutionRoot
- return BazelBuildSettingsFeatures.enabledFeatures(options: options,
- workspaceRoot: workspaceRoot,
- bazelExecRoot: bazelExecroot)
+ return BazelBuildSettingsFeatures.enabledFeatures(options: options)
}
// Regenerates the sourcePaths array based on the currently selected ruleEntries.
diff --git a/src/TulsiGenerator/BazelBuildSettingsFeatures.swift b/src/TulsiGenerator/BazelBuildSettingsFeatures.swift
index 2ae07ba..53385bb 100644
--- a/src/TulsiGenerator/BazelBuildSettingsFeatures.swift
+++ b/src/TulsiGenerator/BazelBuildSettingsFeatures.swift
@@ -45,11 +45,15 @@
}
public class BazelBuildSettingsFeatures {
- public static func enabledFeatures(
- options: TulsiOptionSet,
- workspaceRoot: String,
- bazelExecRoot: String
- ) -> Set<BazelSettingFeature> {
- return [.DirectDebugPrefixMap(bazelExecRoot, workspaceRoot)]
+ public static func enabledFeatures(options: TulsiOptionSet) -> Set<BazelSettingFeature> {
+ // A normalized path for -fdebug-prefix-map exists for keeping all debug information as built by
+ // Clang consistent for the sake of caching within a distributed build system.
+ //
+ // This is handled through a wrapped_clang feature flag via the CROSSTOOL.
+ //
+ // The use of this flag does not affect any sources built by swiftc. At present time, all Swift
+ // compiled sources will be built with uncacheable, absolute paths, as the Swift compiler does
+ // not present an easy means of similarly normalizing all debug information.
+ return [.DebugPathNormalization]
}
}
diff --git a/src/TulsiGenerator/BazelSettingsProvider.swift b/src/TulsiGenerator/BazelSettingsProvider.swift
index ede387b..ecd78bc 100644
--- a/src/TulsiGenerator/BazelSettingsProvider.swift
+++ b/src/TulsiGenerator/BazelSettingsProvider.swift
@@ -24,33 +24,18 @@
/// Feature flag to normalize paths present in debug information via a Clang flag for distributed
/// builds (e.g. multiple distinct paths).
- /// - Mutually exclusive with DirectDebugPrefixMap feature
///
/// The use of this flag does not affect any sources built by swiftc. At present time, all Swift
/// compiled sources will be built with uncacheable, absolute paths, as the Swift compiler does
/// not provide an easy means of similarly normalizing all debug information.
case DebugPathNormalization
- /// Feature flag to normalize paths present in debug information via a Clang flag for local
- /// builds.
- /// - Mutually exclusive with DebugPathNormalization feature
- ///
- /// NOTE: Use of -fdebug-prefix-map leads to producing binaries that cannot be
- /// reused across multiple machines by a distributed build system, unless the
- /// absolute paths to files visible to Xcode match perfectly between all of
- /// those machines.
- ///
- /// For this reason, -fdebug-prefix-map is provided as a default for non-distributed purposes.
- case DirectDebugPrefixMap(String, String)
-
/// TODO(b/111928007): Remove this and/or BazelSettingFeature once DebugPathNormalization is
/// supported by all builds.
public var stringValue: String {
switch self {
case .DebugPathNormalization:
return "DebugPathNormalization"
- case .DirectDebugPrefixMap:
- return "DirectDebugPrefixMap"
}
}
@@ -68,8 +53,6 @@
/// Technically this doesn't support swiftc, but we now support this feature for
/// Cxx compilation alongside swift compilation.
return true
- case .DirectDebugPrefixMap:
- return true
}
}
@@ -77,8 +60,6 @@
switch self {
case .DebugPathNormalization:
return true
- case .DirectDebugPrefixMap:
- return true
}
}
@@ -91,9 +72,6 @@
public var buildFlags: [String] {
switch self {
case .DebugPathNormalization: return ["--features=debug_prefix_map_pwd_is_dot"]
- case .DirectDebugPrefixMap(let execRoot, let workspaceRoot): return [
- String(format: "--copt=-fdebug-prefix-map=%@=%@", execRoot, workspaceRoot)
- ]
}
}
diff --git a/src/TulsiGenerator/XcodeProjectGenerator.swift b/src/TulsiGenerator/XcodeProjectGenerator.swift
index 3785341..b12ab82 100644
--- a/src/TulsiGenerator/XcodeProjectGenerator.swift
+++ b/src/TulsiGenerator/XcodeProjectGenerator.swift
@@ -575,9 +575,7 @@
private func loadRuleEntryMap() throws -> RuleEntryMap {
do {
- let features = BazelBuildSettingsFeatures.enabledFeatures(options: config.options,
- workspaceRoot: workspaceRootURL.path,
- bazelExecRoot: workspaceInfoExtractor.bazelExecutionRoot)
+ let features = BazelBuildSettingsFeatures.enabledFeatures(options: config.options)
return try workspaceInfoExtractor.ruleEntriesForLabels(config.buildTargetLabels,
startupOptions: config.options[.BazelBuildStartupOptionsDebug],
buildOptions: config.options[.BazelBuildOptionsDebug],
@@ -974,9 +972,7 @@
let bazelSettingsProvider = workspaceInfoExtractor.bazelSettingsProvider
let bazelExecRoot = workspaceInfoExtractor.bazelExecutionRoot
- let features = BazelBuildSettingsFeatures.enabledFeatures(options: config.options,
- workspaceRoot: workspaceRootURL.path,
- bazelExecRoot: bazelExecRoot)
+ let features = BazelBuildSettingsFeatures.enabledFeatures(options: config.options)
let bazelBuildSettings = bazelSettingsProvider.buildSettings(bazel: config.bazelURL.path,
bazelExecRoot: bazelExecRoot,
options: config.options,
diff --git a/src/TulsiGeneratorIntegrationTests/EndToEndIntegrationTestCase.swift b/src/TulsiGeneratorIntegrationTests/EndToEndIntegrationTestCase.swift
index 1f44653..cbedb7e 100644
--- a/src/TulsiGeneratorIntegrationTests/EndToEndIntegrationTestCase.swift
+++ b/src/TulsiGeneratorIntegrationTests/EndToEndIntegrationTestCase.swift
@@ -116,10 +116,7 @@
options: TulsiOptionSet,
targets: [String]) -> (String, String) {
let provider = BazelSettingsProvider(universalFlags: bazelUniversalFlags)
- let execRoot = workspaceInfoFetcher.getExecutionRoot()
- let features = BazelBuildSettingsFeatures.enabledFeatures(options: options,
- workspaceRoot: workspaceRootURL.path,
- bazelExecRoot: execRoot)
+ let features = BazelBuildSettingsFeatures.enabledFeatures(options: options)
let dbg = provider.tulsiFlags(hasSwift: swift, options: options, features: features).debug
let rel = provider.tulsiFlags(hasSwift: swift, options: options, features: features).release
diff --git a/src/TulsiGeneratorTests/BuildSettingsTests.swift b/src/TulsiGeneratorTests/BuildSettingsTests.swift
index a7c4218..f1d2047 100644
--- a/src/TulsiGeneratorTests/BuildSettingsTests.swift
+++ b/src/TulsiGeneratorTests/BuildSettingsTests.swift
@@ -135,7 +135,7 @@
"//dir/some/customized:target": BazelFlagsSet(buildFlags: ["a", "b"]),
]
let swiftFeatures = [BazelSettingFeature.DebugPathNormalization.stringValue]
- let nonSwiftFeatures = [BazelSettingFeature.DirectDebugPrefixMap("", "").stringValue]
+ let nonSwiftFeatures = [BazelSettingFeature.DebugPathNormalization.stringValue]
let settings = BazelBuildSettings(bazel: bazel,
bazelExecRoot: bazelExecRoot,
defaultPlatformConfigIdentifier: defaultIdentifier,