Search in sources :

Example 1 with NewRepositoryBuildFileHandler

use of com.google.devtools.build.lib.rules.repository.NewRepositoryBuildFileHandler in project bazel by bazelbuild.

the class NewGitRepositoryFunction method fetch.

@Override
public RepositoryDirectoryValue.Builder fetch(Rule rule, Path outputDirectory, BlazeDirectories directories, Environment env, Map<String, String> markerData) throws InterruptedException, RepositoryFunctionException {
    NewRepositoryBuildFileHandler buildFileHandler = new NewRepositoryBuildFileHandler(directories.getWorkspace());
    if (!buildFileHandler.prepareBuildFile(rule, env)) {
        return null;
    }
    createDirectory(outputDirectory, rule);
    GitCloner.clone(rule, outputDirectory, env.getListener(), clientEnvironment);
    createWorkspaceFile(outputDirectory, rule.getTargetKind(), rule.getName());
    buildFileHandler.finishBuildFile(outputDirectory);
    return RepositoryDirectoryValue.builder().setPath(outputDirectory);
}
Also used : NewRepositoryBuildFileHandler(com.google.devtools.build.lib.rules.repository.NewRepositoryBuildFileHandler)

Example 2 with NewRepositoryBuildFileHandler

use of com.google.devtools.build.lib.rules.repository.NewRepositoryBuildFileHandler in project bazel by bazelbuild.

the class NewHttpArchiveFunction method fetch.

@Nullable
@Override
public RepositoryDirectoryValue.Builder fetch(Rule rule, Path outputDirectory, BlazeDirectories directories, Environment env, Map<String, String> markerData) throws RepositoryFunctionException, InterruptedException {
    NewRepositoryBuildFileHandler buildFileHandler = new NewRepositoryBuildFileHandler(directories.getWorkspace());
    if (!buildFileHandler.prepareBuildFile(rule, env)) {
        return null;
    }
    try {
        FileSystemUtils.createDirectoryAndParents(outputDirectory);
    } catch (IOException e) {
        throw new RepositoryFunctionException(new IOException("Could not create directory for " + rule.getName() + ": " + e.getMessage()), Transience.TRANSIENT);
    }
    // Download.
    Path downloadedPath = downloader.download(rule, outputDirectory, env.getListener(), clientEnvironment);
    // Decompress.
    Path decompressed;
    WorkspaceAttributeMapper mapper = WorkspaceAttributeMapper.of(rule);
    String prefix = null;
    if (mapper.isAttributeValueExplicitlySpecified("strip_prefix")) {
        try {
            prefix = mapper.get("strip_prefix", Type.STRING);
        } catch (EvalException e) {
            throw new RepositoryFunctionException(e, Transience.PERSISTENT);
        }
    }
    decompressed = DecompressorValue.decompress(DecompressorDescriptor.builder().setTargetKind(rule.getTargetKind()).setTargetName(rule.getName()).setArchivePath(downloadedPath).setRepositoryPath(outputDirectory).setPrefix(prefix).build());
    // Finally, write WORKSPACE and BUILD files.
    createWorkspaceFile(decompressed, rule.getTargetKind(), rule.getName());
    buildFileHandler.finishBuildFile(outputDirectory);
    return RepositoryDirectoryValue.builder().setPath(outputDirectory);
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) IOException(java.io.IOException) EvalException(com.google.devtools.build.lib.syntax.EvalException) NewRepositoryBuildFileHandler(com.google.devtools.build.lib.rules.repository.NewRepositoryBuildFileHandler) WorkspaceAttributeMapper(com.google.devtools.build.lib.rules.repository.WorkspaceAttributeMapper) Nullable(javax.annotation.Nullable)

Aggregations

NewRepositoryBuildFileHandler (com.google.devtools.build.lib.rules.repository.NewRepositoryBuildFileHandler)2 WorkspaceAttributeMapper (com.google.devtools.build.lib.rules.repository.WorkspaceAttributeMapper)1 EvalException (com.google.devtools.build.lib.syntax.EvalException)1 Path (com.google.devtools.build.lib.vfs.Path)1 IOException (java.io.IOException)1 Nullable (javax.annotation.Nullable)1