use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.annotations.VisibleForTesting in project buck by facebook.
the class CxxErrorTransformerFactory method transformLine.
@VisibleForTesting
String transformLine(String line) {
for (Pattern pattern : PATH_PATTERNS) {
Matcher m = pattern.matcher(line);
if (m.find()) {
StringBuilder builder = new StringBuilder();
String prefix = m.group("prefix");
if (prefix != null) {
builder.append(prefix);
}
builder.append(transformPath(m.group("path")));
String suffix = m.group("suffix");
if (suffix != null) {
builder.append(suffix);
}
return m.replaceAll(Matcher.quoteReplacement(builder.toString()));
}
}
return line;
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.annotations.VisibleForTesting in project buck by facebook.
the class AbstractCxxSourceRuleFactory method requireCompileBuildRule.
@VisibleForTesting
CxxPreprocessAndCompile requireCompileBuildRule(String name, CxxSource source) {
BuildTarget target = createCompileBuildTarget(name);
Optional<CxxPreprocessAndCompile> existingRule = getResolver().getRuleOptionalWithType(target, CxxPreprocessAndCompile.class);
if (existingRule.isPresent()) {
if (!existingRule.get().getInput().equals(source.getPath())) {
throw new RuntimeException(String.format("Hash collision for %s; a build rule would have been ignored.", name));
}
return existingRule.get();
}
return createCompileBuildRule(name, source);
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.annotations.VisibleForTesting in project buck by facebook.
the class AbstractCxxSourceRuleFactory method createCompileBuildRule.
/**
* @return a {@link CxxPreprocessAndCompile} rule that preprocesses, compiles, and assembles the
* given {@link CxxSource}.
*/
@VisibleForTesting
public CxxPreprocessAndCompile createCompileBuildRule(String name, CxxSource source) {
Preconditions.checkArgument(CxxSourceTypes.isCompilableType(source.getType()));
BuildTarget target = createCompileBuildTarget(name);
DepsBuilder depsBuilder = new DepsBuilder(getRuleFinder());
Compiler compiler = CxxSourceTypes.getCompiler(getCxxPlatform(), source.getType()).resolve(getResolver());
// Build up the list of compiler flags.
CxxToolFlags flags = CxxToolFlags.explicitBuilder().addAllPlatformFlags(getPicType().getFlags(compiler)).addAllPlatformFlags(getPlatformCompileFlags(source.getType())).addAllRuleFlags(getRuleCompileFlags(source.getType())).addAllRuleFlags(source.getFlags()).build();
CompilerDelegate compilerDelegate = new CompilerDelegate(getPathResolver(), getCxxPlatform().getCompilerDebugPathSanitizer(), compiler, flags);
depsBuilder.add(compilerDelegate);
depsBuilder.add(source);
// Build the CxxCompile rule and add it to our sorted set of build rules.
CxxPreprocessAndCompile result = CxxPreprocessAndCompile.compile(getParams().withBuildTarget(target).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(depsBuilder.build()), Suppliers.ofInstance(ImmutableSortedSet.of())), compilerDelegate, getCompileOutputPath(target, name), source.getPath(), source.getType(), getCxxPlatform().getCompilerDebugPathSanitizer(), getCxxPlatform().getAssemblerDebugPathSanitizer(), getSandboxTree());
getResolver().addToIndex(result);
return result;
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.annotations.VisibleForTesting in project buck by facebook.
the class TargetsCommand method printJsonForTargets.
@VisibleForTesting
void printJsonForTargets(CommandRunnerParams params, ListeningExecutorService executor, Iterable<TargetNode<?, ?>> targetNodes, ImmutableMap<BuildTarget, ShowOptions> showRulesResult, ImmutableSet<String> outputAttributes) throws BuildFileParseException {
PatternsMatcher attributesPatternsMatcher = new PatternsMatcher(outputAttributes);
// Print the JSON representation of the build node for the specified target(s).
params.getConsole().getStdOut().println("[");
ObjectMapper mapper = params.getObjectMapper();
Iterator<TargetNode<?, ?>> targetNodeIterator = targetNodes.iterator();
while (targetNodeIterator.hasNext()) {
TargetNode<?, ?> targetNode = targetNodeIterator.next();
Map<String, Object> sortedTargetRule;
sortedTargetRule = params.getParser().getRawTargetNode(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), executor, targetNode);
if (sortedTargetRule == null) {
params.getConsole().printErrorText("unable to find rule for target " + targetNode.getBuildTarget().getFullyQualifiedName());
continue;
}
sortedTargetRule = attributesPatternsMatcher.filterMatchingMapKeys(sortedTargetRule);
ShowOptions showOptions = showRulesResult.get(targetNode.getBuildTarget());
if (showOptions != null) {
putIfValuePresentAndMatches(ShowOptionsName.RULE_KEY.getName(), showOptions.getRuleKey(), sortedTargetRule, attributesPatternsMatcher);
putIfValuePresentAndMatches(ShowOptionsName.OUTPUT_PATH.getName(), showOptions.getOutputPath(), sortedTargetRule, attributesPatternsMatcher);
putIfValuePresentAndMatches(ShowOptionsName.TARGET_HASH.getName(), showOptions.getTargetHash(), sortedTargetRule, attributesPatternsMatcher);
}
String fullyQualifiedNameAttribute = "fully_qualified_name";
if (attributesPatternsMatcher.matches(fullyQualifiedNameAttribute)) {
sortedTargetRule.put(fullyQualifiedNameAttribute, targetNode.getBuildTarget().getFullyQualifiedName());
}
String cellPathAttribute = "buck.cell_path";
if (isShowCellPath() && attributesPatternsMatcher.matches(cellPathAttribute)) {
sortedTargetRule.put(cellPathAttribute, targetNode.getBuildTarget().getCellPath());
}
// Print the build rule information as JSON.
StringWriter stringWriter = new StringWriter();
try {
mapper.writerWithDefaultPrettyPrinter().writeValue(stringWriter, sortedTargetRule);
} catch (IOException e) {
// Shouldn't be possible while writing to a StringWriter...
throw new RuntimeException(e);
}
String output = stringWriter.getBuffer().toString();
if (targetNodeIterator.hasNext()) {
output += ",";
}
params.getConsole().getStdOut().println(output);
}
params.getConsole().getStdOut().println("]");
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.annotations.VisibleForTesting in project buck by facebook.
the class DotnetFramework method resolveFramework.
// TODO(t8390117): Use official Win32 APIs to find the framework
@VisibleForTesting
static DotnetFramework resolveFramework(FileSystem osFilesystem, ImmutableMap<String, String> env, FrameworkVersion version) {
Path programFiles = findProgramFiles(osFilesystem, env);
Path baseDir = programFiles.resolve("Reference Assemblies").resolve("Microsoft").resolve("Framework");
Path frameworkDir;
switch(version) {
case NET35:
frameworkDir = baseDir.resolve("v3.5");
break;
case NET40:
// fall through
case NET45:
// fall through
case NET46:
frameworkDir = baseDir.resolve(".NETFramework").resolve(version.getDirName());
break;
// Which we should never reach
default:
throw new HumanReadableException("Unknown .net framework version: %s", version);
}
if (!Files.exists(frameworkDir)) {
throw new HumanReadableException("Resolved framework dir for %s does not exist: %s", version, frameworkDir);
}
if (!Files.isDirectory(frameworkDir)) {
throw new HumanReadableException("Resolved framework directory is not a directory: %s", frameworkDir);
}
return new DotnetFramework(version, frameworkDir);
}
Aggregations