use of com.facebook.buck.apple.xcode.xcodeproj.PBXTarget in project buck by facebook.
the class ProjectGeneratorTest method testAggregateTargetForLibraryForBuildWithBuck.
@Test
public void testAggregateTargetForLibraryForBuildWithBuck() throws IOException {
BuildTarget libraryTarget = BuildTarget.builder(rootPath, "//foo", "library").build();
TargetNode<?, ?> binaryNode = AppleLibraryBuilder.createBuilder(libraryTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo.m"), ImmutableList.of("-foo")))).build();
ImmutableSet<TargetNode<?, ?>> nodes = ImmutableSet.of(binaryNode);
final TargetGraph targetGraph = TargetGraphFactory.newInstance(nodes);
final AppleDependenciesCache cache = new AppleDependenciesCache(targetGraph);
ProjectGenerator projectGenerator = new ProjectGenerator(targetGraph, cache, nodes.stream().map(TargetNode::getBuildTarget).collect(MoreCollectors.toImmutableSet()), projectCell, OUTPUT_DIRECTORY, PROJECT_NAME, "BUCK", ImmutableSet.of(), Optional.of(libraryTarget), ImmutableList.of("--flag", "value with spaces"), false, Optional.empty(), ImmutableSet.of(), Optional.empty(), new AlwaysFoundExecutableFinder(), ImmutableMap.of(), PLATFORMS, DEFAULT_PLATFORM, getBuildRuleResolverNodeFunction(targetGraph), getFakeBuckEventBus(), halideBuckConfig, cxxBuckConfig, appleConfig, swiftBuckConfig);
projectGenerator.createXcodeProjects();
PBXTarget buildWithBuckTarget = null;
for (PBXTarget target : projectGenerator.getGeneratedProject().getTargets()) {
if (target.getProductName() != null && target.getProductName().endsWith("-Buck")) {
buildWithBuckTarget = target;
}
}
assertThat(buildWithBuckTarget, is(notNullValue()));
assertHasConfigurations(buildWithBuckTarget, "Debug");
assertKeepsConfigurationsInMainGroup(projectGenerator.getGeneratedProject(), buildWithBuckTarget);
assertEquals("Should have exact number of build phases", 1, buildWithBuckTarget.getBuildPhases().size());
PBXBuildPhase buildPhase = Iterables.getOnlyElement(buildWithBuckTarget.getBuildPhases());
assertThat(buildPhase, instanceOf(PBXShellScriptBuildPhase.class));
PBXShellScriptBuildPhase shellScriptBuildPhase = (PBXShellScriptBuildPhase) buildPhase;
assertThat(shellScriptBuildPhase.getShellScript(), containsString("buck -- \"--show-output --report-absolute-paths --flag 'value with spaces'\" " + libraryTarget.getFullyQualifiedName() + " dwarf dwarf-and-dsym"));
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXTarget in project buck by facebook.
the class ProjectGeneratorTest method testAppleLibraryRule.
@Test
public void testAppleLibraryRule() throws IOException {
BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
TargetNode<?, ?> node = AppleLibraryBuilder.createBuilder(buildTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo.m"), ImmutableList.of("-foo")), SourceWithFlags.of(new FakeSourcePath("bar.m")))).setExtraXcodeSources(ImmutableList.of(new FakeSourcePath("libsomething.a"))).setHeaders(ImmutableSortedSet.of(new FakeSourcePath("foo.h"))).build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node));
projectGenerator.createXcodeProjects();
PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:lib");
assertThat(target.isa(), equalTo("PBXNativeTarget"));
assertThat(target.getProductType(), equalTo(ProductType.STATIC_LIBRARY));
assertHasConfigurations(target, "Debug");
assertEquals("Should have exact number of build phases", 1, target.getBuildPhases().size());
assertHasSingletonSourcesPhaseWithSourcesAndFlags(target, ImmutableMap.of("foo.m", Optional.of("-foo"), "bar.m", Optional.empty(), "libsomething.a", Optional.empty()));
// this target should not have an asset catalog build phase
assertTrue(FluentIterable.from(target.getBuildPhases()).filter(PBXResourcesBuildPhase.class).isEmpty());
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXTarget in project buck by facebook.
the class ProjectGeneratorTest method testAssetCatalogsUnderLibraryNotTest.
@Test
public void testAssetCatalogsUnderLibraryNotTest() throws IOException {
BuildTarget libraryTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
BuildTarget testTarget = BuildTarget.builder(rootPath, "//foo", "test").build();
BuildTarget assetCatalogTarget = BuildTarget.builder(rootPath, "//foo", "asset_catalog").build();
TargetNode<?, ?> libraryNode = AppleLibraryBuilder.createBuilder(libraryTarget).setTests(ImmutableSortedSet.of(testTarget)).setDeps(ImmutableSortedSet.of(assetCatalogTarget)).build();
TargetNode<?, ?> testNode = AppleTestBuilder.createBuilder(testTarget).setConfigs(ImmutableSortedMap.of("Default", ImmutableMap.of())).setInfoPlist(new FakeSourcePath("Info.plist")).setDeps(ImmutableSortedSet.of(libraryTarget)).build();
TargetNode<?, ?> assetCatalogNode = AppleAssetCatalogBuilder.createBuilder(assetCatalogTarget).setDirs(ImmutableSortedSet.of(new FakeSourcePath("AssetCatalog.xcassets"))).build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(libraryNode, testNode, assetCatalogNode), ImmutableSet.of(ProjectGenerator.Option.USE_SHORT_NAMES_FOR_TARGETS));
projectGenerator.createXcodeProjects();
PBXProject project = projectGenerator.getGeneratedProject();
PBXGroup mainGroup = project.getMainGroup();
PBXTarget fooLibTarget = assertTargetExistsAndReturnTarget(project, "lib");
assertTrue(FluentIterable.from(fooLibTarget.getBuildPhases()).filter(PBXResourcesBuildPhase.class).isEmpty());
PBXGroup libResourcesGroup = mainGroup.getOrCreateChildGroupByName("lib").getOrCreateChildGroupByName("Resources");
PBXFileReference assetCatalogFile = (PBXFileReference) libResourcesGroup.getChildren().get(0);
assertEquals("AssetCatalog.xcassets", assetCatalogFile.getName());
PBXTarget fooTestTarget = assertTargetExistsAndReturnTarget(project, "test");
PBXResourcesBuildPhase resourcesBuildPhase = ProjectGeneratorTestUtils.getSingletonPhaseByType(fooTestTarget, PBXResourcesBuildPhase.class);
assertThat(resourcesBuildPhase.getFiles(), hasSize(1));
assertThat(assertFileRefIsRelativeAndResolvePath(resourcesBuildPhase.getFiles().get(0).getFileRef()), equalTo(projectFilesystem.resolve("AssetCatalog.xcassets").toString()));
PBXGroup testResourcesGroup = mainGroup.getOrCreateChildGroupByName("test").getOrCreateChildGroupByName("Resources");
assetCatalogFile = (PBXFileReference) testResourcesGroup.getChildren().get(0);
assertEquals("AssetCatalog.xcassets", assetCatalogFile.getName());
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXTarget in project buck by facebook.
the class ProjectGeneratorTest method testResolvingExportFile.
@Test
public void testResolvingExportFile() throws IOException {
BuildTarget source1Target = BuildTarget.builder(rootPath, "//Vendor", "source1").build();
BuildTarget source2Target = BuildTarget.builder(rootPath, "//Vendor", "source2").build();
BuildTarget source2RefTarget = BuildTarget.builder(rootPath, "//Vendor", "source2ref").build();
BuildTarget source3Target = BuildTarget.builder(rootPath, "//Vendor", "source3").build();
BuildTarget headerTarget = BuildTarget.builder(rootPath, "//Vendor", "header").build();
BuildTarget libTarget = BuildTarget.builder(rootPath, "//Libraries", "foo").build();
TargetNode<ExportFileDescription.Arg, ?> source1 = ExportFileBuilder.newExportFileBuilder(source1Target).setSrc(new PathSourcePath(projectFilesystem, Paths.get("Vendor/sources/source1"))).build();
TargetNode<ExportFileDescription.Arg, ?> source2 = ExportFileBuilder.newExportFileBuilder(source2Target).setSrc(new PathSourcePath(projectFilesystem, Paths.get("Vendor/source2"))).build();
TargetNode<ExportFileDescription.Arg, ?> source2Ref = ExportFileBuilder.newExportFileBuilder(source2RefTarget).setSrc(new DefaultBuildTargetSourcePath(source2Target)).build();
TargetNode<ExportFileDescription.Arg, ?> source3 = ExportFileBuilder.newExportFileBuilder(source3Target).build();
TargetNode<ExportFileDescription.Arg, ?> header = ExportFileBuilder.newExportFileBuilder(headerTarget).build();
TargetNode<AppleLibraryDescription.Arg, ?> library = AppleLibraryBuilder.createBuilder(libTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new DefaultBuildTargetSourcePath(source1Target)), SourceWithFlags.of(new DefaultBuildTargetSourcePath(source2RefTarget)), SourceWithFlags.of(new DefaultBuildTargetSourcePath(source3Target)))).setPrefixHeader(Optional.of(new DefaultBuildTargetSourcePath(headerTarget))).build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(source1, source2, source2Ref, source3, header, library));
projectGenerator.createXcodeProjects();
PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), libTarget.toString());
assertHasSingletonSourcesPhaseWithSourcesAndFlags(target, ImmutableMap.of("Vendor/sources/source1", Optional.empty(), "Vendor/source2", Optional.empty(), "Vendor/source3", Optional.empty()));
ImmutableMap<String, String> settings = getBuildSettings(libTarget, target, "Debug");
assertEquals("../Vendor/header", settings.get("GCC_PREFIX_HEADER"));
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXTarget in project buck by facebook.
the class ProjectGeneratorTest method testAppleLibraryExportedPreprocessorFlags.
@Test
public void testAppleLibraryExportedPreprocessorFlags() throws IOException {
BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
TargetNode<?, ?> node = AppleLibraryBuilder.createBuilder(buildTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).setExportedPreprocessorFlags(ImmutableList.of("-DHELLO")).build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node), ImmutableSet.of());
projectGenerator.createXcodeProjects();
PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:lib");
ImmutableMap<String, String> settings = getBuildSettings(buildTarget, target, "Debug");
assertEquals("$(inherited) -Wno-deprecated -Wno-conversion -DHELLO", settings.get("OTHER_CFLAGS"));
}
Aggregations