Search in sources :

Example 21 with VisibleForTesting

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;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 22 with VisibleForTesting

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);
}
Also used : UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) BuildTarget(com.facebook.buck.model.BuildTarget) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 23 with VisibleForTesting

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;
}
Also used : UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) BuildTarget(com.facebook.buck.model.BuildTarget) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 24 with VisibleForTesting

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("]");
}
Also used : PatternsMatcher(com.facebook.buck.util.PatternsMatcher) TargetNode(com.facebook.buck.rules.TargetNode) StringWriter(java.io.StringWriter) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 25 with VisibleForTesting

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);
}
Also used : Path(java.nio.file.Path) HumanReadableException(com.facebook.buck.util.HumanReadableException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1954 IOException (java.io.IOException)284 ArrayList (java.util.ArrayList)214 Map (java.util.Map)156 HashMap (java.util.HashMap)147 List (java.util.List)113 File (java.io.File)94 ImmutableMap (com.google.common.collect.ImmutableMap)72 HashSet (java.util.HashSet)67 Path (org.apache.hadoop.fs.Path)63 ImmutableList (com.google.common.collect.ImmutableList)60 Path (java.nio.file.Path)60 Set (java.util.Set)52 Matcher (java.util.regex.Matcher)46 Collectors (java.util.stream.Collectors)46 Collection (java.util.Collection)39 Optional (java.util.Optional)38 NotNull (org.jetbrains.annotations.NotNull)37 ImmutableSet (com.google.common.collect.ImmutableSet)34 TreeMap (java.util.TreeMap)34