Search in sources :

Example 16 with ImmutableMap

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

the class AppleCxxPlatformsTest method constructCompileRuleKeys.

// Create and return some rule keys from a dummy source for the given platforms.
private ImmutableMap<Flavor, RuleKey> constructCompileRuleKeys(Operation operation, ImmutableMap<Flavor, AppleCxxPlatform> cxxPlatforms) {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    String source = "source.cpp";
    DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, FakeFileHashCache.createFromStrings(ImmutableMap.<String, String>builder().put("source.cpp", Strings.repeat("a", 40)).build()), pathResolver, ruleFinder);
    BuildTarget target = BuildTargetFactory.newInstance("//:target");
    ImmutableMap.Builder<Flavor, RuleKey> ruleKeys = ImmutableMap.builder();
    for (Map.Entry<Flavor, AppleCxxPlatform> entry : cxxPlatforms.entrySet()) {
        CxxSourceRuleFactory cxxSourceRuleFactory = CxxSourceRuleFactory.builder().setParams(new FakeBuildRuleParamsBuilder(target).build()).setResolver(resolver).setPathResolver(pathResolver).setRuleFinder(ruleFinder).setCxxBuckConfig(CxxPlatformUtils.DEFAULT_CONFIG).setCxxPlatform(entry.getValue().getCxxPlatform()).setPicType(CxxSourceRuleFactory.PicType.PIC).build();
        CxxPreprocessAndCompile rule;
        switch(operation) {
            case PREPROCESS_AND_COMPILE:
                rule = cxxSourceRuleFactory.createPreprocessAndCompileBuildRule(source, CxxSource.of(CxxSource.Type.CXX, new FakeSourcePath(source), ImmutableList.of()));
                break;
            case COMPILE:
                rule = cxxSourceRuleFactory.createCompileBuildRule(source, CxxSource.of(CxxSource.Type.CXX_CPP_OUTPUT, new FakeSourcePath(source), ImmutableList.of()));
                break;
            default:
                throw new IllegalStateException();
        }
        ruleKeys.put(entry.getKey(), ruleKeyFactory.build(rule));
    }
    return ruleKeys.build();
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) CxxPreprocessAndCompile(com.facebook.buck.cxx.CxxPreprocessAndCompile) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) RuleKey(com.facebook.buck.rules.RuleKey) Matchers.containsString(org.hamcrest.Matchers.containsString) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ImmutableMap(com.google.common.collect.ImmutableMap) CxxSourceRuleFactory(com.facebook.buck.cxx.CxxSourceRuleFactory) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 17 with ImmutableMap

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

the class ProjectGeneratorTest method setUp.

@Before
public void setUp() throws InterruptedException, IOException {
    assumeTrue(Platform.detect() == Platform.MACOS || Platform.detect() == Platform.LINUX);
    clock = new SettableFakeClock(0, 0);
    fakeProjectFilesystem = new FakeProjectFilesystem(clock);
    projectCell = (new TestCellBuilder()).setFilesystem(fakeProjectFilesystem).build();
    projectFilesystem = projectCell.getFilesystem();
    rootPath = projectFilesystem.getRootPath();
    // Add files and directories used to test resources.
    projectFilesystem.createParentDirs(Paths.get("foodir", "foo.png"));
    projectFilesystem.writeContentsToPath("", Paths.get("foodir", "foo.png"));
    projectFilesystem.writeContentsToPath("", Paths.get("bar.png"));
    fakeProjectFilesystem.touch(Paths.get("Base.lproj", "Bar.storyboard"));
    halideBuckConfig = HalideLibraryBuilder.createDefaultHalideConfig(fakeProjectFilesystem);
    ImmutableMap<String, ImmutableMap<String, String>> sections = ImmutableMap.of("cxx", ImmutableMap.of("cflags", "-Wno-deprecated -Wno-conversion", "cxxflags", "-Wundeclared-selector -Wno-objc-designated-initializers"), "apple", ImmutableMap.of("force_dsym_mode_in_build_with_buck", "false"), "swift", ImmutableMap.of("version", "1.23"));
    BuckConfig config = FakeBuckConfig.builder().setSections(sections).build();
    cxxBuckConfig = new CxxBuckConfig(config);
    appleConfig = new AppleConfig(config);
    swiftBuckConfig = new SwiftBuckConfig(config);
}
Also used : AppleConfig(com.facebook.buck.apple.AppleConfig) ReactNativeBuckConfig(com.facebook.buck.js.ReactNativeBuckConfig) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) SwiftBuckConfig(com.facebook.buck.swift.SwiftBuckConfig) HalideBuckConfig(com.facebook.buck.halide.HalideBuckConfig) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SettableFakeClock(com.facebook.buck.timing.SettableFakeClock) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NSString(com.dd.plist.NSString) SwiftBuckConfig(com.facebook.buck.swift.SwiftBuckConfig) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) ImmutableMap(com.google.common.collect.ImmutableMap) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Before(org.junit.Before)

Example 18 with ImmutableMap

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

the class ProjectGeneratorTest method testAppleLibraryDependentsInheritSearchPaths.

