diff options
author | 2016-01-25 16:04:23 +0000 | |
---|---|---|
committer | 2016-01-25 16:52:26 +0000 | |
commit | 5db44f222687c49c4284bd2f47d58cc8f6545e6b (patch) | |
tree | bd6f542366e61e67c82a238c04e7bc0d83c5b93b /src | |
parent | 58581a35bf0d11e53669e875b4e4f060ebf5aaaf (diff) |
Rollback of commit bd9f25c593a140acb15d3fd3fc7f66d091e1a898.
*** Reason for rollback ***
Violates layering - genrule should not depend on platform- or language-specific parts.
*** Original change description ***
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=112951074
Diffstat (limited to 'src')
6 files changed, 4 insertions, 100 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 8433d4903e..684f998b8f 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,10 +126,6 @@ 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 56344d6f2f..f1682dd16c 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,8 +31,6 @@ 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. @@ -49,7 +47,6 @@ 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. @@ -218,7 +215,7 @@ public final class BazelGenRuleRule implements RuleDefinition { public Metadata getMetadata() { return RuleDefinition.Metadata.builder() .name("genrule") - .ancestors(BaseRuleClasses.RuleBase.class, RequiresXcodeConfigRule.class) + .ancestors(BaseRuleClasses.RuleBase.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 63fa6457de..d9c855a32a 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,23 +39,17 @@ 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); @@ -105,15 +99,6 @@ 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); @@ -122,6 +107,8 @@ 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())); @@ -149,7 +136,7 @@ public class GenRule implements RuleConfiguredTargetFactory { inputs.build(), filesToBuild, argv, - envBuilder.build(), + env, ImmutableMap.copyOf(executionInfo), commandHelper.getRemoteRunfileManifestMap(), message + ' ' + ruleContext.getLabel())); @@ -211,8 +198,6 @@ 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); } diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java index e763627037..32f8027723 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java @@ -219,26 +219,12 @@ public abstract class BuildViewTestCase extends FoundationTestCase { new PathPackageLocator(outputBase, ImmutableList.of(rootDirectory)), ConstantRuleVisibility.PUBLIC, true, 7, "", UUID.randomUUID()); - // The below call evaluates and caches the build graph. If any modifications are made to - // packages which have already been set up, they will not be in the current cached build graph - // view. Call {@link #invalidateAllFiles} to clear this cache. useConfiguration(); setUpSkyframe(); // Also initializes ResourceManager. ResourceManager.instance().setAvailableResources(getStartingResources()); } - /** - * Clears the current build graph cache by invalidating all files. - */ - protected void invalidateAllFiles() throws InterruptedException { - // This is necessary as the build graph may have already been evaluated and cached. If so, - // the previous setup steps in this method would not be taken into account in any of the - // build graphs for this class's tests. - getSkyframeExecutor().invalidateFilesUnderPathForTesting(reporter, - ModifiedFileSet.EVERYTHING_MODIFIED, rootDirectory); - } - protected AnalysisMock getAnalysisMock() { try { Class<?> providerClass = Class.forName(TestConstants.TEST_ANALYSIS_MOCK); diff --git a/src/test/shell/bazel/BUILD b/src/test/shell/bazel/BUILD index 6f179feefd..21863ed6f0 100644 --- a/src/test/shell/bazel/BUILD +++ b/src/test/shell/bazel/BUILD @@ -120,14 +120,6 @@ sh_test( ) sh_test( - name = "bazel_mac_genrule_test", - srcs = ["bazel_mac_genrule_test.sh"], - data = [ - ":test-deps", - ], -) - -sh_test( name = "bazel_execute_testlog", srcs = ["bazel_execute_testlog.sh"], data = [":test-deps"], diff --git a/src/test/shell/bazel/bazel_mac_genrule_test.sh b/src/test/shell/bazel/bazel_mac_genrule_test.sh deleted file mode 100755 index a7e0552eee..0000000000 --- a/src/test/shell/bazel/bazel_mac_genrule_test.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/bash -# -# Copyright 2016 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } - -if [ "${PLATFORM}" != "darwin" ]; then - echo "This test suite requires running on OS X" >&2 - exit 0 -fi - -function test_developer_dir() { - mkdir -p package - # TODO(bazel-team): Local host genrule execution should convert - # the XCODE_VERSION_OVERRIDE environment variable to a DEVELOPER_DIR - # absolute path, preventing us from needing to set this environment - # variable ourself. - export DEVELOPER_DIR="/Applications/Xcode_5.4.app/Contents/Developer/" - - echo "\\\${XCODE_VERSION_OVERRIDE}" ${DEVELOPER_DIR} - - cat > package/BUILD <<EOF -genrule( - name = "foo", - srcs = [], - outs = ["developerdir.out"], - tags = ["requires-darwin"], - cmd = "DEVELOPER_DIR='${DEVELOPER_DIR}' && echo \$\${XCODE_VERSION_OVERRIDE} \$(DEVELOPER_DIR) > \$@", -) -EOF - - bazel build -s //package:foo --xcode_version=5.4 || fail "Should build" - assert_equals "5.4 /Applications/Xcode_5.4.app/Contents/Developer/" \ - "$(cat bazel-genfiles/package/developerdir.out)" || \ - fail "Unexpected value for DEVELOPER_DIR make variable" -} - -run_suite "genrule test suite for Apple Mac hosts" |