diff --git a/.bazelci/postsubmit.yml b/.bazelci/postsubmit.yml index 0ff4c51bcb282a..cfa0d90314b24d 100644 --- a/.bazelci/postsubmit.yml +++ b/.bazelci/postsubmit.yml @@ -44,13 +44,27 @@ tasks: - "-//src/test/shell/bazel:bazel_coverage_cc_released_test_gcc" - "-//src/test/shell/bazel:bazel_coverage_cc_head_test_gcc" - "-//src/test/shell/bazel:bazel_coverage_sh_test" - # https://github.com/bazelbuild/bazel/issues/18776 + # Centos7 uses python 2 by default, so these fail: https://github.com/bazelbuild/bazel/issues/18776 - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test" - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test_with_head_android_tools" - - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test_with_platforms" - "-//src/test/shell/bazel/android:aapt_integration_test" - "-//src/test/shell/bazel/android:aapt_integration_test_with_head_android_tools" - - "-//src/test/shell/bazel/android:aapt_integration_test_with_platforms" + include_json_profile: + - build + - test + fedora39: + shell_commands: + - sed -i.bak -e 's/^# android_sdk_repository/android_sdk_repository/' -e 's/^# + android_ndk_repository/android_ndk_repository/' WORKSPACE.bzlmod + - rm -f WORKSPACE.bzlmod.bak + - rm -rf $HOME/bazeltest + - mkdir $HOME/bazeltest + build_flags: + - "--config=ci-linux" + build_targets: + - "//src:bazel" + - "//src:bazel_jdk_minimal" + - "//src/main/java/..." include_json_profile: - build - test @@ -85,13 +99,6 @@ tasks: - "//tools/bash/..." # Re-enable once fixed: https://github.com/bazelbuild/bazel/issues/8162 - "-//src/java_tools/import_deps_checker/..." - # https://github.com/bazelbuild/bazel/issues/18776 - - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test" - - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test_with_head_android_tools" - - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test_with_platforms" - - "-//src/test/shell/bazel/android:aapt_integration_test" - - "-//src/test/shell/bazel/android:aapt_integration_test_with_head_android_tools" - - "-//src/test/shell/bazel/android:aapt_integration_test_with_platforms" include_json_profile: - build - test @@ -152,13 +159,6 @@ tasks: - "//tools/bash/..." # Re-enable once fixed: https://github.com/bazelbuild/bazel/issues/8162 - "-//src/java_tools/import_deps_checker/..." - # https://github.com/bazelbuild/bazel/issues/18776 - - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test" - - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test_with_head_android_tools" - - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test_with_platforms" - - "-//src/test/shell/bazel/android:aapt_integration_test" - - "-//src/test/shell/bazel/android:aapt_integration_test_with_head_android_tools" - - "-//src/test/shell/bazel/android:aapt_integration_test_with_platforms" include_json_profile: - build - test @@ -206,13 +206,6 @@ tasks: - "-//src/test/shell/bazel/apple:bazel_apple_test" # https://github.com/bazelbuild/bazel/issues/17408 - "-//src/test/shell/bazel/apple:bazel_objc_test" - # https://github.com/bazelbuild/bazel/issues/18776 - - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test" - - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test_with_head_android_tools" - - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test_with_platforms" - - "-//src/test/shell/bazel/android:aapt_integration_test" - - "-//src/test/shell/bazel/android:aapt_integration_test_with_head_android_tools" - - "-//src/test/shell/bazel/android:aapt_integration_test_with_platforms" # https://github.com/bazelbuild/bazel/issues/17410 - "-//src/test/java/com/google/devtools/build/lib/platform:SystemMemoryPressureEventTest" # https://github.com/bazelbuild/bazel/issues/17411 @@ -223,6 +216,17 @@ tasks: - "-//src/test/shell/bazel:bazel_determinism_test" # https://github.com/bazelbuild/bazel/issues/17457 - "-//src/test/shell/bazel:jdeps_test" + # Macs can't find python, so these fail: https://github.com/bazelbuild/bazel/issues/18776 + - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test" + - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test_with_head_android_tools" + - "-//src/test/shell/bazel/android:aapt_integration_test" + - "-//src/test/shell/bazel/android:aapt_integration_test_with_head_android_tools" + # Disable recently regressed tests: https://github.com/bazelbuild/bazel/issues/20437 + - "-//src/test/java/com/google/devtools/build/lib/rules/cpp:CppSysrootTest" + - "-//src/test/java/com/google/devtools/build/lib/rules/cpp:CcImportConfiguredTargetTest" + - "-//src/test/java/com/google/devtools/build/lib/rules/objc:ObjcRulesTests" + - "-//src/test/java/com/google/devtools/build/lib/rules/objc:BazelJ2ObjcLibraryTest" + - "-//src/test/java/com/google/devtools/build/lib/rules/cpp:CcToolchainTest" include_json_profile: - build - test @@ -262,10 +266,6 @@ tasks: - "-//src/test/shell/bazel:bazel_cc_code_coverage_test" # MacOS does not have cgroups so it can't support hardened sandbox - "-//src/test/shell/integration:bazel_hardened_sandboxed_worker_test" - # https://github.com/bazelbuild/bazel/issues/16521 & https://github.com/bazelbuild/bazel/issues/18776 - - "-//src/test/shell/bazel/android/..." - - "-//src/tools/android/java/com/google/devtools/build/android/..." - - "-//src/test/java/com/google/devtools/build/android/dexer:AllTests" # https://github.com/bazelbuild/bazel/issues/16525 - "-//src/test/java/com/google/devtools/build/lib/buildtool:KeepGoingTest" - "-//src/test/java/com/google/devtools/build/lib/buildtool:DanglingSymlinkTest" @@ -277,6 +277,25 @@ tasks: - "-//src/test/java/com/google/devtools/build/lib/rules/objc:ObjcRulesTests" # https://github.com/bazelbuild/bazel/issues/17007 - "-//src/test/java/com/google/devtools/build/lib/platform:SystemMemoryPressureEventTest" + # https://github.com/bazelbuild/bazel/issues/16521 & https://github.com/bazelbuild/bazel/issues/18776 + - "-//src/test/shell/bazel/android/..." + - "-//src/tools/android/java/com/google/devtools/build/android/..." + - "-//src/test/java/com/google/devtools/build/android/dexer:AllTests" + # Macs can't find python, so these fail: https://github.com/bazelbuild/bazel/issues/18776 + - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test" + - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test_with_head_android_tools" + - "-//src/test/shell/bazel/android:aapt_integration_test" + - "-//src/test/shell/bazel/android:aapt_integration_test_with_head_android_tools" + # Disable recently regressed tests: https://github.com/bazelbuild/bazel/issues/20437 + - "-//src/test/java/com/google/devtools/build/lib/rules/cpp:CppSysrootTest" + - "-//src/test/java/com/google/devtools/build/lib/rules/cpp:CcImportConfiguredTargetTest" + - "-//src/test/java/com/google/devtools/build/lib/rules/objc:ObjcRulesTests" + - "-//src/test/java/com/google/devtools/build/lib/rules/objc:BazelJ2ObjcLibraryTest" + - "-//src/test/java/com/google/devtools/build/lib/rules/cpp:CcToolchainTest" + # https://github.com/bazelbuild/bazel/issues/17411 + - "-//src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace:PatchApiBlackBoxTest" + # https://github.com/bazelbuild/bazel/issues/17447 + - "-//src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace:GitRepositoryBlackBoxTest" include_json_profile: - build - test @@ -404,13 +423,6 @@ tasks: - "-//src/test/py/bazel:bazel_yanked_versions_test" - "-//src/test/py/bazel:bzlmod_query_test" - "-//src/test/shell/bazel:verify_workspace" - # https://github.com/bazelbuild/bazel/issues/18776 - - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test" - - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test_with_head_android_tools" - - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test_with_platforms" - - "-//src/test/shell/bazel/android:aapt_integration_test" - - "-//src/test/shell/bazel/android:aapt_integration_test_with_head_android_tools" - - "-//src/test/shell/bazel/android:aapt_integration_test_with_platforms" include_json_profile: - build - test diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 7d24c739659aca..4ecbd214998351 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -45,13 +45,27 @@ tasks: - "-//src/test/shell/bazel:bazel_coverage_cc_released_test_gcc" - "-//src/test/shell/bazel:bazel_coverage_cc_head_test_gcc" - "-//src/test/shell/bazel:bazel_coverage_sh_test" - # https://github.com/bazelbuild/bazel/issues/18776 + # Centos7 uses python 2 by default, so these fail: https://github.com/bazelbuild/bazel/issues/18776 - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test" - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test_with_head_android_tools" - - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test_with_platforms" - "-//src/test/shell/bazel/android:aapt_integration_test" - "-//src/test/shell/bazel/android:aapt_integration_test_with_head_android_tools" - - "-//src/test/shell/bazel/android:aapt_integration_test_with_platforms" + include_json_profile: + - build + - test + fedora39: + shell_commands: + - sed -i.bak -e 's/^# android_sdk_repository/android_sdk_repository/' -e 's/^# + android_ndk_repository/android_ndk_repository/' WORKSPACE.bzlmod + - rm -f WORKSPACE.bzlmod.bak + - rm -rf $HOME/bazeltest + - mkdir $HOME/bazeltest + build_flags: + - "--config=ci-linux" + build_targets: + - "//src:bazel" + - "//src:bazel_jdk_minimal" + - "//src/main/java/..." include_json_profile: - build - test @@ -87,13 +101,6 @@ tasks: - "//tools/bash/..." # Re-enable once fixed: https://github.com/bazelbuild/bazel/issues/8162 - "-//src/java_tools/import_deps_checker/..." - # https://github.com/bazelbuild/bazel/issues/18776 - - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test" - - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test_with_head_android_tools" - - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test_with_platforms" - - "-//src/test/shell/bazel/android:aapt_integration_test" - - "-//src/test/shell/bazel/android:aapt_integration_test_with_head_android_tools" - - "-//src/test/shell/bazel/android:aapt_integration_test_with_platforms" include_json_profile: - build - test @@ -155,13 +162,6 @@ tasks: - "//tools/bash/..." # Re-enable once fixed: https://github.com/bazelbuild/bazel/issues/8162 - "-//src/java_tools/import_deps_checker/..." - # https://github.com/bazelbuild/bazel/issues/18776 - - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test" - - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test_with_head_android_tools" - - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test_with_platforms" - - "-//src/test/shell/bazel/android:aapt_integration_test" - - "-//src/test/shell/bazel/android:aapt_integration_test_with_head_android_tools" - - "-//src/test/shell/bazel/android:aapt_integration_test_with_platforms" include_json_profile: - build - test @@ -210,13 +210,6 @@ tasks: - "-//src/test/shell/bazel/apple:bazel_apple_test" # https://github.com/bazelbuild/bazel/issues/17408 - "-//src/test/shell/bazel/apple:bazel_objc_test" - # https://github.com/bazelbuild/bazel/issues/18776 - - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test" - - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test_with_head_android_tools" - - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test_with_platforms" - - "-//src/test/shell/bazel/android:aapt_integration_test" - - "-//src/test/shell/bazel/android:aapt_integration_test_with_head_android_tools" - - "-//src/test/shell/bazel/android:aapt_integration_test_with_platforms" # https://github.com/bazelbuild/bazel/issues/17410 - "-//src/test/java/com/google/devtools/build/lib/platform:SystemMemoryPressureEventTest" # https://github.com/bazelbuild/bazel/issues/17411 @@ -227,6 +220,17 @@ tasks: - "-//src/test/shell/bazel:bazel_determinism_test" # https://github.com/bazelbuild/bazel/issues/17457 - "-//src/test/shell/bazel:jdeps_test" + # Macs can't find python, so these fail: https://github.com/bazelbuild/bazel/issues/18776 + - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test" + - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test_with_head_android_tools" + - "-//src/test/shell/bazel/android:aapt_integration_test" + - "-//src/test/shell/bazel/android:aapt_integration_test_with_head_android_tools" + # Disable recently regressed tests: https://github.com/bazelbuild/bazel/issues/20437 + - "-//src/test/java/com/google/devtools/build/lib/rules/cpp:CppSysrootTest" + - "-//src/test/java/com/google/devtools/build/lib/rules/cpp:CcImportConfiguredTargetTest" + - "-//src/test/java/com/google/devtools/build/lib/rules/objc:ObjcRulesTests" + - "-//src/test/java/com/google/devtools/build/lib/rules/objc:BazelJ2ObjcLibraryTest" + - "-//src/test/java/com/google/devtools/build/lib/rules/cpp:CcToolchainTest" include_json_profile: - build - test @@ -267,10 +271,6 @@ tasks: - "-//src/test/shell/bazel:bazel_cc_code_coverage_test" # MacOS does not have cgroups so it can't support hardened sandbox - "-//src/test/shell/integration:bazel_hardened_sandboxed_worker_test" - # https://github.com/bazelbuild/bazel/issues/16521 & https://github.com/bazelbuild/bazel/issues/18776 - - "-//src/test/shell/bazel/android/..." - - "-//src/tools/android/java/com/google/devtools/build/android/..." - - "-//src/test/java/com/google/devtools/build/android/dexer:AllTests" # https://github.com/bazelbuild/bazel/issues/16525 - "-//src/test/java/com/google/devtools/build/lib/buildtool:KeepGoingTest" - "-//src/test/java/com/google/devtools/build/lib/buildtool:DanglingSymlinkTest" @@ -335,6 +335,26 @@ tasks: - "-//src/test/shell/bazel:bazel_repository_cache_test" - "-//src/test/shell/integration:aquery_test" - "-//src/test/shell/integration:py_args_escaping_test" + # https://github.com/bazelbuild/bazel/issues/16521 & https://github.com/bazelbuild/bazel/issues/18776 + - "-//src/test/shell/bazel/android/..." + - "-//src/tools/android/java/com/google/devtools/build/android/..." + - "-//src/test/java/com/google/devtools/build/android/dexer:AllTests" + # Macs can't find python, so these fail: https://github.com/bazelbuild/bazel/issues/18776 + - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test" + - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test_with_head_android_tools" + - "-//src/test/shell/bazel/android:aapt_integration_test" + - "-//src/test/shell/bazel/android:aapt_integration_test_with_head_android_tools" + # Disable recently regressed tests: https://github.com/bazelbuild/bazel/issues/20437 + - "-//src/test/java/com/google/devtools/build/lib/rules/cpp:CppSysrootTest" + - "-//src/test/java/com/google/devtools/build/lib/rules/cpp:CcImportConfiguredTargetTest" + - "-//src/test/java/com/google/devtools/build/lib/rules/objc:ObjcRulesTests" + - "-//src/test/java/com/google/devtools/build/lib/rules/objc:BazelJ2ObjcLibraryTest" + - "-//src/test/java/com/google/devtools/build/lib/rules/cpp:CcToolchainTest" + - "-//src/test/shell/integration:minimal_jdk_test" + # https://github.com/bazelbuild/bazel/issues/17411 + - "-//src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace:PatchApiBlackBoxTest" + # https://github.com/bazelbuild/bazel/issues/17447 + - "-//src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace:GitRepositoryBlackBoxTest" include_json_profile: - build - test @@ -468,13 +488,6 @@ tasks: # Flaky on rbe_ubuntu2004 # https://github.com/bazelbuild/continuous-integration/issues/1631 - "-//src/test/shell/bazel:bazel_sandboxing_networking_test" - # https://github.com/bazelbuild/bazel/issues/18776 - - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test" - - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test_with_head_android_tools" - - "-//src/test/shell/bazel/android:android_instrumentation_test_integration_test_with_platforms" - - "-//src/test/shell/bazel/android:aapt_integration_test" - - "-//src/test/shell/bazel/android:aapt_integration_test_with_head_android_tools" - - "-//src/test/shell/bazel/android:aapt_integration_test_with_platforms" include_json_profile: - build - test diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/SingleExtensionEvalFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/SingleExtensionEvalFunction.java index 4cd81e7eeed0ec..48b10d462a5f4f 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/SingleExtensionEvalFunction.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/SingleExtensionEvalFunction.java @@ -620,7 +620,7 @@ public RunModuleExtensionResult run( // Instiantiate the repos one by one. for (InnateExtensionRepo repo : repos) { Object exported = repo.loadedBzl().getModule().getGlobal(repo.ruleName()); - if (!(exported instanceof RepositoryRuleFunction)) { + if (exported == null) { ImmutableSet exportedRepoRules = repo.loadedBzl().getModule().getGlobals().entrySet().stream() .filter(e -> e.getValue() instanceof RepositoryRuleFunction) @@ -636,6 +636,17 @@ public RunModuleExtensionResult run( repo.tag().getLocation(), SpellChecker.didYouMean(repo.ruleName(), exportedRepoRules)), Transience.PERSISTENT); + } else if (!(exported instanceof RepositoryRuleFunction)) { + throw new SingleExtensionEvalFunctionException( + ExternalDepsException.withMessage( + Code.BAD_MODULE, + "%s exports a value called %s of type %s, yet a repository_rule is requested" + + " at %s", + repo.bzlLabel(), + repo.ruleName(), + Starlark.type(exported), + repo.tag().getLocation()), + Transience.PERSISTENT); } RepositoryRuleFunction repoRule = (RepositoryRuleFunction) exported; Dict kwargs = repo.tag().getAttributeValues().attributes(); diff --git a/src/main/java/com/google/devtools/build/lib/cmdline/RepositoryMapping.java b/src/main/java/com/google/devtools/build/lib/cmdline/RepositoryMapping.java index 0246c930171776..b15bdadc61cc22 100644 --- a/src/main/java/com/google/devtools/build/lib/cmdline/RepositoryMapping.java +++ b/src/main/java/com/google/devtools/build/lib/cmdline/RepositoryMapping.java @@ -14,9 +14,10 @@ package com.google.devtools.build.lib.cmdline; -import com.google.auto.value.AutoValue; +import com.google.common.base.Objects; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; @@ -24,43 +25,66 @@ import javax.annotation.Nullable; /** - * A class to distinguish repository mappings for repos from WORKSPACE and Bzlmod. + * Stores the mapping from apparent repo name to canonical repo name, from the viewpoint of an + * "owner repo". * *

