Search in sources :

Example 1 with SubincludePreprocessor

use of com.google.devtools.build.lib.packages.util.SubincludePreprocessor in project bazel by bazelbuild.

the class SkyframeLabelVisitorTest method testSubpackageBoundarySubincludes.

// Regression test for: "package loading ignores subincludes for purposes of checking for
// subpackages cutting of labels"
//
// Indirectly tests that there are dependencies between a package and other packages that could
// potentially cutoff its subincludes.
@Test
public void testSubpackageBoundarySubincludes() throws Exception {
    // This test uses the python preprocessor.
    preprocessorFactorySupplier.inject(new SubincludePreprocessor(scratch.getFileSystem(), getSkyframeExecutor().getPackageManager()));
    PackageCacheOptions packageCacheOptions = Options.getDefaults(PackageCacheOptions.class);
    packageCacheOptions.defaultVisibility = ConstantRuleVisibility.PRIVATE;
    packageCacheOptions.showLoadingProgress = true;
    packageCacheOptions.globbingThreads = 7;
    getSkyframeExecutor().preparePackageLoading(new PathPackageLocator(outputBase, ImmutableList.of(rootDirectory)), packageCacheOptions, loadingMock.getDefaultsPackageContent(), UUID.randomUUID(), ImmutableMap.<String, String>of(), ImmutableMap.<String, String>of(), new TimestampGranularityMonitor(BlazeClock.instance()));
    this.visitor = getSkyframeExecutor().pkgLoader();
    scratch.file("a/BUILD", "subinclude('//b:c/d/foo')");
    scratch.file("b/BUILD", "exports_files(['c/d/foo'])");
    scratch.file("b/c/d/foo", "sh_library(name = 'a')");
    assertLabelsVisited(ImmutableSet.of("//a:a"), ImmutableSet.of("//a:a"), !EXPECT_ERROR, !KEEP_GOING);
    Path subpackageBuildFile = scratch.file("b/c/BUILD", "exports_files(['foo'])");
    syncPackages(ModifiedFileSet.builder().modify(new PathFragment("b/c/BUILD")).build());
    // expect errors
    reporter.removeHandler(failFastHandler);
    assertLabelsVisitedWithErrors(ImmutableSet.of("//a:a"), ImmutableSet.of("//a:a"));
    assertContainsEvent("Label '//b:c/d/foo' crosses boundary of subpackage 'b/c'");
    subpackageBuildFile.delete();
    syncPackages(ModifiedFileSet.builder().modify(new PathFragment("b/c/BUILD")).build());
    assertLabelsVisited(ImmutableSet.of("//a:a"), ImmutableSet.of("//a:a"), !EXPECT_ERROR, !KEEP_GOING);
}
Also used : PathPackageLocator(com.google.devtools.build.lib.pkgcache.PathPackageLocator) Path(com.google.devtools.build.lib.vfs.Path) SubincludePreprocessor(com.google.devtools.build.lib.packages.util.SubincludePreprocessor) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) PackageCacheOptions(com.google.devtools.build.lib.pkgcache.PackageCacheOptions) TimestampGranularityMonitor(com.google.devtools.build.lib.util.io.TimestampGranularityMonitor) Test(org.junit.Test)

Example 2 with SubincludePreprocessor

use of com.google.devtools.build.lib.packages.util.SubincludePreprocessor in project bazel by bazelbuild.

the class SkyframeLabelVisitorTest method testWithNoSubincludes.

@Test
public void testWithNoSubincludes() throws Exception {
    // This test uses the preprocessor.
    preprocessorFactorySupplier.inject(new SubincludePreprocessor(scratch.getFileSystem(), getSkyframeExecutor().getPackageManager()));
    PackageCacheOptions packageCacheOptions = Options.getDefaults(PackageCacheOptions.class);
    packageCacheOptions.defaultVisibility = ConstantRuleVisibility.PRIVATE;
    packageCacheOptions.showLoadingProgress = true;
    packageCacheOptions.globbingThreads = 7;
    getSkyframeExecutor().preparePackageLoading(new PathPackageLocator(outputBase, ImmutableList.of(rootDirectory)), packageCacheOptions, loadingMock.getDefaultsPackageContent(), UUID.randomUUID(), ImmutableMap.<String, String>of(), ImmutableMap.<String, String>of(), new TimestampGranularityMonitor(BlazeClock.instance()));
    this.visitor = getSkyframeExecutor().pkgLoader();
    scratch.file("pkg/BUILD", "sh_library(name = 'x', deps = ['z'])", "sh_library(name = 'z')");
    assertLabelsVisited(ImmutableSet.of("//pkg:x", "//pkg:z"), ImmutableSet.of("//pkg:x"), !EXPECT_ERROR, !KEEP_GOING);
    assertLabelsVisited(ImmutableSet.of("//pkg:x", "//pkg:z"), ImmutableSet.of("//pkg:x"), !EXPECT_ERROR, !KEEP_GOING);
    scratch.file("hassub/BUILD", "subinclude('//sub:sub')");
    scratch.file("sub/BUILD", "exports_files(['sub'])");
    scratch.file("sub/sub", "sh_library(name='zzz')");
    assertLabelsVisited(ImmutableSet.of("//hassub:zzz"), ImmutableSet.of("//hassub:zzz"), !EXPECT_ERROR, !KEEP_GOING);
}
Also used : PathPackageLocator(com.google.devtools.build.lib.pkgcache.PathPackageLocator) SubincludePreprocessor(com.google.devtools.build.lib.packages.util.SubincludePreprocessor) PackageCacheOptions(com.google.devtools.build.lib.pkgcache.PackageCacheOptions) TimestampGranularityMonitor(com.google.devtools.build.lib.util.io.TimestampGranularityMonitor) Test(org.junit.Test)

Example 3 with SubincludePreprocessor

use of com.google.devtools.build.lib.packages.util.SubincludePreprocessor in project bazel by bazelbuild.

the class SubincludePreprocessorTest method createPreprocessor.

@Before
public final void createPreprocessor() throws Exception {
    preprocessor = new SubincludePreprocessor(scratch.getFileSystem(), getPackageManager());
    packageRoot = rootDirectory.getChild("preprocessing");
    assertTrue(packageRoot.createDirectory());
    reporter.removeHandler(failFastHandler);
}
Also used : SubincludePreprocessor(com.google.devtools.build.lib.packages.util.SubincludePreprocessor) Before(org.junit.Before)

Aggregations

SubincludePreprocessor (com.google.devtools.build.lib.packages.util.SubincludePreprocessor)3 PackageCacheOptions (com.google.devtools.build.lib.pkgcache.PackageCacheOptions)2 PathPackageLocator (com.google.devtools.build.lib.pkgcache.PathPackageLocator)2 TimestampGranularityMonitor (com.google.devtools.build.lib.util.io.TimestampGranularityMonitor)2 Test (org.junit.Test)2 Path (com.google.devtools.build.lib.vfs.Path)1 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)1 Before (org.junit.Before)1