Search in sources :

Example 11 with ImmutableMap

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableMap in project buck by facebook.

the class CxxDescriptionEnhancer method parseOnlyPlatformHeaders.

static ImmutableMap<String, SourcePath> parseOnlyPlatformHeaders(BuildTarget buildTarget, BuildRuleResolver resolver, SourcePathRuleFinder ruleFinder, SourcePathResolver sourcePathResolver, CxxPlatform cxxPlatform, String headersParameterName, SourceList headers, String platformHeadersParameterName, PatternMatchedCollection<SourceList> platformHeaders) throws NoSuchBuildTargetException {
    ImmutableMap.Builder<String, SourcePath> parsed = ImmutableMap.builder();
    java.util.function.Function<SourcePath, SourcePath> fixup = path -> {
        try {
            return CxxGenruleDescription.fixupSourcePath(resolver, ruleFinder, cxxPlatform, path);
        } catch (NoSuchBuildTargetException e) {
            throw new RuntimeException(e);
        }
    };
    // Include all normal exported headers that are generated by `cxx_genrule`.
    parsed.putAll(headers.toNameMap(buildTarget, sourcePathResolver, headersParameterName, path -> CxxGenruleDescription.wrapsCxxGenrule(ruleFinder, path), fixup));
    // Include all platform specific headers.
    for (SourceList sourceList : platformHeaders.getMatchingValues(cxxPlatform.getFlavor().toString())) {
        parsed.putAll(sourceList.toNameMap(buildTarget, sourcePathResolver, platformHeadersParameterName, path -> true, fixup));
    }
    return parsed.build();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) PatternMatchedCollection(com.facebook.buck.rules.coercer.PatternMatchedCollection) ImmutableCollection(com.google.common.collect.ImmutableCollection) RichStream(com.facebook.buck.util.RichStream) InternalFlavor(com.facebook.buck.model.InternalFlavor) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) SymlinkTree(com.facebook.buck.rules.SymlinkTree) FlavorDomain(com.facebook.buck.model.FlavorDomain) Matcher(java.util.regex.Matcher) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) StringArg(com.facebook.buck.rules.args.StringArg) Map(java.util.Map) SourceList(com.facebook.buck.rules.coercer.SourceList) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) RuleKeyObjectSink(com.facebook.buck.rules.RuleKeyObjectSink) Path(java.nio.file.Path) JsonConcatenate(com.facebook.buck.json.JsonConcatenate) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) TargetGraph(com.facebook.buck.rules.TargetGraph) BuildTarget(com.facebook.buck.model.BuildTarget) RuleKeyAppendableFunction(com.facebook.buck.rules.args.RuleKeyAppendableFunction) SourceWithFlags(com.facebook.buck.rules.SourceWithFlags) Predicate(com.google.common.base.Predicate) Optional(java.util.Optional) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Pattern(java.util.regex.Pattern) Joiner(com.google.common.base.Joiner) CellPathResolver(com.facebook.buck.rules.CellPathResolver) SourcePathArg(com.facebook.buck.rules.args.SourcePathArg) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) HashMap(java.util.HashMap) BuildRule(com.facebook.buck.rules.BuildRule) ImmutableList(com.google.common.collect.ImmutableList) Files(com.google.common.io.Files) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) Suppliers(com.google.common.base.Suppliers) StreamSupport(java.util.stream.StreamSupport) StringWithMacros(com.facebook.buck.rules.macros.StringWithMacros) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) MoreCollectors(com.facebook.buck.util.MoreCollectors) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Logger(com.facebook.buck.log.Logger) Functions(com.google.common.base.Functions) FileListableLinkerInputArg(com.facebook.buck.rules.args.FileListableLinkerInputArg) HumanReadableException(com.facebook.buck.util.HumanReadableException) QueryUtils(com.facebook.buck.rules.query.QueryUtils) Arg(com.facebook.buck.rules.args.Arg) Paths(java.nio.file.Paths) CommandTool(com.facebook.buck.rules.CommandTool) StringWithMacrosArg(com.facebook.buck.rules.args.StringWithMacrosArg) LocationMacroExpander(com.facebook.buck.rules.macros.LocationMacroExpander) Preconditions(com.google.common.base.Preconditions) Flavor(com.facebook.buck.model.Flavor) MacroHandler(com.facebook.buck.rules.macros.MacroHandler) VisibleForTesting(com.google.common.annotations.VisibleForTesting) BuildTargets(com.facebook.buck.model.BuildTargets) SourceList(com.facebook.buck.rules.coercer.SourceList) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 12 with ImmutableMap

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableMap in project buck by facebook.

