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