Search in sources :

Example 1 with RepositoryValue

use of com.google.devtools.build.lib.skyframe.RepositoryValue 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)

Aggregations

LabelSyntaxException (com.google.devtools.build.lib.cmdline.LabelSyntaxException)1 RepositoryName (com.google.devtools.build.lib.cmdline.RepositoryName)1 RepositoryValue (com.google.devtools.build.lib.skyframe.RepositoryValue)1 WorkspaceFileValue (com.google.devtools.build.lib.skyframe.WorkspaceFileValue)1 Path (com.google.devtools.build.lib.vfs.Path)1 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)1 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)1 SkyKey (com.google.devtools.build.skyframe.SkyKey)1 Nullable (javax.annotation.Nullable)1