Search in sources :

Example 1 with WorkspaceFileValue

use of com.google.devtools.build.lib.skyframe.WorkspaceFileValue in project bazel by bazelbuild.

the class RepositoryLoaderFunction method compute.

@Nullable
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws SkyFunctionException, InterruptedException {
    // This cannot be combined with {@link RepositoryDelegatorFunction}. RDF fetches the
    // repository and must not have a Skyframe restart after writing it (otherwise the repository
    // would be re-downloaded).
    RepositoryName nameFromRule = (RepositoryName) skyKey.argument();
    SkyKey repositoryKey = RepositoryDirectoryValue.key(nameFromRule);
    RepositoryDirectoryValue repository = (RepositoryDirectoryValue) env.getValue(repositoryKey);
    if (repository == null) {
        return null;
    }
    SkyKey workspaceKey = WorkspaceFileValue.key(RootedPath.toRootedPath(repository.getPath(), new PathFragment("WORKSPACE")));
    WorkspaceFileValue workspacePackage = (WorkspaceFileValue) env.getValue(workspaceKey);
    if (workspacePackage == null) {
        return null;
    }
    RepositoryName workspaceName;
    try {
        String workspaceNameStr = workspacePackage.getPackage().getWorkspaceName();
        workspaceName = workspaceNameStr.isEmpty() ? RepositoryName.create("") : RepositoryName.create("@" + workspaceNameStr);
    } catch (LabelSyntaxException e) {
        throw new IllegalStateException(e);
    }
    if (!workspaceName.isDefault() && !workspaceName.strippedName().equals(Label.DEFAULT_REPOSITORY_DIRECTORY) && !nameFromRule.equals(workspaceName)) {
        Path workspacePath = repository.getPath().getRelative("WORKSPACE");
        env.getListener().handle(Event.warn(Location.fromFile(workspacePath), "Workspace name in " + workspacePath + " (" + workspaceName + ") does not match the " + "name given in the repository's definition (" + nameFromRule + "); this will " + "cause a build error in future versions"));
    }
    return new RepositoryValue(nameFromRule, repository);
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Path(com.google.devtools.build.lib.vfs.Path) LabelSyntaxException(com.google.devtools.build.lib.cmdline.LabelSyntaxException) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) RepositoryName(com.google.devtools.build.lib.cmdline.RepositoryName) WorkspaceFileValue(com.google.devtools.build.lib.skyframe.WorkspaceFileValue) RepositoryValue(com.google.devtools.build.lib.skyframe.RepositoryValue) Nullable(javax.annotation.Nullable)

Example 2 with WorkspaceFileValue

use of com.google.devtools.build.lib.skyframe.WorkspaceFileValue in project bazel by bazelbuild.

the class RepositoryFunction method getRule.

/**
   * Uses a remote repository name to fetch the corresponding Rule describing how to get it.
   *
   * <p>This should be the unique entry point for resolving a remote repository function.
   */
@Nullable
public static Rule getRule(String repository, Environment env) throws RepositoryFunctionException, InterruptedException {
    SkyKey packageLookupKey = PackageLookupValue.key(Label.EXTERNAL_PACKAGE_IDENTIFIER);
    PackageLookupValue packageLookupValue = (PackageLookupValue) env.getValue(packageLookupKey);
    if (packageLookupValue == null) {
        return null;
    }
    RootedPath workspacePath = packageLookupValue.getRootedPath(Label.EXTERNAL_PACKAGE_IDENTIFIER);
    SkyKey workspaceKey = WorkspaceFileValue.key(workspacePath);
    do {
        WorkspaceFileValue value = (WorkspaceFileValue) env.getValue(workspaceKey);
        if (value == null) {
            return null;
        }
        Package externalPackage = value.getPackage();
        if (externalPackage.containsErrors()) {
            Event.replayEventsOn(env.getListener(), externalPackage.getEvents());
            throw new RepositoryFunctionException(new BuildFileContainsErrorsException(Label.EXTERNAL_PACKAGE_IDENTIFIER, "Could not load //external package"), Transience.PERSISTENT);
        }
        Rule rule = externalPackage.getRule(repository);
        if (rule != null) {
            return rule;
        }
        workspaceKey = value.next();
    } while (workspaceKey != null);
    throw new RepositoryNotFoundException(repository);
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) PackageLookupValue(com.google.devtools.build.lib.skyframe.PackageLookupValue) BuildFileContainsErrorsException(com.google.devtools.build.lib.packages.BuildFileContainsErrorsException) WorkspaceFileValue(com.google.devtools.build.lib.skyframe.WorkspaceFileValue) Package(com.google.devtools.build.lib.packages.Package) Rule(com.google.devtools.build.lib.packages.Rule) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Nullable(javax.annotation.Nullable)

Aggregations

WorkspaceFileValue (com.google.devtools.build.lib.skyframe.WorkspaceFileValue)2 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)2 SkyKey (com.google.devtools.build.skyframe.SkyKey)2 Nullable (javax.annotation.Nullable)2 LabelSyntaxException (com.google.devtools.build.lib.cmdline.LabelSyntaxException)1 RepositoryName (com.google.devtools.build.lib.cmdline.RepositoryName)1 BuildFileContainsErrorsException (com.google.devtools.build.lib.packages.BuildFileContainsErrorsException)1 Package (com.google.devtools.build.lib.packages.Package)1 Rule (com.google.devtools.build.lib.packages.Rule)1 PackageLookupValue (com.google.devtools.build.lib.skyframe.PackageLookupValue)1 RepositoryValue (com.google.devtools.build.lib.skyframe.RepositoryValue)1 Path (com.google.devtools.build.lib.vfs.Path)1 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)1