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);
}
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);
}
Aggregations