Search in sources :

Example 61 with FakeSourcePath

use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.

the class ProjectGeneratorTest method testAppleLibraryConfiguresOutputPaths.

@Test
public void testAppleLibraryConfiguresOutputPaths() throws IOException {
    BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
    TargetNode<?, ?> node = AppleLibraryBuilder.createBuilder(buildTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).setHeaderPathPrefix(Optional.of("MyHeaderPathPrefix")).setPrefixHeader(Optional.of(new FakeSourcePath("Foo/Foo-Prefix.pch"))).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node), ImmutableSet.of());
    projectGenerator.createXcodeProjects();
    PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:lib");
    assertThat(target.isa(), equalTo("PBXNativeTarget"));
    assertThat(target.getProductType(), equalTo(ProductType.STATIC_LIBRARY));
    ImmutableMap<String, String> settings = getBuildSettings(buildTarget, target, "Debug");
    assertEquals("../Foo/Foo-Prefix.pch", settings.get("GCC_PREFIX_HEADER"));
    assertEquals("$SYMROOT/$CONFIGURATION$EFFECTIVE_PLATFORM_NAME", settings.get("BUILT_PRODUCTS_DIR"));
    assertEquals("$BUILT_PRODUCTS_DIR", settings.get("CONFIGURATION_BUILD_DIR"));
}
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) Test(org.junit.Test)

Example 62 with FakeSourcePath

use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.

the class NewNativeTargetProjectMutatorTest method testScriptBuildPhase.

@Test
public void testScriptBuildPhase() throws NoSuchBuildTargetException {
    NewNativeTargetProjectMutator mutator = mutatorWithCommonDefaults();
    TargetNode<?, ?> prebuildNode = XcodePrebuildScriptBuilder.createBuilder(BuildTargetFactory.newInstance("//foo:script")).setSrcs(ImmutableSortedSet.of(new FakeSourcePath("script/input.png"))).setOutputs(ImmutableSortedSet.of("helloworld.txt")).setCmd("echo \"hello world!\"").build();
    mutator.setPostBuildRunScriptPhasesFromTargetNodes(ImmutableList.of(prebuildNode));
    NewNativeTargetProjectMutator.Result result = mutator.buildTargetAndAddToProject(generatedProject, true);
    PBXShellScriptBuildPhase phase = getSingletonPhaseByType(result.target, PBXShellScriptBuildPhase.class);
    assertThat("Should set input paths correctly", "../script/input.png", is(equalTo(Iterables.getOnlyElement(phase.getInputPaths()))));
    assertThat("Should set output paths correctly", "helloworld.txt", is(equalTo(Iterables.getOnlyElement(phase.getOutputPaths()))));
    assertEquals("should set script correctly", "echo \"hello world!\"", phase.getShellScript());
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXShellScriptBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXShellScriptBuildPhase) Test(org.junit.Test)

Example 63 with FakeSourcePath

use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.

the class NewNativeTargetProjectMutatorTest method testLibraryHeaderGroups.

@Test
public void testLibraryHeaderGroups() throws NoSuchBuildTargetException {
    NewNativeTargetProjectMutator mutator = mutatorWithCommonDefaults();
    SourcePath foo = new FakeSourcePath("HeaderGroup1/foo.h");
    SourcePath bar = new FakeSourcePath("HeaderGroup1/bar.h");
    SourcePath baz = new FakeSourcePath("HeaderGroup2/baz.h");
    mutator.setPublicHeaders(ImmutableSet.of(bar, baz));
    mutator.setPrivateHeaders(ImmutableSet.of(foo));
    NewNativeTargetProjectMutator.Result result = mutator.buildTargetAndAddToProject(generatedProject, true);
    PBXGroup sourcesGroup = result.targetGroup.get().getOrCreateChildGroupByName("Sources");
    assertThat(sourcesGroup.getChildren(), hasSize(2));
    PBXGroup group1 = (PBXGroup) Iterables.get(sourcesGroup.getChildren(), 0);
    assertEquals("HeaderGroup1", group1.getName());
    assertThat(group1.getChildren(), hasSize(2));
    PBXFileReference fileRefBar = (PBXFileReference) Iterables.get(group1.getChildren(), 0);
    assertEquals("bar.h", fileRefBar.getName());
    PBXFileReference fileRefFoo = (PBXFileReference) Iterables.get(group1.getChildren(), 1);
    assertEquals("foo.h", fileRefFoo.getName());
    PBXGroup group2 = (PBXGroup) Iterables.get(sourcesGroup.getChildren(), 1);
    assertEquals("HeaderGroup2", group2.getName());
    assertThat(group2.getChildren(), hasSize(1));
    PBXFileReference fileRefBaz = (PBXFileReference) Iterables.get(group2.getChildren(), 0);
    assertEquals("baz.h", fileRefBaz.getName());
}
Also used : PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXGroup) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference) Test(org.junit.Test)