For repositories from the WORKSPACE file, if the requested repo doesn't exist in the mapping, * we fallback to the requested name. For repositories from Bzlmod, we return null to let the caller - * decide what to do. This class won't be needed if one day we don't define external repositories in - * the WORKSPACE file since {@code fallback} would always be false. + * decide what to do. */ -@AutoValue -public abstract class RepositoryMapping { - - // Always fallback to the requested name +public class RepositoryMapping { + /* A repo mapping that always falls back to using the apparent name as the canonical name. */ public static final RepositoryMapping ALWAYS_FALLBACK = createAllowingFallback(ImmutableMap.of()); + private final ImmutableMap entries; + @Nullable private final RepositoryName ownerRepo; + + private RepositoryMapping( + Map entries, @Nullable RepositoryName ownerRepo) { + this.entries = ImmutableMap.copyOf(entries); + this.ownerRepo = ownerRepo; + } + /** Returns all the entries in this repo mapping. */ - public abstract ImmutableMap entries(); + public final ImmutableMap entries() { + return entries; + } /** * The owner repo of this repository mapping. It is for providing useful debug information when * repository mapping fails due to enforcing strict dependency, therefore it's only recorded when - * we don't fallback to the requested repo name. + * we don't fall back to the requested repo name. */ @Nullable - abstract RepositoryName ownerRepo(); + public final RepositoryName ownerRepo() { + return ownerRepo; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof RepositoryMapping)) { + return false; + } + RepositoryMapping that = (RepositoryMapping) o; + return Objects.equal(entries, that.entries) && Objects.equal(ownerRepo, that.ownerRepo); + } + + @Override + public int hashCode() { + return Objects.hashCode(entries, ownerRepo); + } public static RepositoryMapping create( Map entries, RepositoryName ownerRepo) { - return createInternal( + return new RepositoryMapping( Preconditions.checkNotNull(entries), Preconditions.checkNotNull(ownerRepo)); } public static RepositoryMapping createAllowingFallback(Map entries) { - return createInternal(Preconditions.checkNotNull(entries), null); - } - - private static RepositoryMapping createInternal( - Map entries, RepositoryName ownerRepo) { - return new AutoValue_RepositoryMapping(ImmutableMap.copyOf(entries), ownerRepo); + return new RepositoryMapping(Preconditions.checkNotNull(entries), null); } /** @@ -70,7 +94,7 @@ private static RepositoryMapping createInternal( public RepositoryMapping withAdditionalMappings(Map additionalMappings) { HashMap allMappings = new HashMap<>(additionalMappings); allMappings.putAll(entries()); - return createInternal(allMappings, ownerRepo()); + return new RepositoryMapping(allMappings, ownerRepo()); } /** @@ -134,6 +158,26 @@ public RepositoryMapping composeWith(RepositoryMapping other) { RepositoryName mappedName = other.get(entry.getValue().getName()); entries.put(entry.getKey(), mappedName.isVisible() ? mappedName : entry.getValue()); } - return createInternal(entries, null); + return new RepositoryMapping(entries, null); + } + + /** + * Returns a new {@link RepositoryMapping} instance with identical contents, except that the + * inverse mapping is cached, causing {@link #getInverse} to be much more efficient. This is + * particularly important for the main repo mapping, as it's often used to generate display-form + * labels ({@link Label#getDisplayForm}). + */ + public RepositoryMapping withCachedInverseMap() { + var inverse = Maps.newHashMapWithExpectedSize(entries.size()); + for (Map.Entry entry : entries.entrySet()) { + inverse.putIfAbsent(entry.getValue(), entry.getKey()); + } + var inverseCopy = ImmutableMap.copyOf(inverse); + return new RepositoryMapping(entries, ownerRepo) { + @Override + public Optional getInverse(RepositoryName postMappingName) { + return Optional.ofNullable(inverseCopy.get(postMappingName)); + } + }; } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/config/ConfigSetting.java b/src/main/java/com/google/devtools/build/lib/rules/config/ConfigSetting.java index cc06b86450274f..cb70244ed28eea 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/config/ConfigSetting.java +++ b/src/main/java/com/google/devtools/build/lib/rules/config/ConfigSetting.java @@ -497,10 +497,14 @@ static UserDefinedFlagMatch fromAttributeValueAndPrerequisites( } else if (target.satisfies(BuildSettingProvider.REQUIRE_BUILD_SETTING_PROVIDER)) { // build setting BuildSettingProvider provider = target.getProvider(BuildSettingProvider.class); - Object configurationValue = - optionDetails.getOptionValue(specifiedLabel) != null - ? optionDetails.getOptionValue(specifiedLabel) - : provider.getDefaultValue(); + + Object configurationValue; + if (optionDetails.getOptionValue(provider.getLabel()) != null) { + configurationValue = optionDetails.getOptionValue(provider.getLabel()); + } else { + configurationValue = provider.getDefaultValue(); + } + Object convertedSpecifiedValue; try { // We don't need to supply a base package or repo mapping for the conversion here, diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RepositoryMappingFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/RepositoryMappingFunction.java index ee6ea36772edef..29d92be8f7c90c 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/RepositoryMappingFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/RepositoryMappingFunction.java @@ -126,14 +126,17 @@ public SkyValue compute(SkyKey skyKey, Environment env) .withAdditionalMappings( ImmutableMap.of( externalPackageValue.getPackage().getWorkspaceName(), RepositoryName.MAIN)) - .withAdditionalMappings(additionalMappings); + .withAdditionalMappings(additionalMappings) + .withCachedInverseMap(); } // Try and see if this is a repo generated from a Bazel module. Optional mappingValue = computeForBazelModuleRepo(repositoryName, bazelDepGraphValue); if (mappingValue.isPresent()) { - return mappingValue.get(); + return repositoryName.isMain() + ? mappingValue.get().withCachedInverseMap() + : mappingValue.get(); } // Now try and see if this is a repo generated from a module extension. diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RepositoryMappingValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/RepositoryMappingValue.java index a6a0346b13e4b9..d32aea20728326 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/RepositoryMappingValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/RepositoryMappingValue.java @@ -107,6 +107,17 @@ public final RepositoryMappingValue withAdditionalMappings(Map result = + evaluator.evaluate(ImmutableList.of(skyKey), evaluationContext); + assertThat(result.hasError()).isTrue(); + assertThat(result.getError().getException()) + .hasMessageThat() + .contains( + "//:repo.bzl exports a value called data_repo of type function, yet a repository_rule" + + " is requested at /ws/MODULE.bazel"); + } + + @Test + public void innate_noSuchValue() throws Exception { + scratch.file( + workspaceRoot.getRelative("MODULE.bazel").getPathString(), + "data_repo = use_repo_rule('//:repo.bzl', 'data_repo')", + "data_repo(name='data', data='get up at 6am.')"); + scratch.file(workspaceRoot.getRelative("BUILD").getPathString()); + scratch.file( + workspaceRoot.getRelative("data.bzl").getPathString(), + "load('@data//:data.bzl', self_data='data')", + "data=self_data"); + scratch.file(workspaceRoot.getRelative("repo.bzl").getPathString(), ""); SkyKey skyKey = BzlLoadValue.keyForBuild(Label.parseCanonical("//:data.bzl")); reporter.removeHandler(failFastHandler); diff --git a/src/test/java/com/google/devtools/build/lib/rules/LabelBuildSettingTest.java b/src/test/java/com/google/devtools/build/lib/rules/LabelBuildSettingTest.java index 5500ab253823fc..013cc9a02580d3 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/LabelBuildSettingTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/LabelBuildSettingTest.java @@ -116,6 +116,35 @@ public void testLabelFlag_set() throws Exception { assertThat(b.get("value")).isEqualTo("command_line_value"); } + @Test + public void withSelectThroughAlias() throws Exception { + writeRulesBzl("flag"); + scratch.file( + "test/BUILD", + "load('//test:rules.bzl', 'my_rule', 'simple_rule')", + "simple_rule(name = 'default', value = 'default_value')", + "simple_rule(name = 'command_line', value = 'command_line_value')", + "label_flag(name = 'my_label_flag', build_setting_default = ':default')", + "alias(name = 'my_label_flag_alias', actual = ':my_label_flag')", + "config_setting(", + " name = 'is_default_label',", + " flag_values = {':my_label_flag_alias': '//test:default'}", + ")", + "simple_rule(name = 'selector', value = select({':is_default_label': 'valid'}))"); + + useConfiguration(); + getConfiguredTarget("//test:selector"); + assertNoEvents(); + + reporter.removeHandler(failFastHandler); + useConfiguration( + ImmutableMap.of( + "//test:my_label_flag", Label.parseCanonicalUnchecked("//test:command_line"))); + getConfiguredTarget("//test:selector"); + assertContainsEvent( + "configurable attribute \"value\" in //test:selector doesn't match this configuration"); + } + @Test public void withSelect() throws Exception { writeRulesBzl("flag"); diff --git a/src/test/java/com/google/devtools/build/lib/rules/config/ConfigSettingTest.java b/src/test/java/com/google/devtools/build/lib/rules/config/ConfigSettingTest.java index e96fb2f94d8e63..84ef07d33a286d 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/config/ConfigSettingTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/config/ConfigSettingTest.java @@ -2174,6 +2174,27 @@ public void ruleLicensesUsed() throws Exception { assertThat(getLicenses("//test:match")).containsExactly(LicenseType.NONE); } + @Test + public void aliasedStarlarkFlag() throws Exception { + scratch.file( + "test/flagdef.bzl", + "def _impl(ctx):", + " return []", + "my_flag = rule(", + " implementation = _impl,", + " build_setting = config.string(flag = True))"); + + scratch.file( + "test/BUILD", + "load('//test:flagdef.bzl', 'my_flag')", + "my_flag(name = 'flag', build_setting_default = 'default')", + "alias(name = 'alias', actual = ':flag')", + "config_setting(name = 'alias_setting', flag_values = {':alias': 'specified'})"); + + useConfiguration(ImmutableMap.of("//test:flag", "specified")); + assertThat(getConfigMatchingProviderResultAsBoolean("//test:alias_setting")).isTrue(); + } + @Test public void simpleStarlarkFlag() throws Exception { scratch.file( diff --git a/src/test/py/bazel/py_test.py b/src/test/py/bazel/py_test.py index 6158b17b191a7e..83e45a16d103f6 100644 --- a/src/test/py/bazel/py_test.py +++ b/src/test/py/bazel/py_test.py @@ -46,6 +46,9 @@ def createSimpleFiles(self): ]) def testSmoke(self): + if test_base.TestBase.IsDarwin(): + # Re-enable after fixing https://github.com/bazelbuild/bazel/issues/20660 + return self.createSimpleFiles() _, stdout, _ = self.RunBazel(['run', '//a:a']) self.assertIn('Hello, World', stdout) diff --git a/src/test/shell/bazel/android/DexFileSplitter_synthetic_classes_test.sh b/src/test/shell/bazel/android/DexFileSplitter_synthetic_classes_test.sh index 44c4a00020f2ee..95a4e0d83c835f 100755 --- a/src/test/shell/bazel/android/DexFileSplitter_synthetic_classes_test.sh +++ b/src/test/shell/bazel/android/DexFileSplitter_synthetic_classes_test.sh @@ -33,7 +33,7 @@ source "${CURRENT_DIR}/android_helper.sh" \ || { echo "android_helper.sh not found!" >&2; exit 1; } fail_if_no_android_sdk -resolve_android_toolchains "$1" +resolve_android_toolchains function create_test_app() { diff --git a/src/test/shell/bazel/android/aapt_integration_test.sh b/src/test/shell/bazel/android/aapt_integration_test.sh index 9fc17f76760701..9132f3b4f5b453 100755 --- a/src/test/shell/bazel/android/aapt_integration_test.sh +++ b/src/test/shell/bazel/android/aapt_integration_test.sh @@ -46,7 +46,7 @@ source "$(rlocation io_bazel/src/test/shell/integration_test_setup.sh)" \ # (bazelbuild/continuous-integration#578). add_to_bazelrc "build --incompatible_use_python_toolchains=false" -resolve_android_toolchains "$1" +resolve_android_toolchains function test_build_with_aapt2() { create_new_workspace diff --git a/src/test/shell/bazel/android/aar_integration_test.sh b/src/test/shell/bazel/android/aar_integration_test.sh index 31025bb9fd022e..e52bd77a53a83b 100755 --- a/src/test/shell/bazel/android/aar_integration_test.sh +++ b/src/test/shell/bazel/android/aar_integration_test.sh @@ -33,7 +33,7 @@ fail_if_no_android_sdk source "${CURRENT_DIR}/../../integration_test_setup.sh" \ || { echo "integration_test_setup.sh not found!" >&2; exit 1; } -resolve_android_toolchains "$1" +resolve_android_toolchains # Regression test for https://github.com/bazelbuild/bazel/issues/1928. function test_empty_tree_artifact_action_inputs_mount_empty_directories() { diff --git a/src/test/shell/bazel/android/aidl_integration_test.sh b/src/test/shell/bazel/android/aidl_integration_test.sh index 41ae3db3dbb46f..6a35a4827ee49b 100755 --- a/src/test/shell/bazel/android/aidl_integration_test.sh +++ b/src/test/shell/bazel/android/aidl_integration_test.sh @@ -32,7 +32,7 @@ fail_if_no_android_sdk source "$(rlocation io_bazel/src/test/shell/integration_test_setup.sh)" \ || { echo "integration_test_setup.sh not found!" >&2; exit 1; } -resolve_android_toolchains "$1" +resolve_android_toolchains function test_simple_idl_srcs() { create_new_workspace diff --git a/src/test/shell/bazel/android/android_helper.sh b/src/test/shell/bazel/android/android_helper.sh index 2cb7864a4c2867..7d6341a908c602 100755 --- a/src/test/shell/bazel/android/android_helper.sh +++ b/src/test/shell/bazel/android/android_helper.sh @@ -111,16 +111,9 @@ function setup_head_android_tools_if_exists() { # Resolves Android toolchains with platforms. function resolve_android_toolchains() { - if [[ "$1" = '--with_platforms' ]]; then - echo "This test uses platform-based Android toolchain resolution." - add_to_bazelrc "build --incompatible_enable_android_toolchain_resolution" - add_to_bazelrc "build --incompatible_enable_cc_toolchain_resolution" - add_to_bazelrc "build --android_platforms=//test_android_platforms:simple" - else - echo "This test uses legacy Android toolchains." - add_to_bazelrc "build --noincompatible_enable_android_toolchain_resolution" - add_to_bazelrc "build --noincompatible_enable_cc_toolchain_resolution" - fi + add_to_bazelrc "build --incompatible_enable_android_toolchain_resolution" + add_to_bazelrc "build --incompatible_enable_cc_toolchain_resolution" + add_to_bazelrc "build --android_platforms=//test_android_platforms:simple" } setup_head_android_tools_if_exists diff --git a/src/test/shell/bazel/android/android_instrumentation_test_integration_test.sh b/src/test/shell/bazel/android/android_instrumentation_test_integration_test.sh index c10c21d9051719..8d05fe96162449 100755 --- a/src/test/shell/bazel/android/android_instrumentation_test_integration_test.sh +++ b/src/test/shell/bazel/android/android_instrumentation_test_integration_test.sh @@ -34,7 +34,7 @@ source "${CURRENT_DIR}/../../integration_test_setup.sh" \ # (bazelbuild/continuous-integration#578). add_to_bazelrc "build --incompatible_use_python_toolchains=false" -resolve_android_toolchains "$1" +resolve_android_toolchains function setup_android_instrumentation_test_env() { mkdir -p java/com/bin/res/values diff --git a/src/test/shell/bazel/android/android_integration_test.sh b/src/test/shell/bazel/android/android_integration_test.sh index cd83c7e988dc3d..01b047a86a0d7e 100755 --- a/src/test/shell/bazel/android/android_integration_test.sh +++ b/src/test/shell/bazel/android/android_integration_test.sh @@ -33,7 +33,7 @@ fail_if_no_android_sdk source "${CURRENT_DIR}/../../integration_test_setup.sh" \ || { echo "integration_test_setup.sh not found!" >&2; exit 1; } -resolve_android_toolchains "$1" +resolve_android_toolchains function test_sdk_library_deps() { create_new_workspace @@ -212,7 +212,6 @@ android_binary( ) EOF cat > MODULE.bazel << 'EOF' -# Required for android_integration_test_with_platforms bazel_dep(name = "platforms", version = "0.0.7") EOF diff --git a/src/test/shell/bazel/android/android_local_test_integration_test.sh b/src/test/shell/bazel/android/android_local_test_integration_test.sh index 0c5cf553450e01..fb91c52ec895d3 100755 --- a/src/test/shell/bazel/android/android_local_test_integration_test.sh +++ b/src/test/shell/bazel/android/android_local_test_integration_test.sh @@ -34,7 +34,7 @@ fail_if_no_android_sdk source "${CURRENT_DIR}/../../integration_test_setup.sh" \ || { echo "integration_test_setup.sh not found!" >&2; exit 1; } -resolve_android_toolchains "$1" +resolve_android_toolchains function setup_android_local_test_env() { mkdir -p java/com/bin/res/values diff --git a/src/test/shell/bazel/android/android_ndk_integration_test.sh b/src/test/shell/bazel/android/android_ndk_integration_test.sh index 15f25906c7bad5..6eda46cbfac091 100755 --- a/src/test/shell/bazel/android/android_ndk_integration_test.sh +++ b/src/test/shell/bazel/android/android_ndk_integration_test.sh @@ -38,7 +38,7 @@ fail_if_no_android_ndk source "${CURRENT_DIR}/../../integration_test_setup.sh" \ || { echo "integration_test_setup.sh not found!" >&2; exit 1; } -resolve_android_toolchains $1 +resolve_android_toolchains function create_android_binary() { mkdir -p java/bazel diff --git a/src/test/shell/bazel/android/android_sdk_integration_test.sh b/src/test/shell/bazel/android/android_sdk_integration_test.sh index 3b8326808d761e..2e44190195970d 100755 --- a/src/test/shell/bazel/android/android_sdk_integration_test.sh +++ b/src/test/shell/bazel/android/android_sdk_integration_test.sh @@ -33,7 +33,7 @@ fail_if_no_android_sdk source "${CURRENT_DIR}/../../integration_test_setup.sh" \ || { echo "integration_test_setup.sh not found!" >&2; exit 1; } -resolve_android_toolchains "$1" +resolve_android_toolchains function test_android_sdk_repository_path_from_environment() { create_new_workspace diff --git a/src/test/shell/bazel/android/android_sh_test.bzl b/src/test/shell/bazel/android/android_sh_test.bzl index 426fc9c278bfd0..663890692d782a 100644 --- a/src/test/shell/bazel/android/android_sh_test.bzl +++ b/src/test/shell/bazel/android/android_sh_test.bzl @@ -30,7 +30,7 @@ CHECK_FOR_ANDROID_SDK = select( ) def android_sh_test(create_test_with_released_tools = True, **kwargs): - """Creates versions of the test with and without platforms and head android tools. + """Creates versions of the test with and without head android tools. Args: create_test_with_released_tools: Whether to create a version of the test with the released @@ -47,24 +47,14 @@ def android_sh_test(create_test_with_released_tools = True, **kwargs): # Test with released android_tools version. native.sh_test( name = name, - args = ["--without_platforms"], data = data, **kwargs ) - # Test with platform-based toolchain resolution. - native.sh_test( - name = name + "_with_platforms", - data = data, - args = ["--with_platforms"], - **kwargs - ) - # Test with android_tools version that's built at the same revision # as the test itself. native.sh_test( name = name + "_with_head_android_tools", - args = ["--without_platforms"], data = data + [ "//tools/android/runtime_deps:android_tools.tar", ], diff --git a/src/test/shell/bazel/android/desugarer_integration_test.sh b/src/test/shell/bazel/android/desugarer_integration_test.sh index fa25ace0938de3..87ded51a950e5a 100755 --- a/src/test/shell/bazel/android/desugarer_integration_test.sh +++ b/src/test/shell/bazel/android/desugarer_integration_test.sh @@ -38,7 +38,7 @@ fail_if_no_android_sdk source "$(rlocation io_bazel/src/test/shell/integration_test_setup.sh)" \ || { echo "integration_test_setup.sh not found!" >&2; exit 1; } -resolve_android_toolchains "$1" +resolve_android_toolchains function create_java_8_android_binary() { mkdir -p java/bazel diff --git a/src/test/shell/bazel/android/library_desugarer_integration_test.sh b/src/test/shell/bazel/android/library_desugarer_integration_test.sh index ce8bfcad33e74c..b8b5000066d35d 100755 --- a/src/test/shell/bazel/android/library_desugarer_integration_test.sh +++ b/src/test/shell/bazel/android/library_desugarer_integration_test.sh @@ -38,7 +38,7 @@ fail_if_no_android_sdk source "$(rlocation io_bazel/src/test/shell/integration_test_setup.sh)" \ || { echo "integration_test_setup.sh not found!" >&2; exit 1; } -resolve_android_toolchains "$1" +resolve_android_toolchains function test_library_desugar_lib_builds() { # TODO(b/299338002): Move this to the main desugarer test suite. diff --git a/src/test/shell/bazel/android/proguard_integration_test.sh b/src/test/shell/bazel/android/proguard_integration_test.sh index 8a322e3aa7bd47..869589de67919a 100755 --- a/src/test/shell/bazel/android/proguard_integration_test.sh +++ b/src/test/shell/bazel/android/proguard_integration_test.sh @@ -38,7 +38,7 @@ fail_if_no_android_sdk source "$(rlocation io_bazel/src/test/shell/integration_test_setup.sh)" \ || { echo "integration_test_setup.sh not found!" >&2; exit 1; } -resolve_android_toolchains "$1" +resolve_android_toolchains function test_proguard() { create_new_workspace diff --git a/src/test/shell/bazel/android/resource_processing_integration_test.sh b/src/test/shell/bazel/android/resource_processing_integration_test.sh index 18fef259b8e456..d4d2f08144b2f5 100755 --- a/src/test/shell/bazel/android/resource_processing_integration_test.sh +++ b/src/test/shell/bazel/android/resource_processing_integration_test.sh @@ -38,7 +38,7 @@ fail_if_no_android_sdk source "$(rlocation io_bazel/src/test/shell/integration_test_setup.sh)" \ || { echo "integration_test_setup.sh not found!" >&2; exit 1; } -resolve_android_toolchains "$1" +resolve_android_toolchains function setup_font_resources() { rm java/bazel/BUILD diff --git a/src/test/shell/bazel/jdeps_test.sh b/src/test/shell/bazel/jdeps_test.sh index 98513409df9929..2776ebee9c4c88 100755 --- a/src/test/shell/bazel/jdeps_test.sh +++ b/src/test/shell/bazel/jdeps_test.sh @@ -72,7 +72,7 @@ function test_jdeps() { # src/test/shell/bazel/jdeps_class_denylist.txt. find . -type f -iname \*class | \ grep -vFf "$denylist" | \ - xargs ../jdk/reduced/bin/jdeps --list-reduced-deps --ignore-missing-deps | \ + xargs -s 262144 ../jdk/reduced/bin/jdeps --list-reduced-deps --ignore-missing-deps | \ grep -v "unnamed module" > ../jdeps \ || fail "Failed to run jdeps on non denylisted class files." cd .. diff --git a/src/test/shell/integration/minimal_jdk_test.sh b/src/test/shell/integration/minimal_jdk_test.sh index 82f40fd9e63a94..dad2abe4aa6e64 100755 --- a/src/test/shell/integration/minimal_jdk_test.sh +++ b/src/test/shell/integration/minimal_jdk_test.sh @@ -42,13 +42,13 @@ export BAZEL_SUFFIX="_jdk_minimal" source "$(rlocation "io_bazel/src/test/shell/integration_test_setup.sh")" \ || { echo "integration_test_setup.sh not found!" >&2; exit 1; } -# Bazel's install base is < 370MB with minimal JDK and > 370MB with an all +# Bazel's install base is < 450MB with minimal JDK and > 450MB with an all # modules JDK. -function test_size_less_than_370MB() { +function test_size_less_than_450MB() { bazel info ib=$(bazel info install_base) size=$(du -s "$ib" | cut -d\ -f1) - maxsize=$((1024*370)) + maxsize=$((1024*450)) if [ $size -gt $maxsize ]; then echo "$ib was too big:" 1>&2 du -a "$ib" 1>&2