Search in sources :

Example 6 with RepositoryName

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));
}
Also used : Root(com.google.devtools.build.lib.actions.Root) BuildInfoType(com.google.devtools.build.lib.analysis.buildinfo.BuildInfoFactory.BuildInfoType) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) RepositoryName(com.google.devtools.build.lib.cmdline.RepositoryName) BuildInfoKey(com.google.devtools.build.lib.analysis.buildinfo.BuildInfoFactory.BuildInfoKey) BuildInfoContext(com.google.devtools.build.lib.analysis.buildinfo.BuildInfoFactory.BuildInfoContext) ArtifactFactory(com.google.devtools.build.lib.actions.ArtifactFactory) BuildInfoKeyAndConfig(com.google.devtools.build.lib.skyframe.BuildInfoCollectionValue.BuildInfoKeyAndConfig) BuildInfoFactory(com.google.devtools.build.lib.analysis.buildinfo.BuildInfoFactory)

Example 7 with 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"));
        }
    }
}
Also used : LabelSyntaxException(com.google.devtools.build.lib.cmdline.LabelSyntaxException) DefaultModelResolver(com.google.devtools.build.workspace.maven.DefaultModelResolver) RepositoryName(com.google.devtools.build.lib.cmdline.RepositoryName) ModelSource(org.apache.maven.model.building.ModelSource) InvalidArtifactCoordinateException(com.google.devtools.build.workspace.maven.Resolver.InvalidArtifactCoordinateException) Target(com.google.devtools.build.lib.packages.Target) AttributeMap(com.google.devtools.build.lib.packages.AttributeMap) UnresolvableModelException(org.apache.maven.model.resolution.UnresolvableModelException) Rule(com.google.devtools.build.workspace.maven.Rule) Location(com.google.devtools.build.lib.events.Location)

Example 8 with RepositoryName

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);
}
Also used : BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) RawAttributeMapper(com.google.devtools.build.lib.packages.RawAttributeMapper) ArtifactOwner(com.google.devtools.build.lib.actions.ArtifactOwner) Root(com.google.devtools.build.lib.actions.Root) RepositoryName(com.google.devtools.build.lib.cmdline.RepositoryName) Rule(com.google.devtools.build.lib.packages.Rule) ConfiguredTargetKey(com.google.devtools.build.lib.skyframe.ConfiguredTargetKey)

Aggregations

RepositoryName (com.google.devtools.build.lib.cmdline.RepositoryName)8 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)5 LabelSyntaxException (com.google.devtools.build.lib.cmdline.LabelSyntaxException)3 Path (com.google.devtools.build.lib.vfs.Path)3 Root (com.google.devtools.build.lib.actions.Root)2 Rule (com.google.devtools.build.lib.packages.Rule)2 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)2 SkyKey (com.google.devtools.build.skyframe.SkyKey)2 Nullable (javax.annotation.Nullable)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ActionExecutionException (com.google.devtools.build.lib.actions.ActionExecutionException)1 Artifact (com.google.devtools.build.lib.actions.Artifact)1 ArtifactFactory (com.google.devtools.build.lib.actions.ArtifactFactory)1 ArtifactOwner (com.google.devtools.build.lib.actions.ArtifactOwner)1 BlazeDirectories (com.google.devtools.build.lib.analysis.BlazeDirectories)1 BuildInfoFactory (com.google.devtools.build.lib.analysis.buildinfo.BuildInfoFactory)1 BuildInfoContext (com.google.devtools.build.lib.analysis.buildinfo.BuildInfoFactory.BuildInfoContext)1 BuildInfoKey (com.google.devtools.build.lib.analysis.buildinfo.BuildInfoFactory.BuildInfoKey)1 BuildInfoType (com.google.devtools.build.lib.analysis.buildinfo.BuildInfoFactory.BuildInfoType)1 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)1