the class TargetNodeTranslator method translateNode.

/**
   * @return a copy of the given {@link TargetNode} with all found {@link BuildTarget}s translated,
   *         or {@link Optional#empty()} if the node requires no translation.
   */
public <A> Optional<TargetNode<A, ?>> translateNode(TargetNode<A, ?> node) {
    CellPathResolver cellPathResolver = node.getCellNames();
    BuildTargetPatternParser<BuildTargetPattern> pattern = BuildTargetPatternParser.forBaseName(node.getBuildTarget().getBaseName());
    Optional<BuildTarget> target = translateBuildTarget(node.getBuildTarget());
    Optional<A> constructorArg = translateConstructorArg(cellPathResolver, pattern, node);
    Optional<ImmutableSet<BuildTarget>> declaredDeps = translateSet(cellPathResolver, pattern, node.getDeclaredDeps());
    Optional<ImmutableSet<BuildTarget>> extraDeps = translateSet(cellPathResolver, pattern, node.getExtraDeps());
    Optional<ImmutableMap<BuildTarget, Version>> newSelectedVersions = getSelectedVersions(node.getBuildTarget());
    Optional<ImmutableMap<BuildTarget, Version>> oldSelectedVersions = node.getSelectedVersions();
    Optional<Optional<ImmutableMap<BuildTarget, Version>>> selectedVersions = oldSelectedVersions.equals(newSelectedVersions) ? Optional.empty() : Optional.of(newSelectedVersions);
    // If nothing has changed, don't generate a new node.
    if (!target.isPresent() && !constructorArg.isPresent() && !declaredDeps.isPresent() && !extraDeps.isPresent() && !selectedVersions.isPresent()) {
        return Optional.empty();
    }
    return Optional.of(node.withTargetConstructorArgDepsAndSelectedVerisons(target.orElse(node.getBuildTarget()), constructorArg.orElse(node.getConstructorArg()), declaredDeps.orElse(node.getDeclaredDeps()), extraDeps.orElse(node.getExtraDeps()), selectedVersions.orElse(oldSelectedVersions)));
}
Also used : BuildTargetPattern(com.facebook.buck.model.BuildTargetPattern) Optional(java.util.Optional) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget) CellPathResolver(com.facebook.buck.rules.CellPathResolver)

Example 13 with ImmutableMap

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableMap in project buck by facebook.

the class CompileStringsStepTest method testScrapePluralsNodes.