@Test
public void testAppleLibraryDependentsInheritSearchPaths() throws IOException {
    ImmutableSortedMap<String, ImmutableMap<String, String>> configs = ImmutableSortedMap.of("Debug", ImmutableMap.of("HEADER_SEARCH_PATHS", "headers", "USER_HEADER_SEARCH_PATHS", "user_headers", "LIBRARY_SEARCH_PATHS", "libraries", "FRAMEWORK_SEARCH_PATHS", "frameworks"));
    BuildTarget libraryTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
    TargetNode<?, ?> libraryNode = AppleLibraryBuilder.createBuilder(libraryTarget).setConfigs(configs).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo.m")))).setFrameworks(ImmutableSortedSet.of(FrameworkPath.ofSourceTreePath(new SourceTreePath(PBXReference.SourceTree.SDKROOT, Paths.get("Library.framework"), Optional.empty())))).build();
    BuildTarget testTarget = BuildTarget.builder(rootPath, "//foo", "xctest").build();
    TargetNode<?, ?> testNode = AppleTestBuilder.createBuilder(testTarget).setConfigs(configs).setInfoPlist(new FakeSourcePath("Info.plist")).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("fooTest.m")))).setFrameworks(ImmutableSortedSet.of(FrameworkPath.ofSourceTreePath(new SourceTreePath(PBXReference.SourceTree.SDKROOT, Paths.get("Test.framework"), Optional.empty())))).setDeps(ImmutableSortedSet.of(libraryTarget)).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(libraryNode, testNode), ImmutableSet.of());
    projectGenerator.createXcodeProjects();
    PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:xctest");
    ImmutableMap<String, String> settings = getBuildSettings(testTarget, target, "Debug");
    assertEquals("headers " + "../buck-out/gen/_p/ptQfVNNRRE-priv/.hmap " + "../buck-out/gen/_p/ptQfVNNRRE-pub/.hmap " + "../buck-out/gen/_p/CwkbTNOBmb-pub/.hmap " + "../buck-out", settings.get("HEADER_SEARCH_PATHS"));
    assertEquals("user_headers", settings.get("USER_HEADER_SEARCH_PATHS"));
    assertEquals("libraries $BUILT_PRODUCTS_DIR", settings.get("LIBRARY_SEARCH_PATHS"));
    assertEquals("frameworks $BUILT_PRODUCTS_DIR $SDKROOT", settings.get("FRAMEWORK_SEARCH_PATHS"));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) BuildTarget(com.facebook.buck.model.BuildTarget) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NSString(com.dd.plist.NSString) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 19 with ImmutableMap

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

the class ProjectGeneratorTest method testAppleLibraryWithoutHeaderMaps.

@Test
public void testAppleLibraryWithoutHeaderMaps() throws IOException {
    ImmutableSortedMap<String, ImmutableMap<String, String>> configs = ImmutableSortedMap.of("Debug", ImmutableMap.<String, String>of());
    BuildTarget libraryTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
    TargetNode<?, ?> libraryNode = AppleLibraryBuilder.createBuilder(libraryTarget).setConfigs(configs).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo.m")))).build();
    BuildTarget testTarget = BuildTarget.builder(rootPath, "//foo", "xctest").build();
    TargetNode<?, ?> testNode = AppleTestBuilder.createBuilder(testTarget).setConfigs(configs).setInfoPlist(new FakeSourcePath("Info.plist")).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("fooTest.m")))).setDeps(ImmutableSortedSet.of(libraryTarget)).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(libraryNode, testNode), ImmutableSet.of(ProjectGenerator.Option.DISABLE_HEADER_MAPS));
    projectGenerator.createXcodeProjects();
    PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:xctest");
    ImmutableMap<String, String> settings = getBuildSettings(testTarget, target, "Debug");
    assertEquals("$(inherited) " + "../buck-out/gen/_p/ptQfVNNRRE-priv " + "../buck-out/gen/_p/ptQfVNNRRE-pub " + "../buck-out/gen/_p/CwkbTNOBmb-pub " + "../buck-out", settings.get("HEADER_SEARCH_PATHS"));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) BuildTarget(com.facebook.buck.model.BuildTarget) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NSString(com.dd.plist.NSString) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 20 with ImmutableMap

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

the class ProjectGeneratorTest method assertThatHeaderMapWithoutSymLinksContains.

private void assertThatHeaderMapWithoutSymLinksContains(Path root, ImmutableMap<String, String> content) throws IOException {
    // Read the tree's header map.
    byte[] headerMapBytes;
    try (InputStream headerMapInputStream = projectFilesystem.newFileInputStream(root.resolve(".hmap"))) {
        headerMapBytes = ByteStreams.toByteArray(headerMapInputStream);
    }
    HeaderMap headerMap = HeaderMap.deserialize(headerMapBytes);
    assertNotNull(headerMap);
    assertThat(headerMap.getNumEntries(), equalTo(content.size()));
    for (Map.Entry<String, String> entry : content.entrySet()) {
        String key = entry.getKey();
        Path target = Paths.get(entry.getValue()).toAbsolutePath();
        // Check the header map
        assertThat(headerMap.lookup(key), equalTo(target.toString()));
    }
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) HeaderMap(com.facebook.buck.apple.clang.HeaderMap) InputStream(java.io.InputStream) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NSString(com.dd.plist.NSString) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ImmutableMap(com.google.common.collect.ImmutableMap) HeaderMap(com.facebook.buck.apple.clang.HeaderMap)

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