aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Dave MacLachlan <dmaclach@google.com>2015-11-06 19:45:37 +0000
committerGravatar Florian Weikert <fwe@google.com>2015-11-06 22:53:48 +0000
commit7c1639d2948a49231f0af715330b4056d3d82fdd (patch)
tree34950dfe6a5d66c4d7ee83ed8d0a925f6b3d4a96 /src
parent7cdc5c9dc3f10fc77462d0c3e020ba68df21137e (diff)
Add experimental support for putting full paths into compile actions. This is currently limited to compile actions started by the objc_* rules. Adding this because Xcode needs full paths to files embedded in the debug information if you want to debug while running in the simulator.
RELNOTES:none -- MOS_MIGRATED_REVID=107253500
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java40
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommandLineOptions.java8
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/ObjcConfiguration.java12
3 files changed, 52 insertions, 8 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java
index 17b8f918d2..8c120e7aca 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java
@@ -289,6 +289,26 @@ public final class CompilationSupport {
}
}
+ /**
+ * Adds a source file to a command line, honoring the useAbsolutePathForActions flag.
+ */
+ private CustomCommandLine.Builder addSource(CustomCommandLine.Builder commandLine,
+ ObjcConfiguration objcConfiguration, Artifact sourceFile) {
+ PathFragment sourceExecPathFragment = sourceFile.getExecPath();
+ String sourcePath = sourceExecPathFragment.getPathString();
+ if (!sourceExecPathFragment.isAbsolute() && objcConfiguration.getUseAbsolutePathsForActions()) {
+ sourcePath = objcConfiguration.getXcodeWorkspaceRoot() + "/" + sourcePath;
+ }
+ commandLine.add(sourcePath);
+ return commandLine;
+ }
+
+ private CustomCommandLine.Builder addSource(String argName, CustomCommandLine.Builder commandLine,
+ ObjcConfiguration objcConfiguration, Artifact sourceFile) {
+ commandLine.add(argName);
+ return addSource(commandLine, objcConfiguration, sourceFile);
+ }
+
private void registerCompileAction(
Artifact sourceFile,
Artifact objFile,
@@ -340,11 +360,17 @@ public final class CompilationSupport {
.add(coverageFlags.build())
.add(objcConfiguration.getCopts())
.add(attributes.copts())
- .add(attributes.optionsCopts())
- .addExecPath("-c", sourceFile)
- .addExecPath("-o", objFile)
- .add("-MD")
- .addExecPath("-MF", dotdFile);
+ .add(attributes.optionsCopts());
+ PathFragment sourceExecPathFragment = sourceFile.getExecPath();
+ String sourcePath = sourceExecPathFragment.getPathString();
+ if (!sourceExecPathFragment.isAbsolute() && objcConfiguration.getUseAbsolutePathsForActions()) {
+ sourcePath = objcConfiguration.getXcodeWorkspaceRoot() + "/" + sourcePath;
+ }
+ commandLine
+ .add("-c").add(sourcePath)
+ .addExecPath("-o", objFile)
+ .add("-MD")
+ .addExecPath("-MF", dotdFile);
if (moduleMap.isPresent()) {
// -fmodule-map-file only loads the module in Xcode 7, so we add the module maps's directory
@@ -429,8 +455,8 @@ public final class CompilationSupport {
commandLine
.add("-Onone")
.add("-module-name").add(getModuleName())
- .add("-parse-as-library")
- .addExecPath("-primary-file", sourceFile)
+ .add("-parse-as-library");
+ addSource("-primary-file", commandLine, objcConfiguration, sourceFile)
.addExecPaths(otherSwiftSources)
.addExecPath("-o", objFile)
.addExecPath("-emit-module-path", intermediateArtifacts.swiftModuleFile(sourceFile))
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommandLineOptions.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommandLineOptions.java
index 6db3d16c96..99619bfdfb 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommandLineOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommandLineOptions.java
@@ -207,6 +207,14 @@ public class ObjcCommandLineOptions extends FragmentOptions {
public String iosSigningCertName;
@Option(
+ name = "experimental_use_absolute_paths_for_actions",
+ defaultValue = "false",
+ category = "undocumented",
+ help = "If set, then all actions objc actions will be executed with absolute paths."
+ )
+ public boolean useAbsolutePathsForActions;
+
+ @Option(
name = "xcode_override_workspace_root",
defaultValue = "",
category = "xcode",
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcConfiguration.java
index c5fe6c614a..57e901008f 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcConfiguration.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcConfiguration.java
@@ -81,6 +81,7 @@ public class ObjcConfiguration extends BuildConfiguration.Fragment {
@Nullable private final String signingCertName;
@Nullable private final Path clientWorkspaceRoot;
private final String xcodeOverrideWorkspaceRoot;
+ private final boolean useAbsolutePathsForActions;
// We only load these labels if the mode which uses them is enabled. That is known as part of the
// BuildConfiguration. This label needs to be part of a configuration because only configurations
@@ -123,6 +124,7 @@ public class ObjcConfiguration extends BuildConfiguration.Fragment {
this.clientWorkspaceRoot = directories != null ? directories.getWorkspace() : null;
this.signingCertName = objcOptions.iosSigningCertName;
this.xcodeOverrideWorkspaceRoot = objcOptions.xcodeOverrideWorkspaceRoot;
+ this.useAbsolutePathsForActions = objcOptions.useAbsolutePathsForActions;
}
public Map<String, String> getEnvironmentForDarwin() {
@@ -138,7 +140,7 @@ public class ObjcConfiguration extends BuildConfiguration.Fragment {
public String getIosSdkVersion() {
return iosSdkVersion;
}
-
+
public Optional<String> getXcodeVersionOverride() {
return xcodeVersionOverride;
}
@@ -333,6 +335,14 @@ public class ObjcConfiguration extends BuildConfiguration.Fragment {
}
/**
+ * If true, all calls to actions are done with absolute paths instead of relative paths.
+ * Using absolute paths allows Xcode to debug and deal with blaze errors in the GUI properly.
+ */
+ public boolean getUseAbsolutePathsForActions() {
+ return this.useAbsolutePathsForActions;
+ }
+
+ /**
* Returns the path to be used for workspace_root (and path of pbxGroup mainGroup) in xcodeproj.
* This usually will be the absolute path of the root of Bazel client workspace or null if
* passed-in {@link BlazeDirectories} is null or Bazel fails to find the workspace root directory.