Example 64 with FakeSourcePath

use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.

the class NewNativeTargetProjectMutatorTest method testResourcesBuildPhase.

@Test
public void testResourcesBuildPhase() throws NoSuchBuildTargetException {
    NewNativeTargetProjectMutator mutator = mutatorWithCommonDefaults();
    AppleResourceDescription appleResourceDescription = new AppleResourceDescription();
    AppleResourceDescription.Arg arg = createDescriptionArgWithDefaults(appleResourceDescription);
    arg.files = ImmutableSet.of(new FakeSourcePath("foo.png"));
    mutator.setRecursiveResources(ImmutableSet.of(arg));
    NewNativeTargetProjectMutator.Result result = mutator.buildTargetAndAddToProject(generatedProject, true);
    assertHasSingletonPhaseWithEntries(result.target, PBXResourcesBuildPhase.class, ImmutableList.of("$SOURCE_ROOT/../foo.png"));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) AppleResourceDescription(com.facebook.buck.apple.AppleResourceDescription) Test(org.junit.Test)

Example 65 with FakeSourcePath

use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.

the class ProjectGeneratorTest method testCxxLibraryRule.

@Test
public void testCxxLibraryRule() throws IOException {
    BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
    TargetNode<?, ?> cxxNode = new CxxLibraryBuilder(buildTarget).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo.cpp"), ImmutableList.of("-foo")), SourceWithFlags.of(new FakeSourcePath("bar.cpp")))).setHeaders(ImmutableSortedSet.of(new FakeSourcePath("foo.h"))).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(cxxNode));
    projectGenerator.createXcodeProjects();
    PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:lib");
    assertThat(target.isa(), equalTo("PBXNativeTarget"));
    assertThat(target.getProductType(), equalTo(ProductType.STATIC_LIBRARY));
    assertHasConfigurations(target, "Debug", "Release", "Profile");
    assertEquals("Should have exact number of build phases", 1, target.getBuildPhases().size());
    assertHasSingletonSourcesPhaseWithSourcesAndFlags(target, ImmutableMap.of("foo.cpp", Optional.of("-foo"), "bar.cpp", Optional.empty()));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) BuildTarget(com.facebook.buck.model.BuildTarget) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) Test(org.junit.Test)

Aggregations

FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)318 Test (org.junit.Test)297 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)188 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)188 BuildTarget (com.facebook.buck.model.BuildTarget)182 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)116 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)104 SourcePath (com.facebook.buck.rules.SourcePath)90 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)85 TargetGraph (com.facebook.buck.rules.TargetGraph)84 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)68 Path (java.nio.file.Path)67 BuildRule (com.facebook.buck.rules.BuildRule)52 PathSourcePath (com.facebook.buck.rules.PathSourcePath)48 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)46 PBXTarget (com.facebook.buck.apple.xcode.xcodeproj.PBXTarget)45 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)45 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)35 CxxLibraryBuilder (com.facebook.buck.cxx.CxxLibraryBuilder)25 NSString (com.dd.plist.NSString)24