Search in sources :

Example 6 with SourceTreePath

use of com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath 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 7 with SourceTreePath

use of com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath in project buck by facebook.

the class FrameworkPathTypeCoercer method coerce.

@Override
public FrameworkPath coerce(CellPathResolver cellRoots, ProjectFilesystem filesystem, Path pathRelativeToProjectRoot, Object object) throws CoerceFailedException {
    if (object instanceof String) {
        Path path = Paths.get((String) object);
        String firstElement = Preconditions.checkNotNull(Iterables.getFirst(path, Paths.get(""))).toString();
        if (firstElement.startsWith("$")) {
            // NOPMD - length() > 0 && charAt(0) == '$' is ridiculous
            Optional<PBXReference.SourceTree> sourceTree = PBXReference.SourceTree.fromBuildSetting(firstElement);
            if (sourceTree.isPresent()) {
                int nameCount = path.getNameCount();
                if (nameCount < 2) {
                    throw new HumanReadableException("Invalid source tree path: '%s'. Should have at least one path component after" + "'%s'.", path, firstElement);
                }
                return FrameworkPath.ofSourceTreePath(new SourceTreePath(sourceTree.get(), path.subpath(1, path.getNameCount()), Optional.empty()));
            } else {
                throw new HumanReadableException("Unknown SourceTree: '%s'. Should be one of: %s", firstElement, Joiner.on(", ").join(Iterables.transform(ImmutableList.copyOf(PBXReference.SourceTree.values()), input -> "$" + input.toString())));
            }
        } else {
            return FrameworkPath.ofSourcePath(sourcePathTypeCoercer.coerce(cellRoots, filesystem, pathRelativeToProjectRoot, object));
        }
    }
    throw CoerceFailedException.simple(object, getOutputClass(), "input should be either a source tree path or a source path");
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) HumanReadableException(com.facebook.buck.util.HumanReadableException)

Example 8 with SourceTreePath

use of com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath in project buck by facebook.

the class CxxLinkableEnhancerTest method frameworksToLinkerFlagsTransformer.

@Test
public void frameworksToLinkerFlagsTransformer() {
    ProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    SourcePathResolver resolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    Arg linkerFlags = CxxLinkableEnhancer.frameworksToLinkerArg(ImmutableSortedSet.of(FrameworkPath.ofSourceTreePath(new SourceTreePath(PBXReference.SourceTree.DEVELOPER_DIR, Paths.get("Library/Frameworks/XCTest.framework"), Optional.empty())), FrameworkPath.ofSourcePath(new PathSourcePath(projectFilesystem, Paths.get("Vendor/Bar/Bar.framework")))));
    assertEquals(ImmutableList.of("-framework", "XCTest", "-framework", "Bar"), Arg.stringifyList(linkerFlags, resolver));
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SourcePathArg(com.facebook.buck.rules.args.SourcePathArg) StringArg(com.facebook.buck.rules.args.StringArg) Arg(com.facebook.buck.rules.args.Arg) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 9 with SourceTreePath

use of com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath in project buck by facebook.

the class CxxLibraryDescriptionTest method sharedLibraryShouldLinkOwnRequiredLibraries.

@Test
public void sharedLibraryShouldLinkOwnRequiredLibraries() throws Exception {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    CxxPlatform platform = CxxLibraryBuilder.createDefaultPlatform();
    CxxLibraryBuilder libraryBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:foo").withFlavors(platform.getFlavor(), CxxDescriptionEnhancer.SHARED_FLAVOR), cxxBuckConfig);
    libraryBuilder.setLibraries(ImmutableSortedSet.of(FrameworkPath.ofSourceTreePath(new SourceTreePath(PBXReference.SourceTree.SDKROOT, Paths.get("/usr/lib/libz.dylib"), Optional.empty())), FrameworkPath.ofSourcePath(new FakeSourcePath("/another/path/liba.dylib")))).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo.c"))));
    TargetGraph targetGraph = TargetGraphFactory.newInstance(libraryBuilder.build());
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    CxxLink library = (CxxLink) libraryBuilder.build(resolver, filesystem, targetGraph);
    assertThat(Arg.stringify(library.getArgs(), pathResolver), hasItems("-L", "/another/path", "$SDKROOT/usr/lib", "-la", "-lz"));
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 10 with SourceTreePath

use of com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath in project buck by facebook.

the class NewNativeTargetProjectMutatorTest method testFrameworkBuildPhase.

@Test
public void testFrameworkBuildPhase() throws NoSuchBuildTargetException {
    NewNativeTargetProjectMutator mutator = mutatorWithCommonDefaults();
    mutator.setFrameworks(ImmutableSet.of(FrameworkPath.ofSourceTreePath(new SourceTreePath(PBXReference.SourceTree.SDKROOT, Paths.get("Foo.framework"), Optional.empty()))));
    mutator.setArchives(ImmutableSet.of(new PBXFileReference("libdep.a", "libdep.a", PBXReference.SourceTree.BUILT_PRODUCTS_DIR, Optional.empty())));
    NewNativeTargetProjectMutator.Result result = mutator.buildTargetAndAddToProject(generatedProject, true);
    assertHasSingletonFrameworksPhaseWithFrameworkEntries(result.target, ImmutableList.of("$SDKROOT/Foo.framework", "$BUILT_PRODUCTS_DIR/libdep.a"));
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference) Test(org.junit.Test)

Aggregations

SourceTreePath (com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath)21 NSString (com.dd.plist.NSString)10 Test (org.junit.Test)10 PBXFileReference (com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference)8 BuildTarget (com.facebook.buck.model.BuildTarget)8 PBXGroup (com.facebook.buck.apple.xcode.xcodeproj.PBXGroup)7 PBXTarget (com.facebook.buck.apple.xcode.xcodeproj.PBXTarget)7 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)7 ImmutableMap (com.google.common.collect.ImmutableMap)5 SourcePath (com.facebook.buck.rules.SourcePath)4 FrameworkPath (com.facebook.buck.rules.coercer.FrameworkPath)4 HumanReadableException (com.facebook.buck.util.HumanReadableException)4 Path (java.nio.file.Path)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 NSDictionary (com.dd.plist.NSDictionary)3 PBXBuildFile (com.facebook.buck.apple.xcode.xcodeproj.PBXBuildFile)3 PathSourcePath (com.facebook.buck.rules.PathSourcePath)3 NSObject (com.dd.plist.NSObject)2 AppleBundleDescription (com.facebook.buck.apple.AppleBundleDescription)2 AppleLibraryDescription (com.facebook.buck.apple.AppleLibraryDescription)2