use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.annotations.VisibleForTesting in project buck by facebook.
the class Resolver method getNewerVersionFile.
/**
* @return {@link Path} to the file in {@code project} with filename consistent with the given
* {@link Artifact}, but with a newer version. If no such file exists, {@link Optional#empty} is
* returned. If multiple such files are present one with the newest version will be returned.
*/
@VisibleForTesting
Optional<Path> getNewerVersionFile(final Artifact artifactToDownload, Path project) throws IOException {
final Version artifactToDownloadVersion;
try {
artifactToDownloadVersion = versionScheme.parseVersion(artifactToDownload.getVersion());
} catch (InvalidVersionSpecificationException e) {
throw new RuntimeException(e);
}
final Pattern versionExtractor = Pattern.compile(String.format(ARTIFACT_FILE_NAME_REGEX_FORMAT, artifactToDownload.getArtifactId(), VERSION_REGEX_GROUP, artifactToDownload.getExtension()));
Iterable<Version> versionsPresent = FluentIterable.from(Files.newDirectoryStream(project)).transform(new Function<Path, Version>() {
@Nullable
@Override
public Version apply(Path input) {
Matcher matcher = versionExtractor.matcher(input.getFileName().toString());
if (matcher.matches()) {
try {
return versionScheme.parseVersion(matcher.group(1));
} catch (InvalidVersionSpecificationException e) {
throw new RuntimeException(e);
}
} else {
return null;
}
}
}).filter(Objects::nonNull);
List<Version> newestPresent = Ordering.natural().greatestOf(versionsPresent, 1);
if (newestPresent.isEmpty() || newestPresent.get(0).compareTo(artifactToDownloadVersion) <= 0) {
return Optional.empty();
} else {
return Optional.of(project.resolve(String.format(ARTIFACT_FILE_NAME_FORMAT, artifactToDownload.getArtifactId(), newestPresent.get(0).toString(), artifactToDownload.getExtension())));
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.annotations.VisibleForTesting in project buck by facebook.
the class WorkerProcessPoolFactory method getEnvironmentForProcess.
@VisibleForTesting
ImmutableMap<String, String> getEnvironmentForProcess(ExecutionContext context, WorkerJobParams workerJobParams) {
Path tmpDir = workerJobParams.getTempDir();
Map<String, String> envVars = Maps.newHashMap(context.getEnvironment());
envVars.put("TMP", filesystem.resolve(tmpDir).toString());
envVars.putAll(workerJobParams.getStartupEnvironment());
return ImmutableMap.copyOf(envVars);
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.annotations.VisibleForTesting in project buck by facebook.
the class Genrule method isWorkerGenrule.
@VisibleForTesting
public boolean isWorkerGenrule() {
Arg cmdArg = cmd.orElse(null);
Arg bashArg = bash.orElse(null);
Arg cmdExeArg = cmdExe.orElse(null);
if ((cmdArg instanceof WorkerMacroArg) || (bashArg instanceof WorkerMacroArg) || (cmdExeArg instanceof WorkerMacroArg)) {
if ((cmdArg != null && !(cmdArg instanceof WorkerMacroArg)) || (bashArg != null && !(bashArg instanceof WorkerMacroArg)) || (cmdExeArg != null && !(cmdExeArg instanceof WorkerMacroArg))) {
throw new HumanReadableException("You cannot use a worker macro in one of the cmd, bash, " + "or cmd_exe properties and not in the others for genrule %s.", getBuildTarget().getFullyQualifiedName());
}
return true;
}
return false;
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.annotations.VisibleForTesting in project buck by facebook.
the class Genrule method getBuildSteps.
@Override
@VisibleForTesting
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
ImmutableList.Builder<Step> commands = ImmutableList.builder();
// Make sure that the directory to contain the output file exists, deleting any pre-existing
// ones. Rules get output to a directory named after the base path, so we don't want to nuke
// the entire directory.
commands.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToOutDirectory));
// Delete the old temp directory
commands.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToTmpDirectory));
// Create a directory to hold all the source files.
commands.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToSrcDirectory));
addSymlinkCommands(context, commands);
// Create a shell command that corresponds to this.cmd.
if (this.isWorkerGenrule) {
commands.add(createWorkerShellStep(context));
} else {
commands.add(createGenruleStep(context));
}
if (MorePaths.getFileExtension(pathToOutFile).equals("zip")) {
commands.add(new ZipScrubberStep(getProjectFilesystem(), pathToOutFile));
}
buildableContext.recordArtifact(pathToOutFile);
return commands.build();
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.annotations.VisibleForTesting in project buck by facebook.
the class Genrule method addSymlinkCommands.
@VisibleForTesting
void addSymlinkCommands(BuildContext context, ImmutableList.Builder<Step> commands) {
Path basePath = getBuildTarget().getBasePath();
// Symlink all sources into the temp directory so that they can be used in the genrule.
for (SourcePath src : srcs) {
Path relativePath = context.getSourcePathResolver().getRelativePath(src);
Path absolutePath = context.getSourcePathResolver().getAbsolutePath(src);
Path canonicalPath = absolutePath.normalize();
// By the time we get this far, all source paths (the keys in the map) have been converted
// to paths relative to the project root. We want the path relative to the build target, so
// strip the base path.
Path localPath;
if (absolutePath.equals(canonicalPath)) {
if (relativePath.startsWith(basePath) || getBuildTarget().isInCellRoot()) {
localPath = MorePaths.relativize(basePath, relativePath);
} else {
localPath = canonicalPath.getFileName();
}
} else {
localPath = relativePath;
}
Path destination = pathToSrcDirectory.resolve(localPath);
commands.add(new MkdirAndSymlinkFileStep(getProjectFilesystem(), relativePath, destination));
}
}
Aggregations