use of com.google.devtools.build.lib.cmdline.RepositoryName in project bazel by bazelbuild.
the class BuildInfoCollectionFunction method compute.
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException {
final BuildInfoKeyAndConfig keyAndConfig = (BuildInfoKeyAndConfig) skyKey.argument();
WorkspaceStatusValue infoArtifactValue = (WorkspaceStatusValue) env.getValue(WorkspaceStatusValue.SKY_KEY);
if (infoArtifactValue == null) {
return null;
}
Map<BuildInfoKey, BuildInfoFactory> buildInfoFactories = PrecomputedValue.BUILD_INFO_FACTORIES.get(env);
if (buildInfoFactories == null) {
return null;
}
WorkspaceNameValue nameValue = (WorkspaceNameValue) env.getValue(WorkspaceNameValue.key());
if (nameValue == null) {
return null;
}
RepositoryName repositoryName = RepositoryName.createFromValidStrippedName(nameValue.maybeGetName());
final ArtifactFactory factory = artifactFactory.get();
BuildInfoContext context = new BuildInfoContext() {
@Override
public Artifact getBuildInfoArtifact(PathFragment rootRelativePath, Root root, BuildInfoType type) {
return type == BuildInfoType.NO_REBUILD ? factory.getConstantMetadataArtifact(rootRelativePath, root, keyAndConfig) : factory.getDerivedArtifact(rootRelativePath, root, keyAndConfig);
}
};
return new BuildInfoCollectionValue(buildInfoFactories.get(keyAndConfig.getInfoKey()).create(context, keyAndConfig.getConfig(), infoArtifactValue.getStableArtifact(), infoArtifactValue.getVolatileArtifact(), repositoryName));
}
use of com.google.devtools.build.lib.cmdline.RepositoryName in project bazel by bazelbuild.
the class WorkspaceResolver method resolveTransitiveDependencies.
/**
* Calculates transitive dependencies of the given //external package.
*/
public void resolveTransitiveDependencies(Package externalPackage) {
Location location = Location.fromFile(externalPackage.getFilename());
for (Target target : externalPackage.getTargets()) {
// Targets are //external:foo.
if (target.getTargetKind().startsWith("maven_jar ")) {
RepositoryName repositoryName;
try {
repositoryName = RepositoryName.create("@" + target.getName());
} catch (LabelSyntaxException e) {
handler.handle(Event.error(location, "Invalid repository name for " + target + ": " + e.getMessage()));
return;
}
com.google.devtools.build.lib.packages.Rule workspaceRule = externalPackage.getRule(repositoryName.strippedName());
DefaultModelResolver modelResolver = resolver.getModelResolver();
AttributeMap attributeMap = AggregatingAttributeMapper.of(workspaceRule);
Rule rule;
try {
rule = new Rule(Resolver.getArtifact(attributeMap.get("artifact", Type.STRING)));
} catch (InvalidArtifactCoordinateException e) {
handler.handle(Event.error(location, "Couldn't get attribute: " + e.getMessage()));
return;
}
if (attributeMap.isAttributeValueExplicitlySpecified("repository")) {
modelResolver.addUserRepository(attributeMap.get("repository", Type.STRING));
rule.setRepository(attributeMap.get("repository", Type.STRING), handler);
}
if (attributeMap.isAttributeValueExplicitlySpecified("sha1")) {
rule.setSha1(attributeMap.get("sha1", Type.STRING));
} else {
rule.setSha1(resolver.downloadSha1(rule));
}
ModelSource modelSource;
try {
modelSource = modelResolver.resolveModel(rule.groupId(), rule.artifactId(), rule.version());
} catch (UnresolvableModelException e) {
handler.handle(Event.error("Could not resolve model for " + target + ": " + e.getMessage()));
continue;
}
resolver.addArtifact(rule, modelSource.getLocation());
resolver.resolveEffectiveModel(modelSource, Sets.<String>newHashSet(), rule);
} else if (!target.getTargetKind().startsWith("bind") && !target.getTargetKind().startsWith("source ")) {
handler.handle(Event.warn(location, "Cannot fetch transitive dependencies for " + target + " yet, skipping"));
}
}
}
use of com.google.devtools.build.lib.cmdline.RepositoryName in project bazel by bazelbuild.
the class BuildViewTestCase method getImplicitOutputArtifact.
protected Artifact getImplicitOutputArtifact(ConfiguredTarget target, SafeImplicitOutputsFunction outputFunction) {
Rule associatedRule = target.getTarget().getAssociatedRule();
RepositoryName repository = associatedRule.getRepository();
BuildConfiguration configuration = target.getConfiguration();
Root root;
if (associatedRule.hasBinaryOutput()) {
root = configuration.getBinDirectory(repository);
} else {
root = configuration.getGenfilesDirectory(repository);
}
ArtifactOwner owner = new ConfiguredTargetKey(target.getTarget().getLabel(), target.getConfiguration());
RawAttributeMapper attr = RawAttributeMapper.of(associatedRule);
String path = Iterables.getOnlyElement(outputFunction.getImplicitOutputs(attr));
return view.getArtifactFactory().getDerivedArtifact(target.getTarget().getLabel().getPackageFragment().getRelative(path), root, owner);
}
Aggregations