Search in sources :

Example 31 with Package

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

the class PackageCacheTest method testMovedBuildFileCausesReloadAfterSync.

@Test
public void testMovedBuildFileCausesReloadAfterSync() throws Exception {
    Path buildFile1 = scratch.file("pkg/BUILD", "cc_library(name = 'foo')");
    Path buildFile2 = scratch.file("/otherroot/pkg/BUILD", "cc_library(name = 'bar')");
    setOptions("--package_path=/workspace:/otherroot");
    Package oldPkg = getPackage("pkg");
    // change not yet visible
    assertSame(oldPkg, getPackage("pkg"));
    assertEquals(buildFile1, oldPkg.getFilename());
    assertEquals(rootDirectory, oldPkg.getSourceRoot());
    buildFile1.delete();
    invalidatePackages();
    Package newPkg = getPackage("pkg");
    assertNotSame(oldPkg, newPkg);
    assertEquals(buildFile2, newPkg.getFilename());
    assertEquals(scratch.dir("/otherroot"), newPkg.getSourceRoot());
// TODO(bazel-team): (2009) test BUILD file moves in the other direction too.
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) Package(com.google.devtools.build.lib.packages.Package) Test(org.junit.Test)

Example 32 with Package

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

the class IncrementalLoadingTest method testIrrelevantFileInSubdirDoesntReloadPackage.

@Test
public void testIrrelevantFileInSubdirDoesntReloadPackage() throws Exception {
    tester.addFile("pkg/BUILD", "sh_library(name = 'pkg', srcs = glob(['**/*.sh']))");
    tester.addFile("pkg/pkg.sh", "#!/bin/bash");
    tester.addFile("pkg/bar/bar.sh", "#!/bin/bash");
    Package pkg = tester.getTarget("//pkg:pkg").getPackage();
    // Write file in directory to force reload of top-level glob.
    tester.addFile("pkg/irrelevant_file");
    // Subglob is also reloaded.
    tester.addFile("pkg/bar/irrelevant_file");
    assertSame(pkg, tester.getTarget("//pkg:pkg").getPackage());
}
Also used : Package(com.google.devtools.build.lib.packages.Package) Test(org.junit.Test)

Example 33 with Package

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

the class SkyframeDependencyResolver method getTarget.

@Nullable
@Override
protected Target getTarget(Target from, Label label, NestedSetBuilder<Label> rootCauses) throws InterruptedException {
    SkyKey key = PackageValue.key(label.getPackageIdentifier());
    PackageValue packageValue;
    try {
        packageValue = (PackageValue) env.getValueOrThrow(key, NoSuchPackageException.class);
    } catch (NoSuchPackageException e) {
        rootCauses.add(label);
        missingEdgeHook(from, label, e);
        return null;
    }
    if (packageValue == null) {
        return null;
    }
    Package pkg = packageValue.getPackage();
    try {
        Target target = pkg.getTarget(label.getName());
        if (pkg.containsErrors()) {
            NoSuchTargetException e = new NoSuchTargetException(target);
            missingEdgeHook(from, label, e);
            if (target != null) {
                rootCauses.add(label);
                return target;
            } else {
                return null;
            }
        }
        return target;
    } catch (NoSuchTargetException e) {
        rootCauses.add(label);
        missingEdgeHook(from, label, e);
        return null;
    }
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) Target(com.google.devtools.build.lib.packages.Target) NoSuchPackageException(com.google.devtools.build.lib.packages.NoSuchPackageException) NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException) Package(com.google.devtools.build.lib.packages.Package) Nullable(javax.annotation.Nullable)

Example 34 with Package

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

the class WorkspaceFileFunction method compute.

