Search in sources :

Example 1 with GlobCache

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

the class PackageFactoryApparatus method evalAndReturnGlobCache.

/**
   * Evaluates the {@code buildFileAST} into a {@link Package}.
   */
public Pair<Package, GlobCache> evalAndReturnGlobCache(String packageName, Path buildFile, BuildFileAST buildFileAST) throws InterruptedException {
    PackageIdentifier packageId = PackageIdentifier.createInMainRepo(packageName);
    GlobCache globCache = new GlobCache(buildFile.getParentDirectory(), packageId, getPackageLocator(), null, TestUtils.getPool(), -1);
    LegacyGlobber globber = PackageFactory.createLegacyGlobber(globCache);
    Package externalPkg = factory.newExternalPackageBuilder(buildFile.getParentDirectory().getRelative("WORKSPACE"), "TESTING").build();
    Builder resultBuilder = factory.evaluateBuildFile(externalPkg.getWorkspaceName(), packageId, buildFileAST, buildFile, globber, ImmutableList.<Event>of(), ConstantRuleVisibility.PUBLIC, false, new MakeEnvironment.Builder(), ImmutableMap.<String, Extension>of(), ImmutableList.<Label>of());
    Package result = resultBuilder.build();
    Event.replayEventsOn(eventHandler, result.getEvents());
    return Pair.of(result, globCache);
}
Also used : PackageIdentifier(com.google.devtools.build.lib.cmdline.PackageIdentifier) LegacyGlobber(com.google.devtools.build.lib.packages.PackageFactory.LegacyGlobber) Builder(com.google.devtools.build.lib.packages.Package.Builder) MakeEnvironment(com.google.devtools.build.lib.packages.MakeEnvironment) Package(com.google.devtools.build.lib.packages.Package) GlobCache(com.google.devtools.build.lib.packages.GlobCache)

Example 2 with GlobCache

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

the class PackageFactoryTestBase method assertEvaluates.

protected static void assertEvaluates(Package pkg, List<String> expected, List<String> include, List<String> exclude) throws Exception {
    GlobCache globCache = new GlobCache(pkg.getFilename().getParentDirectory(), pkg.getPackageIdentifier(), PackageFactoryApparatus.createEmptyLocator(), null, TestUtils.getPool(), -1);
    assertThat(globCache.globUnsorted(include, exclude, false)).containsExactlyElementsIn(expected);
}
Also used : GlobCache(com.google.devtools.build.lib.packages.GlobCache)

Example 3 with GlobCache

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

the class PackageFactoryTestBase method assertGlobMatches.

/**
   * Test globbing in the context of a package, using the build language.
   * We use the specially setup "globs" test package and the files beneath it.
   * @param result the expected list of filenames that match the glob
   * @param includes an include pattern for the glob
   * @param excludes an exclude pattern for the glob
   * @param excludeDirs an exclude_directories flag for the glob
   * @throws Exception if the glob doesn't match the expected result.
   */
protected void assertGlobMatches(List<String> result, List<String> includes, List<String> excludes, boolean excludeDirs) throws Exception {
    // The BUILD language, unlike Skylark, doesn't have fail(), so instead,
    // we rely on boolean short circuit logic to only try to evaluate
    // the undefined identifier this_will_fail if the result isn't as expected,
    // in which case an error occurs (which we test in testGlobNegativeTest).
    Pair<Package, GlobCache> evaluated = evaluateGlob(includes, excludes, excludeDirs, Printer.format("(result == sorted(%r)) or this_will_fail()", result));
    Package pkg = evaluated.first;
    GlobCache globCache = evaluated.second;
    // Ensure all of the patterns are recorded against this package:
    assertTrue(globCache.getKeySet().containsAll(createGlobCacheKeys(includes, excludeDirs)));
    assertTrue(globCache.getKeySet().containsAll(createGlobCacheKeys(excludes, excludeDirs)));
    assertFalse(pkg.containsErrors());
}
Also used : Package(com.google.devtools.build.lib.packages.Package) GlobCache(com.google.devtools.build.lib.packages.GlobCache)

Aggregations

GlobCache (com.google.devtools.build.lib.packages.GlobCache)3 Package (com.google.devtools.build.lib.packages.Package)2 PackageIdentifier (com.google.devtools.build.lib.cmdline.PackageIdentifier)1 MakeEnvironment (com.google.devtools.build.lib.packages.MakeEnvironment)1 Builder (com.google.devtools.build.lib.packages.Package.Builder)1 LegacyGlobber (com.google.devtools.build.lib.packages.PackageFactory.LegacyGlobber)1