use of com.facebook.buck.apple.xcode.xcodeproj.PBXTarget in project buck by facebook.
the class ProjectGeneratorTest method testCxxLibraryPlatformFlags.
@Test
public void testCxxLibraryPlatformFlags() throws IOException {
BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
TargetNode<?, ?> node = new CxxLibraryBuilder(buildTarget).setPlatformCompilerFlags(PatternMatchedCollection.<ImmutableList<String>>builder().add(Pattern.compile("android.*"), ImmutableList.of("-ffoo-android")).add(Pattern.compile("iphone.*"), ImmutableList.of("-ffoo-iphone")).add(Pattern.compile("macosx.*"), ImmutableList.of("-ffoo-macosx")).build()).setPlatformPreprocessorFlags(PatternMatchedCollection.<ImmutableList<String>>builder().add(Pattern.compile("android.*"), ImmutableList.of("-fbar-android")).add(Pattern.compile("iphone.*"), ImmutableList.of("-fbar-iphone")).add(Pattern.compile("macosx.*"), ImmutableList.of("-fbar-macosx")).build()).setPlatformLinkerFlags(PatternMatchedCollection.<ImmutableList<StringWithMacros>>builder().add(Pattern.compile("android.*"), ImmutableList.of(StringWithMacrosUtils.format("-lbaz-android"))).add(Pattern.compile("iphone.*"), ImmutableList.of(StringWithMacrosUtils.format("-lbaz-iphone"))).add(Pattern.compile("macosx.*"), ImmutableList.of(StringWithMacrosUtils.format("-lbaz-macosx"))).build()).build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node), ImmutableSet.of());
projectGenerator.createXcodeProjects();
PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:lib");
assertHasConfigurations(target, "Debug", "Release", "Profile");
ImmutableMap<String, String> settings = ProjectGeneratorTestUtils.getBuildSettings(projectFilesystem, buildTarget, target, "Debug");
assertEquals("-Wno-deprecated -Wno-conversion -Wno-deprecated -Wno-conversion", settings.get("OTHER_CFLAGS"));
assertEquals("-Wundeclared-selector -Wno-objc-designated-initializers " + "-Wundeclared-selector -Wno-objc-designated-initializers", settings.get("OTHER_CPLUSPLUSFLAGS"));
assertEquals("$(inherited) ", settings.get("OTHER_LDFLAGS"));
assertEquals("-Wno-deprecated -Wno-conversion -ffoo-iphone -fbar-iphone " + "-Wno-deprecated -Wno-conversion -ffoo-iphone -fbar-iphone", settings.get("OTHER_CFLAGS[sdk=*iphone*]"));
assertEquals("-Wundeclared-selector -Wno-objc-designated-initializers -ffoo-iphone -fbar-iphone " + "-Wundeclared-selector -Wno-objc-designated-initializers -ffoo-iphone -fbar-iphone", settings.get("OTHER_CPLUSPLUSFLAGS[sdk=*iphone*]"));
assertEquals("-lbaz-iphone -lbaz-iphone", settings.get("OTHER_LDFLAGS[sdk=*iphone*]"));
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXTarget in project buck by facebook.
the class ProjectGeneratorTest method testHeaderSymlinkTreesWithTestsAndLibraryBundles.
@Test
public void testHeaderSymlinkTreesWithTestsAndLibraryBundles() throws IOException {
BuildTarget libraryTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
BuildTarget bundleTarget = BuildTarget.builder(rootPath, "//foo", "bundle").build();
BuildTarget testTarget = BuildTarget.builder(rootPath, "//foo", "test").build();
TargetNode<?, ?> libraryNode = AppleLibraryBuilder.createBuilder(libraryTarget).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo.h"), ImmutableList.of("public")), SourceWithFlags.of(new FakeSourcePath("bar.h")))).build();
TargetNode<?, ?> bundleNode = AppleBundleBuilder.createBuilder(bundleTarget).setBinary(libraryTarget).setExtension(Either.ofLeft(AppleBundleExtension.FRAMEWORK)).setInfoPlist(new FakeSourcePath("Info.plist")).setTests(ImmutableSortedSet.of(testTarget)).build();
TargetNode<?, ?> testNode = AppleTestBuilder.createBuilder(testTarget).setConfigs(ImmutableSortedMap.of("Default", ImmutableMap.of())).setInfoPlist(new FakeSourcePath("Info.plist")).setDeps(ImmutableSortedSet.of(bundleTarget)).build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(libraryNode, bundleNode, testNode));
projectGenerator.createXcodeProjects();
PBXProject project = projectGenerator.getGeneratedProject();
PBXTarget testPBXTarget = assertTargetExistsAndReturnTarget(project, "//foo:test");
ImmutableMap<String, String> buildSettings = getBuildSettings(testTarget, testPBXTarget, "Default");
assertEquals("test binary should use header symlink trees for both public and non-public headers " + "of the tested library in HEADER_SEARCH_PATHS", "$(inherited) " + "../buck-out/gen/_p/LpygK8zq5F-priv/.hmap " + "../buck-out/gen/_p/LpygK8zq5F-pub/.hmap " + "../buck-out/gen/_p/CwkbTNOBmb-pub/.hmap " + "../buck-out/gen/_p/CwkbTNOBmb-priv/.hmap " + "../buck-out", buildSettings.get("HEADER_SEARCH_PATHS"));
assertEquals("USER_HEADER_SEARCH_PATHS should not be set", null, buildSettings.get("USER_HEADER_SEARCH_PATHS"));
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXTarget in project buck by facebook.
the class ProjectGeneratorTest method testAppleBundleRuleForSharedLibraryFramework.
@Test
public void testAppleBundleRuleForSharedLibraryFramework() throws IOException {
BuildTarget sharedLibraryTarget = BuildTarget.builder(rootPath, "//dep", "shared").addFlavors(CxxDescriptionEnhancer.SHARED_FLAVOR).build();
TargetNode<?, ?> sharedLibraryNode = AppleLibraryBuilder.createBuilder(sharedLibraryTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).build();
BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "bundle").build();
TargetNode<?, ?> node = AppleBundleBuilder.createBuilder(buildTarget).setExtension(Either.ofLeft(AppleBundleExtension.FRAMEWORK)).setInfoPlist(new FakeSourcePath("Info.plist")).setBinary(sharedLibraryTarget).build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(sharedLibraryNode, node), ImmutableSet.of());
projectGenerator.createXcodeProjects();
PBXProject project = projectGenerator.getGeneratedProject();
PBXTarget target = assertTargetExistsAndReturnTarget(project, "//foo:bundle");
assertEquals(target.getProductType(), ProductType.FRAMEWORK);
assertThat(target.isa(), equalTo("PBXNativeTarget"));
PBXFileReference productReference = target.getProductReference();
assertEquals("bundle.framework", productReference.getName());
assertEquals(Optional.of("wrapper.framework"), productReference.getExplicitFileType());
ImmutableMap<String, String> settings = getBuildSettings(buildTarget, target, "Debug");
assertEquals("framework", settings.get("WRAPPER_EXTENSION"));
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXTarget in project buck by facebook.
the class WorkspaceAndProjectGeneratorTest method buildWithBuckFocused.
@Test
public void buildWithBuckFocused() throws IOException, InterruptedException {
final String fooLib = "//foo:lib";
Optional<Path> buck = new ExecutableFinder().getOptionalExecutable(Paths.get("buck"), ImmutableMap.of());
assumeThat(buck.isPresent(), is(true));
WorkspaceAndProjectGenerator generator = new WorkspaceAndProjectGenerator(rootCell, targetGraph, workspaceNode.getConstructorArg(), workspaceNode.getBuildTarget(), ImmutableSet.of(ProjectGenerator.Option.INCLUDE_TESTS, ProjectGenerator.Option.INCLUDE_DEPENDENCIES_TESTS), false, /* combinedProject */
true, /* buildWithBuck */
ImmutableList.of(), Optional.of(ImmutableSet.of(BuildTargetFactory.newInstance(fooLib).getUnflavoredBuildTarget())), false, /* parallelizeBuild */
new AlwaysFoundExecutableFinder(), ImmutableMap.of(), PLATFORMS, DEFAULT_PLATFORM, "BUCK", getBuildRuleResolverForNodeFunction(targetGraph), getFakeBuckEventBus(), halideBuckConfig, cxxBuckConfig, appleConfig, swiftBuckConfig);
Map<Path, ProjectGenerator> projectGenerators = new HashMap<>();
generator.generateWorkspaceAndDependentProjects(projectGenerators, MoreExecutors.newDirectExecutorService());
ProjectGenerator fooProjectGenerator = projectGenerators.get(Paths.get("foo"));
assertThat(fooProjectGenerator, is(notNullValue()));
for (PBXTarget target : fooProjectGenerator.getGeneratedProject().getTargets()) {
if (target.getName() != null && !target.getName().equals(fooLib) && !target.getName().endsWith("-Buck")) {
// all non-lib and non-Buck targets should have 0 steps as they are not in focus
// (focus on .*lib.* only)
assertThat(target.getBuildPhases().size(), Matchers.equalTo(0));
}
}
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXTarget in project buck by facebook.
the class ProjectGenerator method generateProjectTarget.
@SuppressWarnings("unchecked")
private Optional<PBXTarget> generateProjectTarget(TargetNode<?, ?> targetNode) throws IOException {
Preconditions.checkState(isBuiltByCurrentProject(targetNode.getBuildTarget()), "should not generate rule if it shouldn't be built by current project");
Optional<PBXTarget> result = Optional.empty();
if (targetNode.getDescription() instanceof AppleLibraryDescription) {
result = Optional.of(generateAppleLibraryTarget(project, (TargetNode<AppleNativeTargetDescriptionArg, ?>) targetNode, Optional.empty()));
} else if (targetNode.getDescription() instanceof CxxLibraryDescription) {
result = Optional.of(generateCxxLibraryTarget(project, (TargetNode<CxxLibraryDescription.Arg, ?>) targetNode, ImmutableSet.of(), ImmutableSet.of(), Optional.empty()));
} else if (targetNode.getDescription() instanceof AppleBinaryDescription) {
result = Optional.of(generateAppleBinaryTarget(project, (TargetNode<AppleNativeTargetDescriptionArg, ?>) targetNode));
} else if (targetNode.getDescription() instanceof AppleBundleDescription) {
TargetNode<AppleBundleDescription.Arg, ?> bundleTargetNode = (TargetNode<AppleBundleDescription.Arg, ?>) targetNode;
result = Optional.of(generateAppleBundleTarget(project, bundleTargetNode, (TargetNode<AppleNativeTargetDescriptionArg, ?>) targetGraph.get(bundleTargetNode.getConstructorArg().binary), Optional.empty()));
} else if (targetNode.getDescription() instanceof AppleTestDescription) {
result = Optional.of(generateAppleTestTarget((TargetNode<AppleTestDescription.Arg, ?>) targetNode));
} else if (targetNode.getDescription() instanceof AppleResourceDescription) {
checkAppleResourceTargetNodeReferencingValidContents((TargetNode<AppleResourceDescription.Arg, ?>) targetNode);
} else if (targetNode.getDescription() instanceof HalideLibraryDescription) {
TargetNode<HalideLibraryDescription.Arg, ?> halideTargetNode = (TargetNode<HalideLibraryDescription.Arg, ?>) targetNode;
BuildTarget buildTarget = targetNode.getBuildTarget();
// The generated target just runs a shell script that invokes the "compiler" with the
// correct target architecture.
result = generateHalideLibraryTarget(project, halideTargetNode);
// Make sure the compiler gets built at project time, since we'll need
// it to generate the shader code during the Xcode build.
requiredBuildTargetsBuilder.add(HalideLibraryDescription.createHalideCompilerBuildTarget(buildTarget));
// headers from.
if (HalideLibraryDescription.isPlatformSupported(halideTargetNode.getConstructorArg(), defaultCxxPlatform)) {
// Run the compiler once at project time to generate the header
// file needed for compilation if the Halide target is for the default
// platform.
requiredBuildTargetsBuilder.add(buildTarget.withFlavors(HalideLibraryDescription.HALIDE_COMPILE_FLAVOR, defaultCxxPlatform.getFlavor()));
}
}
buckEventBus.post(ProjectGenerationEvent.processed());
return result;
}
Aggregations