diff options
Diffstat (limited to 'src/test/java/com/google/devtools')
25 files changed, 95 insertions, 404 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/BUILD b/src/test/java/com/google/devtools/build/lib/BUILD index adcbbf9d56..302276a94f 100644 --- a/src/test/java/com/google/devtools/build/lib/BUILD +++ b/src/test/java/com/google/devtools/build/lib/BUILD @@ -64,7 +64,6 @@ java_library( srcs = glob(["testutil/*.java"]), visibility = ["//visibility:public"], deps = [ - "//src/main/java/com/google/devtools/build/lib:BazelPackageLoader", "//src/main/java/com/google/devtools/build/lib:bazel-main", "//src/main/java/com/google/devtools/build/lib:bazel-rules", "//src/main/java/com/google/devtools/build/lib:build-base", @@ -340,7 +339,6 @@ java_library( ":foundations_testutil", ":packages_testutil", ":testutil", - "//src/main/java/com/google/devtools/build/lib:BazelPackageLoader", "//src/main/java/com/google/devtools/build/lib:android-rules", "//src/main/java/com/google/devtools/build/lib:bazel-main", "//src/main/java/com/google/devtools/build/lib:bazel-rules", @@ -583,7 +581,6 @@ java_library( ":foundations_testutil", ":testutil", "//src/main/java/com/google/devtools/build/docgen:docgen_javalib", - "//src/main/java/com/google/devtools/build/lib:BazelPackageLoader", "//src/main/java/com/google/devtools/build/lib:bazel-main", "//src/main/java/com/google/devtools/build/lib:bazel-rules", "//src/main/java/com/google/devtools/build/lib:build-base", diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisMock.java b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisMock.java index 70e3ef0d01..57a6ac45db 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisMock.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisMock.java @@ -24,6 +24,7 @@ import com.google.devtools.build.lib.bazel.rules.android.AndroidNdkRepositoryRul import com.google.devtools.build.lib.bazel.rules.android.AndroidSdkRepositoryFunction; import com.google.devtools.build.lib.bazel.rules.android.AndroidSdkRepositoryRule; import com.google.devtools.build.lib.flags.InvocationPolicyEnforcer; +import com.google.devtools.build.lib.packages.PackageFactory; import com.google.devtools.build.lib.packages.util.LoadingMock; import com.google.devtools.build.lib.packages.util.MockCcSupport; import com.google.devtools.build.lib.packages.util.MockToolsConfig; @@ -33,11 +34,11 @@ import com.google.devtools.build.lib.rules.repository.RepositoryDelegatorFunctio import com.google.devtools.build.lib.rules.repository.RepositoryFunction; import com.google.devtools.build.lib.rules.repository.RepositoryLoaderFunction; import com.google.devtools.build.lib.skyframe.SkyFunctions; -import com.google.devtools.build.lib.skyframe.packages.PackageFactoryBuilderWithSkyframeForTesting; import com.google.devtools.build.lib.testutil.TestConstants; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.skyframe.SkyFunction; import com.google.devtools.build.skyframe.SkyFunctionName; + import java.io.IOException; import java.lang.reflect.Field; import java.util.Collection; @@ -67,8 +68,8 @@ public abstract class AnalysisMock extends LoadingMock { } @Override - public PackageFactoryBuilderWithSkyframeForTesting getPackageFactoryBuilderForTesting() { - return super.getPackageFactoryBuilderForTesting().setExtraSkyFunctions(getSkyFunctions()); + public PackageFactory.FactoryForTesting getPackageFactoryForTesting() { + return TestConstants.PACKAGE_FACTORY_FACTORY_FOR_TESTING; } @Override diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java index 977439a6a8..a7ddfa9228 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java @@ -166,8 +166,8 @@ public abstract class AnalysisTestCase extends FoundationTestCase { this.ruleClassProvider = ruleClassProvider; PackageFactory pkgFactory = analysisMock - .getPackageFactoryBuilderForTesting() - .build(ruleClassProvider, scratch.getFileSystem()); + .getPackageFactoryForTesting() + .create(ruleClassProvider, scratch.getFileSystem()); BinTools binTools = BinTools.forUnitTesting(directories, analysisMock.getEmbeddedTools()); skyframeExecutor = SequencedSkyframeExecutor.create( 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 3dddeb1b6d..4c698ee8bb 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 @@ -214,17 +214,14 @@ public abstract class BuildViewTestCase extends FoundationTestCase { configurationFactory = analysisMock.createConfigurationFactory(ruleClassProvider.getConfigurationFragments()); - ImmutableList<PrecomputedValue.Injected> extraPrecomputedValues = ImmutableList.of( - PrecomputedValue.injected( - RepositoryDelegatorFunction.REPOSITORY_OVERRIDES, - ImmutableMap.<RepositoryName, PathFragment>of())); pkgFactory = analysisMock - .getPackageFactoryBuilderForTesting() - .setExtraPrecomputeValues(extraPrecomputedValues) - .setEnvironmentExtensions(getEnvironmentExtensions()) - .setPlatformSetRegexps(getPlatformSetRegexps()) - .build(ruleClassProvider, scratch.getFileSystem()); + .getPackageFactoryForTesting() + .create( + ruleClassProvider, + getPlatformSetRegexps(), + getEnvironmentExtensions(), + scratch.getFileSystem()); tsgm = new TimestampGranularityMonitor(BlazeClock.instance()); skyframeExecutor = SequencedSkyframeExecutor.create( @@ -241,7 +238,9 @@ public abstract class BuildViewTestCase extends FoundationTestCase { analysisMock.getProductName(), CrossRepositoryLabelViolationStrategy.ERROR, ImmutableList.of(BuildFileName.BUILD_DOT_BAZEL, BuildFileName.BUILD)); - skyframeExecutor.injectExtraPrecomputedValues(extraPrecomputedValues); + skyframeExecutor.injectExtraPrecomputedValues(ImmutableList.of(PrecomputedValue.injected( + RepositoryDelegatorFunction.REPOSITORY_OVERRIDES, + ImmutableMap.<RepositoryName, PathFragment>of()))); packageCacheOptions.defaultVisibility = ConstantRuleVisibility.PUBLIC; packageCacheOptions.showLoadingProgress = true; packageCacheOptions.globbingThreads = 7; diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/ConfigurationTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/util/ConfigurationTestCase.java index 0f61da4431..9cfc8fd9b2 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/util/ConfigurationTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/util/ConfigurationTestCase.java @@ -98,8 +98,8 @@ public abstract class ConfigurationTestCase extends FoundationTestCase { new BlazeDirectories(outputBase, outputBase, rootDirectory, analysisMock.getProductName()); pkgFactory = analysisMock - .getPackageFactoryBuilderForTesting() - .build(ruleClassProvider, scratch.getFileSystem()); + .getPackageFactoryForTesting() + .create(ruleClassProvider, scratch.getFileSystem()); AnalysisTestUtil.DummyWorkspaceStatusActionFactory workspaceStatusActionFactory = new AnalysisTestUtil.DummyWorkspaceStatusActionFactory(directories); diff --git a/src/test/java/com/google/devtools/build/lib/packages/util/LoadingMock.java b/src/test/java/com/google/devtools/build/lib/packages/util/LoadingMock.java index 217c37565d..f08e502b21 100644 --- a/src/test/java/com/google/devtools/build/lib/packages/util/LoadingMock.java +++ b/src/test/java/com/google/devtools/build/lib/packages/util/LoadingMock.java @@ -15,7 +15,7 @@ package com.google.devtools.build.lib.packages.util; import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider; import com.google.devtools.build.lib.flags.InvocationPolicyEnforcer; -import com.google.devtools.build.lib.skyframe.packages.PackageFactoryBuilderWithSkyframeForTesting; +import com.google.devtools.build.lib.packages.PackageFactory; import com.google.devtools.build.lib.testutil.TestConstants; import com.google.devtools.build.lib.testutil.TestRuleClassProvider; @@ -29,9 +29,8 @@ public class LoadingMock { return TestConstants.PRODUCT_NAME; } - public PackageFactoryBuilderWithSkyframeForTesting getPackageFactoryBuilderForTesting() { - return (PackageFactoryBuilderWithSkyframeForTesting) - TestConstants.PACKAGE_FACTORY_BUILDER_FACTORY_FOR_TESTING.builder(); + public PackageFactory.FactoryForTesting getPackageFactoryForTesting() { + return TestConstants.PACKAGE_FACTORY_FACTORY_FOR_TESTING; } public ConfiguredRuleClassProvider createRuleClassProvider() { diff --git a/src/test/java/com/google/devtools/build/lib/packages/util/PackageLoadingTestCase.java b/src/test/java/com/google/devtools/build/lib/packages/util/PackageLoadingTestCase.java index 3ebda8ea71..975160dc0d 100644 --- a/src/test/java/com/google/devtools/build/lib/packages/util/PackageLoadingTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/packages/util/PackageLoadingTestCase.java @@ -90,9 +90,8 @@ public abstract class PackageLoadingTestCase extends FoundationTestCase { } packageFactory = loadingMock - .getPackageFactoryBuilderForTesting() - .setEnvironmentExtensions(getEnvironmentExtensions()) - .build(ruleClassProvider, scratch.getFileSystem()); + .getPackageFactoryForTesting() + .create(ruleClassProvider, null, getEnvironmentExtensions(), scratch.getFileSystem()); skyframeExecutor = createSkyframeExecutor(); setUpSkyframe(); } diff --git a/src/test/java/com/google/devtools/build/lib/pkgcache/IncrementalLoadingTest.java b/src/test/java/com/google/devtools/build/lib/pkgcache/IncrementalLoadingTest.java index def12d9fc0..8e57f6c5d8 100644 --- a/src/test/java/com/google/devtools/build/lib/pkgcache/IncrementalLoadingTest.java +++ b/src/test/java/com/google/devtools/build/lib/pkgcache/IncrementalLoadingTest.java @@ -468,8 +468,8 @@ public class IncrementalLoadingTest { skyframeExecutor = SequencedSkyframeExecutor.create( loadingMock - .getPackageFactoryBuilderForTesting() - .build(loadingMock.createRuleClassProvider(), fs), + .getPackageFactoryForTesting() + .create(loadingMock.createRuleClassProvider(), fs), new BlazeDirectories( fs.getPath("/install"), fs.getPath("/output"), diff --git a/src/test/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunnerTest.java b/src/test/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunnerTest.java index eb114ea224..9de3dec925 100644 --- a/src/test/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunnerTest.java +++ b/src/test/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunnerTest.java @@ -604,7 +604,7 @@ public class LoadingPhaseRunnerTest { ConfiguredRuleClassProvider ruleClassProvider = analysisMock.createRuleClassProvider(); PackageFactory pkgFactory = - analysisMock.getPackageFactoryBuilderForTesting().build(ruleClassProvider, fs); + analysisMock.getPackageFactoryForTesting().create(ruleClassProvider, fs); PackageCacheOptions options = Options.getDefaults(PackageCacheOptions.class); storedErrors = new StoredEventHandler(); BlazeDirectories directories = diff --git a/src/test/java/com/google/devtools/build/lib/pkgcache/PackageCacheTest.java b/src/test/java/com/google/devtools/build/lib/pkgcache/PackageCacheTest.java index 3161f71c8d..165db96d5c 100644 --- a/src/test/java/com/google/devtools/build/lib/pkgcache/PackageCacheTest.java +++ b/src/test/java/com/google/devtools/build/lib/pkgcache/PackageCacheTest.java @@ -37,7 +37,6 @@ import com.google.devtools.build.lib.packages.BuildFileContainsErrorsException; import com.google.devtools.build.lib.packages.NoSuchPackageException; import com.google.devtools.build.lib.packages.NoSuchTargetException; import com.google.devtools.build.lib.packages.Package; -import com.google.devtools.build.lib.packages.PackageFactory; import com.google.devtools.build.lib.packages.Rule; import com.google.devtools.build.lib.packages.Target; import com.google.devtools.build.lib.skyframe.DiffAwareness; @@ -78,22 +77,15 @@ public class PackageCacheTest extends FoundationTestCase { @Before public final void initializeSkyframeExecutor() throws Exception { - initializeSkyframeExecutor(/*doPackageLoadingChecks=*/ true); - } - - private void initializeSkyframeExecutor(boolean doPackageLoadingChecks) throws Exception { analysisMock = AnalysisMock.get(); ruleClassProvider = analysisMock.createRuleClassProvider(); BlazeDirectories directories = new BlazeDirectories(outputBase, outputBase, rootDirectory, analysisMock.getProductName()); - PackageFactory.BuilderForTesting packageFactoryBuilder = - analysisMock.getPackageFactoryBuilderForTesting(); - if (!doPackageLoadingChecks) { - packageFactoryBuilder.disableChecks(); - } skyframeExecutor = SequencedSkyframeExecutor.create( - packageFactoryBuilder.build(ruleClassProvider, scratch.getFileSystem()), + analysisMock + .getPackageFactoryForTesting() + .create(ruleClassProvider, scratch.getFileSystem()), directories, null, /* BinTools */ null, /* workspaceStatusActionFactory */ @@ -549,8 +541,6 @@ public class PackageCacheTest extends FoundationTestCase { @Test public void testDeletedPackages() throws Exception { - // PackageLoader doesn't support --deleted_packages. - initializeSkyframeExecutor(/*doPackageLoadingChecks=*/ false); reporter.removeHandler(failFastHandler); setUpCacheWithTwoRootLocator(); createBuildFile(rootDir1, "c", "d/x"); diff --git a/src/test/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorTest.java b/src/test/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorTest.java index 849a3b712d..449cf0ca11 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorTest.java @@ -106,7 +106,7 @@ public class RepositoryDelegatorTest extends FoundationTestCase { SkyFunctions.WORKSPACE_FILE, new WorkspaceFileFunction( TestRuleClassProvider.getRuleClassProvider(), - TestConstants.PACKAGE_FACTORY_BUILDER_FACTORY_FOR_TESTING.builder().build( + TestConstants.PACKAGE_FACTORY_FACTORY_FOR_TESTING.create( TestRuleClassProvider.getRuleClassProvider(), root.getFileSystem()), directories)) .put(SkyFunctions.LOCAL_REPOSITORY_LOOKUP, new LocalRepositoryLookupFunction()) diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTestCase.java b/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTestCase.java index c01285e969..491ecc14d1 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTestCase.java @@ -108,7 +108,7 @@ abstract class ArtifactFunctionTestCase { SkyFunctions.WORKSPACE_FILE, new WorkspaceFileFunction( TestRuleClassProvider.getRuleClassProvider(), - TestConstants.PACKAGE_FACTORY_BUILDER_FACTORY_FOR_TESTING.builder().build( + TestConstants.PACKAGE_FACTORY_FACTORY_FOR_TESTING.create( TestRuleClassProvider.getRuleClassProvider(), root.getFileSystem()), directories)) .put(SkyFunctions.EXTERNAL_PACKAGE, new ExternalPackageFunction()) diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java index 3ac748efc6..830b91c786 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java @@ -157,7 +157,7 @@ public class FileFunctionTest { SkyFunctions.WORKSPACE_FILE, new WorkspaceFileFunction( TestRuleClassProvider.getRuleClassProvider(), - TestConstants.PACKAGE_FACTORY_BUILDER_FACTORY_FOR_TESTING.builder().build( + TestConstants.PACKAGE_FACTORY_FACTORY_FOR_TESTING.create( TestRuleClassProvider.getRuleClassProvider(), fs), directories)) .put(SkyFunctions.EXTERNAL_PACKAGE, new ExternalPackageFunction()) diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/FilesystemValueCheckerTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/FilesystemValueCheckerTest.java index 74e7c776e5..2c92706a7a 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/FilesystemValueCheckerTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/FilesystemValueCheckerTest.java @@ -128,7 +128,7 @@ public class FilesystemValueCheckerTest { new WorkspaceASTFunction(TestRuleClassProvider.getRuleClassProvider())); skyFunctions.put(SkyFunctions.WORKSPACE_FILE, new WorkspaceFileFunction(TestRuleClassProvider.getRuleClassProvider(), - TestConstants.PACKAGE_FACTORY_BUILDER_FACTORY_FOR_TESTING.builder().build( + TestConstants.PACKAGE_FACTORY_FACTORY_FOR_TESTING.create( TestRuleClassProvider.getRuleClassProvider(), fs), directories)); skyFunctions.put(SkyFunctions.EXTERNAL_PACKAGE, new ExternalPackageFunction()); diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupFunctionTest.java index c8c5bae031..a2d51781c3 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupFunctionTest.java @@ -24,7 +24,6 @@ import com.google.devtools.build.lib.cmdline.PackageIdentifier; import com.google.devtools.build.lib.cmdline.RepositoryName; import com.google.devtools.build.lib.events.NullEventHandler; import com.google.devtools.build.lib.packages.PackageFactory; -import com.google.devtools.build.lib.packages.PackageFactory.EnvironmentExtension; import com.google.devtools.build.lib.packages.RuleClassProvider; import com.google.devtools.build.lib.pkgcache.PathPackageLocator; import com.google.devtools.build.lib.skyframe.ExternalFilesHelper.ExternalFileAction; @@ -95,12 +94,10 @@ public class LocalRepositoryLookupFunctionTest extends FoundationTestCase { new WorkspaceFileFunction( ruleClassProvider, analysisMock - .getPackageFactoryBuilderForTesting() - .setEnvironmentExtensions( - ImmutableList.<EnvironmentExtension>of( - new PackageFactory.EmptyEnvironmentExtension())) - .build( + .getPackageFactoryForTesting() + .create( ruleClassProvider, + new PackageFactory.EmptyEnvironmentExtension(), scratch.getFileSystem()), directories)); skyFunctions.put(SkyFunctions.EXTERNAL_PACKAGE, new ExternalPackageFunction()); diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/PackageLookupFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/PackageLookupFunctionTest.java index ff5b2bdeee..9fe08801d5 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/PackageLookupFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/PackageLookupFunctionTest.java @@ -31,7 +31,6 @@ import com.google.devtools.build.lib.cmdline.RepositoryName; import com.google.devtools.build.lib.events.NullEventHandler; import com.google.devtools.build.lib.packages.BuildFileNotFoundException; import com.google.devtools.build.lib.packages.PackageFactory; -import com.google.devtools.build.lib.packages.PackageFactory.EnvironmentExtension; import com.google.devtools.build.lib.packages.RuleClassProvider; import com.google.devtools.build.lib.pkgcache.PathPackageLocator; import com.google.devtools.build.lib.rules.repository.LocalRepositoryFunction; @@ -118,12 +117,10 @@ public abstract class PackageLookupFunctionTest extends FoundationTestCase { new WorkspaceFileFunction( ruleClassProvider, analysisMock - .getPackageFactoryBuilderForTesting() - .setEnvironmentExtensions( - ImmutableList.<EnvironmentExtension>of( - new PackageFactory.EmptyEnvironmentExtension())) - .build( + .getPackageFactoryForTesting() + .create( ruleClassProvider, + new PackageFactory.EmptyEnvironmentExtension(), scratch.getFileSystem()), directories)); skyFunctions.put(SkyFunctions.EXTERNAL_PACKAGE, new ExternalPackageFunction()); diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunctionTest.java index 1fed2177f3..229cbcfb48 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunctionTest.java @@ -120,8 +120,8 @@ public final class RecursiveFilesystemTraversalFunctionTest extends FoundationTe new WorkspaceFileFunction( ruleClassProvider, analysisMock - .getPackageFactoryBuilderForTesting() - .build(ruleClassProvider, scratch.getFileSystem()), + .getPackageFactoryForTesting() + .create(ruleClassProvider, scratch.getFileSystem()), directories)); skyFunctions.put(SkyFunctions.EXTERNAL_PACKAGE, new ExternalPackageFunction()); skyFunctions.put(SkyFunctions.LOCAL_REPOSITORY_LOOKUP, new LocalRepositoryLookupFunction()); diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/TimestampBuilderTestCase.java b/src/test/java/com/google/devtools/build/lib/skyframe/TimestampBuilderTestCase.java index 2104ec53dd..901fa9ffe9 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/TimestampBuilderTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/TimestampBuilderTestCase.java @@ -205,7 +205,7 @@ public abstract class TimestampBuilderTestCase extends FoundationTestCase { SkyFunctions.WORKSPACE_FILE, new WorkspaceFileFunction( TestRuleClassProvider.getRuleClassProvider(), - TestConstants.PACKAGE_FACTORY_BUILDER_FACTORY_FOR_TESTING.builder().build( + TestConstants.PACKAGE_FACTORY_FACTORY_FOR_TESTING.create( TestRuleClassProvider.getRuleClassProvider(), scratch.getFileSystem()), directories)) .put(SkyFunctions.EXTERNAL_PACKAGE, new ExternalPackageFunction()) diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/packages/AbstractPackageLoaderTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/packages/AbstractPackageLoaderTest.java deleted file mode 100644 index 40deb5089d..0000000000 --- a/src/test/java/com/google/devtools/build/lib/skyframe/packages/AbstractPackageLoaderTest.java +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright 2017 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. -package com.google.devtools.build.lib.skyframe.packages; - -import static com.google.common.truth.Truth.assertThat; -import static com.google.devtools.build.lib.testutil.MoreAsserts.assertContainsEvent; -import static com.google.devtools.build.lib.testutil.MoreAsserts.assertNoEvents; -import static org.junit.Assert.fail; - -import com.google.common.base.Joiner; -import com.google.common.eventbus.EventBus; -import com.google.devtools.build.lib.cmdline.PackageIdentifier; -import com.google.devtools.build.lib.events.Reporter; -import com.google.devtools.build.lib.events.StoredEventHandler; -import com.google.devtools.build.lib.packages.NoSuchPackageException; -import com.google.devtools.build.lib.packages.Package; -import com.google.devtools.build.lib.vfs.FileSystem; -import com.google.devtools.build.lib.vfs.FileSystemUtils; -import com.google.devtools.build.lib.vfs.Path; -import com.google.devtools.build.lib.vfs.PathFragment; -import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; -import org.junit.Before; -import org.junit.Test; - -/** Abstract base class of a unit test for a {@link AbstractPackageLoader} implementation. */ -public abstract class AbstractPackageLoaderTest { - private Path pkgRoot; - protected StoredEventHandler handler; - protected PackageLoader pkgLoader; - - @Before - public final void init() throws Exception { - FileSystem fs = new InMemoryFileSystem(); - pkgRoot = fs.getRootDirectory().getChild("pkgRoot"); - FileSystemUtils.createDirectoryAndParents(pkgRoot); - Reporter reporter = new Reporter(new EventBus()); - handler = new StoredEventHandler(); - reporter.addHandler(handler); - pkgLoader = makeFreshBuilder(pkgRoot).setReporter(reporter).build(); - } - - protected abstract AbstractPackageLoader.Builder makeFreshBuilder(Path pkgRoot); - - @Test - public void simpleNoPackage() throws Exception { - PackageIdentifier pkgId = PackageIdentifier.createInMainRepo(PathFragment.create("nope")); - try { - pkgLoader.loadPackage(pkgId); - fail(); - } catch (NoSuchPackageException expected) { - assertThat(expected) - .hasMessageThat() - .isEqualTo("no such package 'nope': BUILD file not found on package path"); - } - assertNoEvents(handler.getEvents()); - } - - @Test - public void simpleBadPackage() throws Exception { - file("bad/BUILD", "invalidBUILDsyntax"); - PackageIdentifier pkgId = PackageIdentifier.createInMainRepo(PathFragment.create("bad")); - Package badPkg = pkgLoader.loadPackage(pkgId); - assertThat(badPkg.containsErrors()).isTrue(); - assertContainsEvent(badPkg.getEvents(), "invalidBUILDsyntax"); - assertContainsEvent(handler.getEvents(), "invalidBUILDsyntax"); - } - - @Test - public void simpleGoodPackage() throws Exception { - file("good/BUILD", "sh_library(name = 'good')"); - PackageIdentifier pkgId = PackageIdentifier.createInMainRepo(PathFragment.create("good")); - Package goodPkg = pkgLoader.loadPackage(pkgId); - assertThat(goodPkg.containsErrors()).isFalse(); - assertThat( - goodPkg.getTarget("good").getAssociatedRule().getRuleClass()).isEqualTo("sh_library"); - assertNoEvents(goodPkg.getEvents()); - assertNoEvents(handler.getEvents()); - } - - @Test - public void simpleGoodPackage_Skylark() throws Exception { - file("good/good.bzl", - "def f(x):", - " native.sh_library(name = x)"); - file("good/BUILD", - "load('//good:good.bzl', 'f')", - "f('good')"); - PackageIdentifier pkgId = PackageIdentifier.createInMainRepo(PathFragment.create("good")); - Package goodPkg = pkgLoader.loadPackage(pkgId); - assertThat(goodPkg.containsErrors()).isFalse(); - assertThat( - goodPkg.getTarget("good").getAssociatedRule().getRuleClass()).isEqualTo("sh_library"); - assertNoEvents(goodPkg.getEvents()); - assertNoEvents(handler.getEvents()); - } - - protected Path path(String rootRelativePath) { - return pkgRoot.getRelative(PathFragment.create(rootRelativePath)); - } - - protected Path file(String fileName, String... contents) throws Exception { - Path path = path(fileName); - FileSystemUtils.createDirectoryAndParents(path.getParentDirectory()); - FileSystemUtils.writeContentAsLatin1(path, Joiner.on("\n").join(contents)); - return path; - } -} diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/packages/BUILD b/src/test/java/com/google/devtools/build/lib/skyframe/packages/BUILD deleted file mode 100644 index 89f75b39c4..0000000000 --- a/src/test/java/com/google/devtools/build/lib/skyframe/packages/BUILD +++ /dev/null @@ -1,25 +0,0 @@ -filegroup( - name = "srcs", - srcs = glob(["**"]), - visibility = ["//src/test/java/com/google/devtools/build/lib:__pkg__"], -) - -java_test( - name = "BazelPackageLoaderTest", - srcs = [ - "AbstractPackageLoaderTest.java", - "BazelPackageLoaderTest.java", - ], - deps = [ - "//src/main/java/com/google/devtools/build/lib:BazelPackageLoader", - "//src/main/java/com/google/devtools/build/lib:events", - "//src/main/java/com/google/devtools/build/lib:inmemoryfs", - "//src/main/java/com/google/devtools/build/lib:packages", - "//src/main/java/com/google/devtools/build/lib:vfs", - "//src/test/java/com/google/devtools/build/lib:testutil", - "//third_party:guava", - "//third_party:jsr305", - "//third_party:junit4", - "//third_party:truth", - ], -) diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/packages/BazelPackageLoaderTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/packages/BazelPackageLoaderTest.java deleted file mode 100644 index e6f6e4df2c..0000000000 --- a/src/test/java/com/google/devtools/build/lib/skyframe/packages/BazelPackageLoaderTest.java +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2017 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. -package com.google.devtools.build.lib.skyframe.packages; - -import com.google.devtools.build.lib.vfs.Path; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** - * Simple tests for {@link BazelPackageLoader}. - * - * <p>Bazel's unit and integration tests do sanity checks with {@link BazelPackageLoader} under the - * covers, so we get pretty exhaustive correctness tests for free. - */ -@RunWith(JUnit4.class) -public final class BazelPackageLoaderTest extends AbstractPackageLoaderTest { - @Override - protected BazelPackageLoader.Builder makeFreshBuilder(Path pkgRoot) { - return BazelPackageLoader.builder(pkgRoot); - } -} diff --git a/src/test/java/com/google/devtools/build/lib/testutil/BazelPackageBuilderHelperForTesting.java b/src/test/java/com/google/devtools/build/lib/testutil/BazelPackageBuilderHelperForTesting.java deleted file mode 100644 index 21f20cfb16..0000000000 --- a/src/test/java/com/google/devtools/build/lib/testutil/BazelPackageBuilderHelperForTesting.java +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright 2017 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. -package com.google.devtools.build.lib.testutil; - -import com.google.common.base.Function; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; -import com.google.common.collect.Sets; -import com.google.devtools.build.lib.cmdline.Label; -import com.google.devtools.build.lib.cmdline.PackageIdentifier; -import com.google.devtools.build.lib.packages.NoSuchPackageException; -import com.google.devtools.build.lib.packages.Package; -import com.google.devtools.build.lib.packages.RuleClassProvider; -import com.google.devtools.build.lib.packages.Target; -import com.google.devtools.build.lib.skyframe.PackageFunction; -import com.google.devtools.build.lib.skyframe.packages.BazelPackageLoader; -import com.google.devtools.build.lib.skyframe.packages.PackageLoader; -import com.google.devtools.build.lib.vfs.Path; -import com.google.devtools.build.lib.vfs.PathFragment; - -/** - * A Package.Builder.Helper for use in tests that a sanity check with {@link BazelPackageLoader} for - * each loaded package, for the sake of getting pretty nice test coverage. - */ -public class BazelPackageBuilderHelperForTesting implements Package.Builder.Helper { - private final RuleClassProvider ruleClassProvider; - - public BazelPackageBuilderHelperForTesting(RuleClassProvider ruleClassProvider) { - this.ruleClassProvider = ruleClassProvider; - } - - @Override - public Package createFreshPackage(PackageIdentifier packageId, String runfilesPrefix) { - return Package.Builder.DefaultHelper.INSTANCE.createFreshPackage(packageId, runfilesPrefix); - } - - @Override - public void onLoadingComplete(Package pkg) { - sanityCheckBazelPackageLoader(pkg, ruleClassProvider); - } - - private static final Function<Target, Label> TARGET_TO_LABEL = - new Function<Target, Label>() { - @Override - public Label apply(Target input) { - return input.getLabel(); - } - }; - - // This is synchronized because some Skylark internals aren't thread safe. - private synchronized void sanityCheckBazelPackageLoader( - Package pkg, - RuleClassProvider ruleClassProvider) { - PackageIdentifier pkgId = pkg.getPackageIdentifier(); - if (pkgId.equals(Label.EXTERNAL_PACKAGE_IDENTIFIER) - || !pkg.getPackageIdentifier().getRepository().isMain() - || PackageFunction.isDefaultsPackage(pkg.getPackageIdentifier())) { - // TODO(nharmata): Support these packages. - return; - } - int numNameSegments = pkg.getNameFragment().segmentCount(); - PathFragment fullFilenameFragment = pkg.getFilename().asFragment(); - int numFullFilenameFragmentSegments = fullFilenameFragment.segmentCount(); - Path workspaceRoot = pkg.getFilename().getFileSystem().getPath( - fullFilenameFragment.subFragment( - 0, - numFullFilenameFragmentSegments - (numNameSegments + 1))); - PackageLoader packageLoader = BazelPackageLoader.builder(workspaceRoot) - .setRuleClassProvider(ruleClassProvider) - .build(); - Package newlyLoadedPkg; - try { - newlyLoadedPkg = packageLoader.loadPackage(pkg.getPackageIdentifier()); - } catch (InterruptedException e) { - return; - } catch (NoSuchPackageException e) { - throw new IllegalStateException(e); - } - ImmutableSet<Label> targetsInPkg = - ImmutableSet.copyOf(Iterables.transform(pkg.getTargets(), TARGET_TO_LABEL)); - ImmutableSet<Label> targetsInNewlyLoadedPkg = - ImmutableSet.copyOf(Iterables.transform(newlyLoadedPkg.getTargets(), TARGET_TO_LABEL)); - if (!targetsInPkg.equals(targetsInNewlyLoadedPkg)) { - throw new IllegalStateException(String.format( - "The Package for %s had a different set of targets (<targetsInPkg> - " - + "<targetsInNewlyLoadedPkg> = %s, <targetsInNewlyLoadedPkg> - <targetsInPkg> = %s) when " - + "loaded normally during execution of the current test than it did when loaded via " - + "BazelPackageLoader (done automatically by the BazelPackageBuilderHelperForTesting " - + "hook). This either means: (i) Skyframe package loading semantics have diverged from " - + "BazelPackageLoader semantics (ii) The test in question is doing something that " - + "confuses BazelPackageBuilderHelperForTesting.", - pkgId, - Sets.difference(targetsInPkg, targetsInNewlyLoadedPkg), - Sets.difference(targetsInNewlyLoadedPkg, targetsInPkg))); - } - } -} diff --git a/src/test/java/com/google/devtools/build/lib/testutil/PackageFactoryBuilderFactoryForBazelUnitTests.java b/src/test/java/com/google/devtools/build/lib/testutil/PackageFactoryBuilderFactoryForBazelUnitTests.java deleted file mode 100644 index 04e8e03710..0000000000 --- a/src/test/java/com/google/devtools/build/lib/testutil/PackageFactoryBuilderFactoryForBazelUnitTests.java +++ /dev/null @@ -1,56 +0,0 @@ -// 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. -package com.google.devtools.build.lib.testutil; - -import com.google.devtools.build.lib.packages.Package; -import com.google.devtools.build.lib.packages.PackageFactory; -import com.google.devtools.build.lib.packages.RuleClassProvider; -import com.google.devtools.build.lib.skyframe.packages.PackageFactoryBuilderWithSkyframeForTesting; -import com.google.devtools.build.lib.vfs.FileSystem; - -/** - * A {@link PackageFactory.BuilderFactoryForTesting} implementation that injects a - * {@link BazelPackageBuilderHelperForTesting}. - */ -class PackageFactoryBuilderFactoryForBazelUnitTests - extends PackageFactory.BuilderFactoryForTesting { - static final PackageFactoryBuilderFactoryForBazelUnitTests INSTANCE = - new PackageFactoryBuilderFactoryForBazelUnitTests(); - - private PackageFactoryBuilderFactoryForBazelUnitTests() { - } - - @Override - public PackageFactoryBuilderWithSkyframeForTesting builder() { - return new PackageFactoryBuilderForBazelUnitTests(); - } - - private static class PackageFactoryBuilderForBazelUnitTests - extends PackageFactoryBuilderWithSkyframeForTesting { - @Override - public PackageFactory build(RuleClassProvider ruleClassProvider, FileSystem fs) { - Package.Builder.Helper packageBuilderHelperForTesting = doChecksForTesting - ? new BazelPackageBuilderHelperForTesting(ruleClassProvider) - : Package.Builder.DefaultHelper.INSTANCE; - return new PackageFactory( - ruleClassProvider, - platformSetRegexps, - attributeContainerFactory, - environmentExtensions, - version, - packageBuilderHelperForTesting); - } - } -} - diff --git a/src/test/java/com/google/devtools/build/lib/testutil/PackageFactoryFactoryForBazelUnitTests.java b/src/test/java/com/google/devtools/build/lib/testutil/PackageFactoryFactoryForBazelUnitTests.java new file mode 100644 index 0000000000..43dea593ab --- /dev/null +++ b/src/test/java/com/google/devtools/build/lib/testutil/PackageFactoryFactoryForBazelUnitTests.java @@ -0,0 +1,51 @@ +// 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. +package com.google.devtools.build.lib.testutil; + +import com.google.common.base.Function; +import com.google.devtools.build.lib.packages.AttributeContainer; +import com.google.devtools.build.lib.packages.Package; +import com.google.devtools.build.lib.packages.PackageFactory; +import com.google.devtools.build.lib.packages.PackageFactory.EnvironmentExtension; +import com.google.devtools.build.lib.packages.RuleClass; +import com.google.devtools.build.lib.packages.RuleClassProvider; +import com.google.devtools.build.lib.vfs.FileSystem; + +import java.util.Map; + +class PackageFactoryFactoryForBazelUnitTests extends PackageFactory.FactoryForTesting { + static final PackageFactoryFactoryForBazelUnitTests INSTANCE = + new PackageFactoryFactoryForBazelUnitTests(); + + private PackageFactoryFactoryForBazelUnitTests() { + } + + @Override + protected PackageFactory create( + RuleClassProvider ruleClassProvider, + Map<String, String> platformSetRegexps, + Function<RuleClass, AttributeContainer> attributeContainerFactory, + Iterable<EnvironmentExtension> environmentExtensions, + String version, + FileSystem fs) { + return new PackageFactory( + ruleClassProvider, + platformSetRegexps, + attributeContainerFactory, + environmentExtensions, + version, + Package.Builder.DefaultHelper.INSTANCE); + } +} + diff --git a/src/test/java/com/google/devtools/build/lib/testutil/TestConstants.java b/src/test/java/com/google/devtools/build/lib/testutil/TestConstants.java index 480a5d3cac..52cf1bac99 100644 --- a/src/test/java/com/google/devtools/build/lib/testutil/TestConstants.java +++ b/src/test/java/com/google/devtools/build/lib/testutil/TestConstants.java @@ -15,7 +15,7 @@ package com.google.devtools.build.lib.testutil; import com.google.common.collect.ImmutableList; -import com.google.devtools.build.lib.packages.PackageFactory.BuilderFactoryForTesting; +import com.google.devtools.build.lib.packages.PackageFactory; import com.google.devtools.build.lib.runtime.proto.InvocationPolicyOuterClass.InvocationPolicy; /** @@ -83,6 +83,6 @@ public class TestConstants { public static final InvocationPolicy TEST_INVOCATION_POLICY = InvocationPolicy.getDefaultInstance(); - public static final BuilderFactoryForTesting PACKAGE_FACTORY_BUILDER_FACTORY_FOR_TESTING = - PackageFactoryBuilderFactoryForBazelUnitTests.INSTANCE; + public static final PackageFactory.FactoryForTesting PACKAGE_FACTORY_FACTORY_FOR_TESTING = + PackageFactoryFactoryForBazelUnitTests.INSTANCE; } |