@Test
public void testScrapePluralsNodes() throws IOException, SAXException {
    String xmlInput = "<plurals name='name1' gender='unknown'>" + "<item quantity='zero'>%d people saw this</item>" + "<item quantity='one'>%d person saw this</item>" + "<item quantity='many'>%d people saw this</item>" + "</plurals>" + "<plurals name='name1_f1gender' gender='female'>" + "<item quantity='zero'>%d people saw this f1</item>" + "<item quantity='one'>%d person saw this f1</item>" + "<item quantity='many'>%d people saw this f1</item>" + "</plurals>" + "<plurals name='name2' gender='unknown'>" + "<item quantity='zero'>%d people ate this</item>" + "<item quantity='many'>%d people ate this</item>" + "</plurals>" + "<plurals name='name2_m2gender' gender='male'>" + "<item quantity='zero'>%d people ate this m2</item>" + "<item quantity='many'>%d people ate this m2</item>" + "</plurals>" + // Test empty array.
    "<plurals name='name3' gender='unknown'></plurals>" + // Ignored since "name2" already found.
    "<plurals name='name2' gender='unknown'></plurals>";
    NodeList pluralsNodes = XmlDomParser.parse(createResourcesXml(xmlInput)).getElementsByTagName("plurals");
    EnumMap<Gender, ImmutableMap<String, String>> map1 = Maps.newEnumMap(Gender.class);
    map1.put(Gender.unknown, ImmutableMap.of("zero", "%d people saw this", "one", "%d person saw this", "many", "%d people saw this"));
    map1.put(Gender.female, ImmutableMap.of("zero", "%d people saw this f1", "one", "%d person saw this f1", "many", "%d people saw this f1"));
    EnumMap<Gender, ImmutableMap<String, String>> map2 = Maps.newEnumMap(Gender.class);
    map2.put(Gender.unknown, ImmutableMap.of("zero", "%d people ate this", "many", "%d people ate this"));
    map2.put(Gender.male, ImmutableMap.of("zero", "%d people ate this m2", "many", "%d people ate this m2"));
    EnumMap<Gender, ImmutableMap<String, String>> map3 = Maps.newEnumMap(Gender.class);
    map3.put(Gender.unknown, ImmutableMap.of());
    Map<Integer, EnumMap<Gender, ImmutableMap<String, String>>> pluralsMap = Maps.newHashMap();
    CompileStringsStep step = createNonExecutingStep();
    step.addPluralsResourceNameToIdMap(ImmutableMap.of("name1", 1, "name2", 2, "name3", 3));
    step.scrapePluralsNodes(pluralsNodes, pluralsMap);
    assertEquals("Incorrect map of resource id to plural values.", ImmutableMap.of(1, map1, 2, map2, 3, map3), pluralsMap);
}
Also used : NodeList(org.w3c.dom.NodeList) Gender(com.facebook.buck.android.StringResources.Gender) EnumMap(java.util.EnumMap) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 14 with ImmutableMap

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableMap in project buck by facebook.

the class CompileStringsStepTest method testScrapeNodesWithSameName.

@Test
public void testScrapeNodesWithSameName() throws IOException, SAXException {
    String xmlInput = "<string name='name1' gender='unknown'>1</string>" + "<string name='name1_f1gender' gender='female'>1 f1</string>" + "<plurals name='name1' gender='unknown'>" + "<item quantity='one'>2</item>" + "<item quantity='other'>3</item>" + "</plurals>" + "<plurals name='name1_f1gender' gender='female'>" + "<item quantity='one'>2 f1</item>" + "<item quantity='other'>3 f1</item>" + "</plurals>" + "<string-array name='name1' gender='unknown'>" + "<item>4</item>" + "<item>5</item>" + "</string-array>" + "<string-array name='name1_f1gender' gender='female'>" + "<item>4 f1</item>" + "<item>5 f1</item>" + "</string-array>";
    NodeList stringNodes = XmlDomParser.parse(createResourcesXml(xmlInput)).getElementsByTagName("string");
    NodeList pluralsNodes = XmlDomParser.parse(createResourcesXml(xmlInput)).getElementsByTagName("plurals");
    NodeList arrayNodes = XmlDomParser.parse(createResourcesXml(xmlInput)).getElementsByTagName("string-array");
    Map<Integer, EnumMap<Gender, String>> stringMap = Maps.newTreeMap();
    Map<Integer, EnumMap<Gender, ImmutableMap<String, String>>> pluralsMap = Maps.newTreeMap();
    Map<Integer, EnumMap<Gender, ImmutableList<String>>> arraysMap = Maps.newTreeMap();
    EnumMap<Gender, String> map1 = Maps.newEnumMap(Gender.class);
    map1.put(Gender.unknown, "1");
    map1.put(Gender.female, "1 f1");
    EnumMap<Gender, Map<String, String>> map2 = Maps.newEnumMap(Gender.class);
    map2.put(Gender.unknown, ImmutableMap.of("one", "2", "other", "3"));
    map2.put(Gender.female, ImmutableMap.of("one", "2 f1", "other", "3 f1"));
    EnumMap<Gender, ImmutableList<String>> map3 = Maps.newEnumMap(Gender.class);
    map3.put(Gender.unknown, ImmutableList.of("4", "5"));
    map3.put(Gender.female, ImmutableList.of("4 f1", "5 f1"));
    CompileStringsStep step = createNonExecutingStep();
    step.addStringResourceNameToIdMap(ImmutableMap.of("name1", 1));
    step.addPluralsResourceNameToIdMap(ImmutableMap.of("name1", 2));
    step.addArrayResourceNameToIdMap(ImmutableMap.of("name1", 3));
    step.scrapeStringNodes(stringNodes, stringMap);
    step.scrapePluralsNodes(pluralsNodes, pluralsMap);
    step.scrapeStringArrayNodes(arrayNodes, arraysMap);
    assertEquals("Incorrect map of resource id to string.", ImmutableMap.of(1, map1), stringMap);
    assertEquals("Incorrect map of resource id to plurals.", ImmutableMap.of(2, map2), pluralsMap);
    assertEquals("Incorrect map of resource id to string arrays.", ImmutableMap.of(3, map3), arraysMap);
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) NodeList(org.w3c.dom.NodeList) Gender(com.facebook.buck.android.StringResources.Gender) EnumMap(java.util.EnumMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) EnumMap(java.util.EnumMap) Test(org.junit.Test)

