Search in sources :

Example 21 with EvalException

use of com.google.devtools.build.lib.syntax.EvalException in project bazel by bazelbuild.

the class HttpArchiveFunction method getDescriptor.

protected DecompressorDescriptor getDescriptor(Rule rule, Path downloadPath, Path outputDirectory) throws RepositoryFunctionException {
    DecompressorDescriptor.Builder builder = DecompressorDescriptor.builder().setTargetKind(rule.getTargetKind()).setTargetName(rule.getName()).setArchivePath(downloadPath).setRepositoryPath(outputDirectory);
    WorkspaceAttributeMapper mapper = WorkspaceAttributeMapper.of(rule);
    if (mapper.isAttributeValueExplicitlySpecified("strip_prefix")) {
        try {
            builder.setPrefix(mapper.get("strip_prefix", Type.STRING));
        } catch (EvalException e) {
            throw new RepositoryFunctionException(e, Transience.PERSISTENT);
        }
    }
    return builder.build();
}
Also used : EvalException(com.google.devtools.build.lib.syntax.EvalException) WorkspaceAttributeMapper(com.google.devtools.build.lib.rules.repository.WorkspaceAttributeMapper)

Example 22 with EvalException

use of com.google.devtools.build.lib.syntax.EvalException in project bazel by bazelbuild.

the class HttpFileFunction method getDescriptor.

@Override
protected DecompressorDescriptor getDescriptor(Rule rule, Path downloadPath, Path outputDirectory) throws RepositoryFunctionException {
    WorkspaceAttributeMapper mapper = WorkspaceAttributeMapper.of(rule);
    boolean executable = false;
    try {
        executable = (mapper.isAttributeValueExplicitlySpecified("executable") && mapper.get("executable", Type.BOOLEAN));
    } catch (EvalException e) {
        throw new RepositoryFunctionException(e, Transience.PERSISTENT);
    }
    return DecompressorDescriptor.builder().setDecompressor(FileDecompressor.INSTANCE).setTargetKind(rule.getTargetKind()).setTargetName(rule.getName()).setArchivePath(downloadPath).setRepositoryPath(outputDirectory).setExecutable(executable).build();
}
Also used : EvalException(com.google.devtools.build.lib.syntax.EvalException) WorkspaceAttributeMapper(com.google.devtools.build.lib.rules.repository.WorkspaceAttributeMapper)

Example 23 with EvalException

use of com.google.devtools.build.lib.syntax.EvalException in project bazel by bazelbuild.

the class MavenJarFunction method createOutputTree.

private RepositoryDirectoryValue.Builder createOutputTree(Rule rule, Path outputDirectory, MavenServerValue serverValue) throws RepositoryFunctionException, InterruptedException {
    Preconditions.checkState(downloader instanceof MavenDownloader);
    MavenDownloader mavenDownloader = (MavenDownloader) downloader;
    createDirectory(outputDirectory);
    String name = rule.getName();
    Path repositoryJar;
    try {
        repositoryJar = mavenDownloader.download(name, WorkspaceAttributeMapper.of(rule), outputDirectory, serverValue);
    } catch (IOException e) {
        throw new RepositoryFunctionException(e, Transience.TRANSIENT);
    } catch (EvalException e) {
        throw new RepositoryFunctionException(e, Transience.TRANSIENT);
    }
    // Add a WORKSPACE file & BUILD file to the Maven jar.
    Path result = DecompressorValue.decompress(DecompressorDescriptor.builder().setDecompressor(JarDecompressor.INSTANCE).setTargetKind(MavenJarRule.NAME).setTargetName(name).setArchivePath(repositoryJar).setRepositoryPath(outputDirectory).build());
    return RepositoryDirectoryValue.builder().setPath(result);
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) IOException(java.io.IOException) EvalException(com.google.devtools.build.lib.syntax.EvalException)

Example 24 with EvalException

use of com.google.devtools.build.lib.syntax.EvalException in project bazel by bazelbuild.

the class MavenJarFunction method getServer.

private static MavenServerValue getServer(Rule rule, Environment env) throws RepositoryFunctionException, InterruptedException {
    WorkspaceAttributeMapper mapper = WorkspaceAttributeMapper.of(rule);
    boolean hasRepository = mapper.isAttributeValueExplicitlySpecified("repository");
    boolean hasServer = mapper.isAttributeValueExplicitlySpecified("server");
    if (hasRepository && hasServer) {
        throw new RepositoryFunctionException(new EvalException(rule.getLocation(), rule + " specifies both " + "'repository' and 'server', which are mutually exclusive options"), Transience.PERSISTENT);
    }
    try {
        if (hasRepository) {
            return MavenServerValue.createFromUrl(mapper.get("repository", Type.STRING));
        } else {
            String serverName = DEFAULT_SERVER;
            if (hasServer) {
                serverName = mapper.get("server", Type.STRING);
            }
            return (MavenServerValue) env.getValue(MavenServerValue.key(serverName));
        }
    } catch (EvalException e) {
        throw new RepositoryFunctionException(e, Transience.PERSISTENT);
    }
}
Also used : EvalException(com.google.devtools.build.lib.syntax.EvalException) WorkspaceAttributeMapper(com.google.devtools.build.lib.rules.repository.WorkspaceAttributeMapper)

