diff options
author | 2016-01-20 20:06:28 +0000 | |
---|---|---|
committer | 2016-01-21 10:34:49 +0000 | |
commit | bd9f25c593a140acb15d3fd3fc7f66d091e1a898 (patch) | |
tree | 8a91d7d3aeb44f0e226138f73aa34fb4c49f1505 /src/main/java | |
parent | e87849b8d391af8f5d98e3a91e680e88a1264b64 (diff) |
Add a DEVELOPER_DIR make variable to genrules to propagate the apple xcode environment variable DEVELOPER_DIR to commands.
If $(DEVELOPER_DIR) is included in the genrule command, we bootstrap the XCODE_VERSION_OVERRIDE environment variable to the command.
The contract with the actual action executor is, if XCODE_VERSION_OVERRIDE is present in the environment, to additionally bootstrap the DEVELOPER_DIR absolute path to the command.
--
MOS_MIGRATED_REVID=112605616
Diffstat (limited to 'src/main/java')
3 files changed, 26 insertions, 4 deletions
diff --git a/src/main/java/com/google/devtools/build/docgen/templates/be/make-variables.vm b/src/main/java/com/google/devtools/build/docgen/templates/be/make-variables.vm index 684f998b8f..8433d4903e 100644 --- a/src/main/java/com/google/devtools/build/docgen/templates/be/make-variables.vm +++ b/src/main/java/com/google/devtools/build/docgen/templates/be/make-variables.vm @@ -126,6 +126,10 @@ in your genrule's cmd attribute. the tool is to use <code>$(location <i>toolname</i>)</code>, where <i>toolname</i> must be listed in the <code>tools</code> attribute for the genrule.</li> + <li><code>DEVELOPER_DIR</code>: + The base developer directory as defined on Apple architectures, most commonly + used in invoking Apple tools such as <code>xcrun</code>. + Supported only on Apple execution hosts.</li> <li><code>GENDIR</code>: The base of the generated code tree for the target architecture.</li> <li><code>JAVABASE</code>: diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/genrule/BazelGenRuleRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/genrule/BazelGenRuleRule.java index 593d32aed2..e153e13e5e 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/genrule/BazelGenRuleRule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/genrule/BazelGenRuleRule.java @@ -31,6 +31,8 @@ import com.google.devtools.build.lib.packages.AttributeMap; import com.google.devtools.build.lib.packages.BuildType; import com.google.devtools.build.lib.packages.RuleClass; import com.google.devtools.build.lib.packages.RuleClass.Builder; +import com.google.devtools.build.lib.rules.apple.AppleConfiguration; +import com.google.devtools.build.lib.rules.apple.AppleToolchain.RequiresXcodeConfigRule; /** * Rule definition for the genrule rule. @@ -47,6 +49,7 @@ public final class BazelGenRuleRule implements RuleDefinition { <code>srcs</code> attribute. <!-- #END_BLAZE_RULE.NAME --> */ return builder + .requiresConfigurationFragments(AppleConfiguration.class) .setOutputToGenfiles() /* <!-- #BLAZE_RULE(genrule).ATTRIBUTE(srcs) --> A list of inputs for this rule, such as source files to process. @@ -215,7 +218,7 @@ public final class BazelGenRuleRule implements RuleDefinition { public Metadata getMetadata() { return RuleDefinition.Metadata.builder() .name("genrule") - .ancestors(BaseRuleClasses.RuleBase.class) + .ancestors(BaseRuleClasses.RuleBase.class, RequiresXcodeConfigRule.class) .factoryClass(GenRule.class) .build(); } diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/genrule/GenRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/genrule/GenRule.java index d9c855a32a..63fa6457de 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/genrule/GenRule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/genrule/GenRule.java @@ -39,17 +39,23 @@ import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.collect.nestedset.Order; import com.google.devtools.build.lib.packages.TargetUtils; import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory; +import com.google.devtools.build.lib.rules.apple.AppleToolchain; +import com.google.devtools.build.lib.rules.apple.XcodeConfigProvider; import com.google.devtools.build.lib.syntax.Type; import com.google.devtools.build.lib.vfs.PathFragment; import java.util.List; import java.util.Map; +import java.util.regex.Pattern; /** * An implementation of genrule. */ public class GenRule implements RuleConfiguredTargetFactory { + private static final Pattern DEVELOPER_DIR_MAKE_VARIABLE = + Pattern.compile("\\$\\((DEVELOPER_DIR)\\)"); + private Artifact getExecutable(RuleContext ruleContext, NestedSet<Artifact> filesToBuild) { if (Iterables.size(filesToBuild) == 1) { Artifact out = Iterables.getOnlyElement(filesToBuild); @@ -99,6 +105,15 @@ public class GenRule implements RuleConfiguredTargetFactory { String command = String.format("source %s; %s", ruleContext.getPrerequisiteArtifact("$genrule_setup", Mode.HOST).getExecPath(), baseCommand); + + ImmutableMap.Builder<String, String> envBuilder = ImmutableMap.<String, String>builder() + .putAll(ruleContext.getConfiguration().getLocalShellEnvironment()); + + if (DEVELOPER_DIR_MAKE_VARIABLE.matcher(command).find()) { + XcodeConfigProvider xcodeConfigProvider = + ruleContext.getPrerequisite(":xcode_config", Mode.HOST, XcodeConfigProvider.class); + envBuilder.putAll(AppleToolchain.appleHostSystemEnv(xcodeConfigProvider)); + } command = resolveCommand(ruleContext, command, resolvedSrcs, filesToBuild); @@ -107,8 +122,6 @@ public class GenRule implements RuleConfiguredTargetFactory { message = "Executing genrule"; } - ImmutableMap<String, String> env = ruleContext.getConfiguration().getLocalShellEnvironment(); - Map<String, String> executionInfo = Maps.newLinkedHashMap(); executionInfo.putAll(TargetUtils.getExecutionInfo(ruleContext.getRule())); @@ -136,7 +149,7 @@ public class GenRule implements RuleConfiguredTargetFactory { inputs.build(), filesToBuild, argv, - env, + envBuilder.build(), ImmutableMap.copyOf(executionInfo), commandHelper.getRemoteRunfileManifestMap(), message + ' ' + ruleContext.getLabel())); @@ -198,6 +211,8 @@ public class GenRule implements RuleConfiguredTargetFactory { PathFragment relPath = ruleContext.getRule().getLabel().getPackageFragment(); return dir.getRelative(relPath).getPathString(); } + } else if (DEVELOPER_DIR_MAKE_VARIABLE.matcher("$(" + name + ")").find()) { + return "$${DEVELOPER_DIR}"; } else { return super.lookupMakeVariable(name); } |