Search in sources :

Example 86 with ImmutableMap

use of com.google.common.collect.ImmutableMap in project buck by facebook.

the class ParserBenchmark method setUpBenchmark.

@BeforeExperiment
public void setUpBenchmark() throws Exception {
    tempDir.before();
    Path root = tempDir.getRoot();
    Files.createDirectories(root);
    filesystem = new ProjectFilesystem(root);
    Path fbJavaRoot = root.resolve(root.resolve("java/com/facebook"));
    Files.createDirectories(fbJavaRoot);
    for (int i = 0; i < targetCount; i++) {
        Path targetRoot = fbJavaRoot.resolve(String.format("target_%d", i));
        Files.createDirectories(targetRoot);
        Path buckFile = targetRoot.resolve("BUCK");
        Files.createFile(buckFile);
        Files.write(buckFile, ("java_library(name = 'foo', srcs = ['A.java'])\n" + "genrule(name = 'baz', out = '')\n").getBytes("UTF-8"));
        Path javaFile = targetRoot.resolve("A.java");
        Files.createFile(javaFile);
        Files.write(javaFile, String.format("package com.facebook.target_%d; class A {}", i).getBytes("UTF-8"));
    }
    ImmutableMap.Builder<String, ImmutableMap<String, String>> configSectionsBuilder = ImmutableMap.builder();
    if (threadCount > 1) {
        configSectionsBuilder.put("project", ImmutableMap.of("parallel_parsing", "true", "parsing_threads", Integer.toString(threadCount)));
    }
    BuckConfig config = FakeBuckConfig.builder().setFilesystem(filesystem).setSections(configSectionsBuilder.build()).build();
    cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
    eventBus = BuckEventBusFactory.newInstance();
    executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(threadCount));
    DefaultTypeCoercerFactory typeCoercerFactory = new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance());
    ConstructorArgMarshaller marshaller = new ConstructorArgMarshaller(typeCoercerFactory);
    parser = new Parser(new BroadcastEventListener(), config.getView(ParserConfig.class), typeCoercerFactory, marshaller);
}
Also used : Path(java.nio.file.Path) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BroadcastEventListener(com.facebook.buck.event.listener.BroadcastEventListener) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) ImmutableMap(com.google.common.collect.ImmutableMap) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) BeforeExperiment(com.google.caliper.BeforeExperiment)

Example 87 with ImmutableMap

use of com.google.common.collect.ImmutableMap in project buck by facebook.

the class KnownBuildRuleTypesTest method whenJavacIsSetInBuckConfigConfiguredRulesCreateJavaLibraryRuleWithDifferentRuleKey.

@Test
public void whenJavacIsSetInBuckConfigConfiguredRulesCreateJavaLibraryRuleWithDifferentRuleKey() throws Exception {
    final Path javac;
    if (Platform.detect() == Platform.WINDOWS) {
        javac = Paths.get("C:/Windows/system32/rundll32.exe");
    } else {
        javac = temporaryFolder.newExecutableFile();
    }
    ProjectFilesystem filesystem = new ProjectFilesystem(temporaryFolder.getRoot());
    ImmutableMap<String, ImmutableMap<String, String>> sections = ImmutableMap.of("tools", ImmutableMap.of("javac", javac.toString()));
    BuckConfig buckConfig = FakeBuckConfig.builder().setFilesystem(filesystem).setSections(sections).build();
    KnownBuildRuleTypes buildRuleTypes = KnownBuildRuleTypesTestUtil.getDefaultKnownBuildRuleTypes(filesystem, environment);
    DefaultJavaLibrary libraryRule = createJavaLibrary(buildRuleTypes);
    ProcessExecutor processExecutor = createExecutor(javac.toString(), "fakeVersion 0.1");
    KnownBuildRuleTypes configuredBuildRuleTypes = KnownBuildRuleTypes.createBuilder(buckConfig, filesystem, processExecutor, new FakeAndroidDirectoryResolver()).build();
    DefaultJavaLibrary configuredRule = createJavaLibrary(configuredBuildRuleTypes);
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
    SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
    FakeFileHashCache hashCache = new FakeFileHashCache(ImmutableMap.of(javac, MorePaths.asByteSource(javac).hash(Hashing.sha1())));
    RuleKey configuredKey = new DefaultRuleKeyFactory(0, hashCache, resolver, ruleFinder).build(configuredRule);
    RuleKey libraryKey = new DefaultRuleKeyFactory(0, hashCache, resolver, ruleFinder).build(libraryRule);
    assertNotEquals(libraryKey, configuredKey);
}
Also used : Path(java.nio.file.Path) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) ImmutableMap(com.google.common.collect.ImmutableMap) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) FakeAndroidDirectoryResolver(com.facebook.buck.android.FakeAndroidDirectoryResolver) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 88 with ImmutableMap

use of com.google.common.collect.ImmutableMap in project buck by facebook.

the class KnownBuildRuleTypesTest method ocamlUsesConfiguredDefaultPlatform.