Example 25 with EvalException

use of com.google.devtools.build.lib.syntax.EvalException in project bazel by bazelbuild.

the class PostConfiguredTargetFunction method compute.

@Nullable
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws SkyFunctionException, InterruptedException {
    ImmutableMap<ActionAnalysisMetadata, ConflictException> badActions = PrecomputedValue.BAD_ACTIONS.get(env);
    ConfiguredTargetValue ctValue = (ConfiguredTargetValue) env.getValue(ConfiguredTargetValue.key((ConfiguredTargetKey) skyKey.argument()));
    if (env.valuesMissing()) {
        return null;
    }
    for (ActionAnalysisMetadata action : ctValue.getActions()) {
        if (badActions.containsKey(action)) {
            throw new ActionConflictFunctionException(badActions.get(action));
        }
    }
    ConfiguredTarget ct = ctValue.getConfiguredTarget();
    TargetAndConfiguration ctgValue = new TargetAndConfiguration(ct.getTarget(), ct.getConfiguration());
    ImmutableMap<Label, ConfigMatchingProvider> configConditions = getConfigurableAttributeConditions(ctgValue, env);
    if (configConditions == null) {
        return null;
    }
    OrderedSetMultimap<Attribute, Dependency> deps;
    try {
        BuildConfiguration hostConfiguration = buildViewProvider.getSkyframeBuildView().getHostConfiguration(ct.getConfiguration());
        SkyframeDependencyResolver resolver = buildViewProvider.getSkyframeBuildView().createDependencyResolver(env);
        // We don't track root causes here - this function is only invoked for successfully analyzed
        // targets - as long as we redo the exact same steps here as in ConfiguredTargetFunction, this
        // can never fail.
        deps = resolver.dependentNodeMap(ctgValue, hostConfiguration, /*aspect=*/
        null, configConditions);
        if (ct.getConfiguration() != null && ct.getConfiguration().useDynamicConfigurations()) {
            deps = ConfiguredTargetFunction.getDynamicConfigurations(env, ctgValue, deps, hostConfiguration, ruleClassProvider);
        }
    } catch (EvalException | ConfiguredTargetFunction.DependencyEvaluationException | InvalidConfigurationException | InconsistentAspectOrderException e) {
        throw new PostConfiguredTargetFunctionException(e);
    }
    env.getValues(Iterables.transform(deps.values(), TO_KEYS));
    if (env.valuesMissing()) {
        return null;
    }
    return new PostConfiguredTargetValue(ct);
}
Also used : ConflictException(com.google.devtools.build.lib.skyframe.SkyframeActionExecutor.ConflictException) Attribute(com.google.devtools.build.lib.packages.Attribute) Label(com.google.devtools.build.lib.cmdline.Label) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) ActionAnalysisMetadata(com.google.devtools.build.lib.actions.ActionAnalysisMetadata) Dependency(com.google.devtools.build.lib.analysis.Dependency) EvalException(com.google.devtools.build.lib.syntax.EvalException) InconsistentAspectOrderException(com.google.devtools.build.lib.analysis.DependencyResolver.InconsistentAspectOrderException) InvalidConfigurationException(com.google.devtools.build.lib.analysis.config.InvalidConfigurationException) BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) TargetAndConfiguration(com.google.devtools.build.lib.analysis.TargetAndConfiguration) ConfigMatchingProvider(com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider) Nullable(javax.annotation.Nullable)

Aggregations

EvalException (com.google.devtools.build.lib.syntax.EvalException)47 IOException (java.io.IOException)15 WorkspaceAttributeMapper (com.google.devtools.build.lib.rules.repository.WorkspaceAttributeMapper)9 ClassObject (com.google.devtools.build.lib.syntax.ClassObject)9 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 Label (com.google.devtools.build.lib.cmdline.Label)8 Path (com.google.devtools.build.lib.vfs.Path)8 SkylarkClassObject (com.google.devtools.build.lib.packages.SkylarkClassObject)7 Environment (com.google.devtools.build.lib.syntax.Environment)7 Map (java.util.Map)7 LabelSyntaxException (com.google.devtools.build.lib.cmdline.LabelSyntaxException)6 RepositoryFunctionException (com.google.devtools.build.lib.rules.repository.RepositoryFunction.RepositoryFunctionException)6 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)6 SkyKey (com.google.devtools.build.skyframe.SkyKey)6 Nullable (javax.annotation.Nullable)6 FileValue (com.google.devtools.build.lib.skyframe.FileValue)5 ImmutableList (com.google.common.collect.ImmutableList)4 Artifact (com.google.devtools.build.lib.actions.Artifact)4 BaseFunction (com.google.devtools.build.lib.syntax.BaseFunction)3