@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws WorkspaceFileFunctionException, InterruptedException {
    WorkspaceFileKey key = (WorkspaceFileKey) skyKey.argument();
    RootedPath workspaceRoot = key.getPath();
    WorkspaceASTValue workspaceASTValue = (WorkspaceASTValue) env.getValue(WorkspaceASTValue.key(workspaceRoot));
    if (workspaceASTValue == null) {
        return null;
    }
    Path repoWorkspace = workspaceRoot.getRoot().getRelative(workspaceRoot.getRelativePath());
    Package.Builder builder = packageFactory.newExternalPackageBuilder(repoWorkspace, ruleClassProvider.getRunfilesPrefix());
    if (workspaceASTValue.getASTs().isEmpty()) {
        return new WorkspaceFileValue(// resulting package
        builder.build(), // list of imports
        ImmutableMap.<String, Extension>of(), // list of symbol bindings
        ImmutableMap.<String, Object>of(), // Workspace root
        workspaceRoot, // first fragment, idx = 0
        0, // last fragment
        false);
    }
    WorkspaceFactory parser;
    try (Mutability mutability = Mutability.create("workspace %s", repoWorkspace)) {
        parser = new WorkspaceFactory(builder, ruleClassProvider, packageFactory.getEnvironmentExtensions(), mutability, key.getIndex() == 0, directories.getEmbeddedBinariesRoot(), directories.getWorkspace());
        if (key.getIndex() > 0) {
            WorkspaceFileValue prevValue = (WorkspaceFileValue) env.getValue(WorkspaceFileValue.key(key.getPath(), key.getIndex() - 1));
            if (prevValue == null) {
                return null;
            }
            if (prevValue.next() == null) {
                return prevValue;
            }
            parser.setParent(prevValue.getPackage(), prevValue.getImportMap(), prevValue.getBindings());
        }
        BuildFileAST ast = workspaceASTValue.getASTs().get(key.getIndex());
        PackageFunction.SkylarkImportResult importResult = PackageFunction.fetchImportsFromBuildFile(repoWorkspace, rootPackage, ast, env, null);
        if (importResult == null) {
            return null;
        }
        parser.execute(ast, importResult.importMap);
    } catch (NoSuchPackageException e) {
        throw new WorkspaceFileFunctionException(e, Transience.PERSISTENT);
    } catch (NameConflictException e) {
        throw new WorkspaceFileFunctionException(e, Transience.PERSISTENT);
    }
    return new WorkspaceFileValue(builder.build(), parser.getImportMap(), parser.getVariableBindings(), workspaceRoot, key.getIndex(), key.getIndex() < workspaceASTValue.getASTs().size() - 1);
}
Also used : RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Path(com.google.devtools.build.lib.vfs.Path) WorkspaceFactory(com.google.devtools.build.lib.packages.WorkspaceFactory) Mutability(com.google.devtools.build.lib.syntax.Mutability) NameConflictException(com.google.devtools.build.lib.packages.Package.NameConflictException) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) NoSuchPackageException(com.google.devtools.build.lib.packages.NoSuchPackageException) WorkspaceFileKey(com.google.devtools.build.lib.skyframe.WorkspaceFileValue.WorkspaceFileKey) Package(com.google.devtools.build.lib.packages.Package) BuildFileAST(com.google.devtools.build.lib.syntax.BuildFileAST)

Example 35 with Package

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

the class WorkspaceFileFunctionTest method testBindArgsReversed.

@Test
public void testBindArgsReversed() throws Exception {
    String[] lines = { "bind(actual = '//foo:bar', name = 'foo/bar')" };
    RootedPath workspacePath = createWorkspaceFile(lines);
    SkyKey key = ExternalPackageFunction.key(workspacePath);
    PackageValue value = (PackageValue) externalSkyFunc.compute(key, getEnv());
    Package pkg = value.getPackage();
    assertEquals(Label.parseAbsolute("//foo:bar"), getLabelMapping(pkg, "foo/bar"));
    MoreAsserts.assertNoEvents(pkg.getEvents());
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) Package(com.google.devtools.build.lib.packages.Package) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Test(org.junit.Test)

Aggregations

Package (com.google.devtools.build.lib.packages.Package)61 SkyKey (com.google.devtools.build.skyframe.SkyKey)25 Test (org.junit.Test)20 PackageIdentifier (com.google.devtools.build.lib.cmdline.PackageIdentifier)14 NoSuchPackageException (com.google.devtools.build.lib.packages.NoSuchPackageException)14 Label (com.google.devtools.build.lib.cmdline.Label)13 Path (com.google.devtools.build.lib.vfs.Path)13 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)13 Target (com.google.devtools.build.lib.packages.Target)12 NoSuchTargetException (com.google.devtools.build.lib.packages.NoSuchTargetException)11 Nullable (javax.annotation.Nullable)10 BuildFileContainsErrorsException (com.google.devtools.build.lib.packages.BuildFileContainsErrorsException)8 ImmutableMap (com.google.common.collect.ImmutableMap)7 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)5 BuildFileNotFoundException (com.google.devtools.build.lib.packages.BuildFileNotFoundException)5 LinkedHashSet (java.util.LinkedHashSet)5 LabelSyntaxException (com.google.devtools.build.lib.cmdline.LabelSyntaxException)4 SkyValue (com.google.devtools.build.skyframe.SkyValue)4 InvalidConfigurationException (com.google.devtools.build.lib.analysis.config.InvalidConfigurationException)3 Attribute (com.google.devtools.build.lib.packages.Attribute)3