Example 15 with ImmutableMap

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableMap in project buck by facebook.

the class AndroidNativeLibsPackageableGraphEnhancerTest method testNdkLibrary.

@Test
public void testNdkLibrary() throws Exception {
    BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver sourcePathResolver = new SourcePathResolver(new SourcePathRuleFinder(ruleResolver));
    NdkLibrary ndkLibrary = new NdkLibraryBuilder(BuildTargetFactory.newInstance("//:ndklib")).build(ruleResolver);
    BuildTarget target = BuildTargetFactory.newInstance("//:target");
    BuildRuleParams originalParams = new FakeBuildRuleParamsBuilder(target).setDeclaredDeps(ImmutableSortedSet.of(ndkLibrary)).build();
    APKModuleGraph apkModuleGraph = new APKModuleGraph(TargetGraph.EMPTY, target, Optional.empty());
    AndroidNativeLibsPackageableGraphEnhancer enhancer = new AndroidNativeLibsPackageableGraphEnhancer(ruleResolver, originalParams, ImmutableMap.of(), ImmutableSet.of(), CxxPlatformUtils.DEFAULT_CONFIG, /* nativeLibraryMergeMap */
    Optional.empty(), /* nativeLibraryMergeGlue */
    Optional.empty(), AndroidBinary.RelinkerMode.DISABLED, apkModuleGraph);
    AndroidPackageableCollector collector = new AndroidPackageableCollector(target, ImmutableSet.of(), ImmutableSet.of(), apkModuleGraph);
    collector.addPackageables(AndroidPackageableCollector.getPackageableRules(ImmutableSet.of(ndkLibrary)));
    Optional<ImmutableMap<APKModule, CopyNativeLibraries>> copyNativeLibrariesOptional = enhancer.enhance(collector.build()).getCopyNativeLibraries();
    CopyNativeLibraries copyNativeLibraries = copyNativeLibrariesOptional.get().get(apkModuleGraph.getRootAPKModule());
    assertThat(copyNativeLibraries.getStrippedObjectDescriptions(), Matchers.empty());
    assertThat(copyNativeLibraries.getNativeLibDirectories().stream().map(sourcePathResolver::getRelativePath).collect(MoreCollectors.toImmutableList()), Matchers.contains(ndkLibrary.getLibraryPath()));
}
Also used : FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ImmutableMap(com.google.common.collect.ImmutableMap) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1261 Map (java.util.Map)662 Test (org.junit.Test)309 ImmutableList (com.google.common.collect.ImmutableList)300 List (java.util.List)288 HashMap (java.util.HashMap)269 ImmutableSet (com.google.common.collect.ImmutableSet)211 IOException (java.io.IOException)202 Optional (java.util.Optional)190 Set (java.util.Set)168 ArrayList (java.util.ArrayList)158 Path (java.nio.file.Path)151 Collectors (java.util.stream.Collectors)133 File (java.io.File)117 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)102 Collection (java.util.Collection)93 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)85 Test (org.testng.annotations.Test)85 HashSet (java.util.HashSet)83 Collections (java.util.Collections)78