@Test
public void ocamlUsesConfiguredDefaultPlatform() throws Exception {
    ProjectFilesystem filesystem = new ProjectFilesystem(temporaryFolder.getRoot());
    Flavor flavor = InternalFlavor.of("flavor");
    ImmutableMap<String, ImmutableMap<String, String>> sections = ImmutableMap.of("cxx", ImmutableMap.of("default_platform", flavor.toString()), "cxx#" + flavor, ImmutableMap.of());
    BuckConfig buckConfig = FakeBuckConfig.builder().setSections(sections).build();
    KnownBuildRuleTypes knownBuildRuleTypes = KnownBuildRuleTypes.createBuilder(buckConfig, filesystem, createExecutor(), new FakeAndroidDirectoryResolver()).build();
    OcamlLibraryDescription ocamlLibraryDescription = (OcamlLibraryDescription) knownBuildRuleTypes.getDescription(knownBuildRuleTypes.getBuildRuleType("ocaml_library"));
    assertThat(ocamlLibraryDescription.getOcamlBuckConfig().getCxxPlatform(), Matchers.equalTo(knownBuildRuleTypes.getCxxPlatforms().getValue(flavor)));
    OcamlBinaryDescription ocamlBinaryDescription = (OcamlBinaryDescription) knownBuildRuleTypes.getDescription(knownBuildRuleTypes.getBuildRuleType("ocaml_binary"));
    assertThat(ocamlBinaryDescription.getOcamlBuckConfig().getCxxPlatform(), Matchers.equalTo(knownBuildRuleTypes.getCxxPlatforms().getValue(flavor)));
}
Also used : FakeAndroidDirectoryResolver(com.facebook.buck.android.FakeAndroidDirectoryResolver) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) OcamlLibraryDescription(com.facebook.buck.ocaml.OcamlLibraryDescription) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) OcamlBinaryDescription(com.facebook.buck.ocaml.OcamlBinaryDescription) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 89 with ImmutableMap

use of com.google.common.collect.ImmutableMap in project buck by facebook.

the class KnownBuildRuleTypesTest method canOverrideDefaultHostPlatform.

@Test
public void canOverrideDefaultHostPlatform() throws Exception {
    ProjectFilesystem filesystem = new ProjectFilesystem(temporaryFolder.getRoot());
    Flavor flavor = InternalFlavor.of("flavor");
    String flag = "-flag";
    ImmutableMap<String, ImmutableMap<String, String>> sections = ImmutableMap.of("cxx#" + flavor, ImmutableMap.of("cflags", flag));
    BuckConfig buckConfig = FakeBuckConfig.builder().setSections(sections).build();
    KnownBuildRuleTypes knownBuildRuleTypes = KnownBuildRuleTypes.createBuilder(buckConfig, filesystem, createExecutor(), new FakeAndroidDirectoryResolver()).build();
    assertThat(knownBuildRuleTypes.getCxxPlatforms().getValue(flavor).getCflags(), Matchers.contains(flag));
}
Also used : FakeAndroidDirectoryResolver(com.facebook.buck.android.FakeAndroidDirectoryResolver) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 90 with ImmutableMap

use of com.google.common.collect.ImmutableMap in project buck by facebook.

the class KnownBuildRuleTypesTest method canSetDefaultPlatformToDefault.

@Test
public void canSetDefaultPlatformToDefault() throws Exception {
    ProjectFilesystem filesystem = new ProjectFilesystem(temporaryFolder.getRoot());
    ImmutableMap<String, ImmutableMap<String, String>> sections = ImmutableMap.of("cxx", ImmutableMap.of("default_platform", "default"));
    BuckConfig buckConfig = FakeBuckConfig.builder().setSections(sections).build();
    // This would throw if "default" weren't available as a platform.
    KnownBuildRuleTypes.createBuilder(buckConfig, filesystem, createExecutor(), new FakeAndroidDirectoryResolver()).build();
}
Also used : FakeAndroidDirectoryResolver(com.facebook.buck.android.FakeAndroidDirectoryResolver) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)702 Map (java.util.Map)346 Test (org.junit.Test)195 HashMap (java.util.HashMap)144 ImmutableList (com.google.common.collect.ImmutableList)126 Path (java.nio.file.Path)104 List (java.util.List)100 ImmutableSet (com.google.common.collect.ImmutableSet)89 IOException (java.io.IOException)84 ArrayList (java.util.ArrayList)74 Set (java.util.Set)69 Optional (java.util.Optional)61 BuildTarget (com.facebook.buck.model.BuildTarget)57 File (java.io.File)57 Collectors (java.util.stream.Collectors)45 HashSet (java.util.HashSet)44 SourcePath (com.facebook.buck.rules.SourcePath)41 VisibleForTesting (com.google.common.annotations.VisibleForTesting)39 Nullable (javax.annotation.Nullable)39 LinkedHashMap (java.util.LinkedHashMap)36