Search in sources :

Example 1 with SourceTreePath

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

the class NewNativeTargetProjectMutator method addPhasesAndGroupsForSources.

private void addPhasesAndGroupsForSources(PBXNativeTarget target, PBXGroup targetGroup) {
    PBXGroup sourcesGroup = targetGroup.getOrCreateChildGroupByName("Sources");
    // Sources groups stay in the order in which they're declared in the BUCK file.
    sourcesGroup.setSortPolicy(PBXGroup.SortPolicy.UNSORTED);
    PBXSourcesBuildPhase sourcesBuildPhase = new PBXSourcesBuildPhase();
    PBXHeadersBuildPhase headersBuildPhase = new PBXHeadersBuildPhase();
    traverseGroupsTreeAndHandleSources(sourcesGroup, sourcesBuildPhase, RuleUtils.createGroupsFromSourcePaths(pathRelativizer::outputPathToSourcePath, sourcesWithFlags, extraXcodeSources, publicHeaders, privateHeaders));
    if (prefixHeader.isPresent()) {
        SourceTreePath prefixHeaderSourceTreePath = new SourceTreePath(PBXReference.SourceTree.GROUP, pathRelativizer.outputPathToSourcePath(prefixHeader.get()), Optional.empty());
        sourcesGroup.getOrCreateFileReferenceBySourceTreePath(prefixHeaderSourceTreePath);
    }
    if (infoPlist.isPresent()) {
        SourceTreePath infoPlistSourceTreePath = new SourceTreePath(PBXReference.SourceTree.GROUP, pathRelativizer.outputPathToSourcePath(infoPlist.get()), Optional.empty());
        sourcesGroup.getOrCreateFileReferenceBySourceTreePath(infoPlistSourceTreePath);
    }
    if (bridgingHeader.isPresent()) {
        SourceTreePath bridgingHeaderSourceTreePath = new SourceTreePath(PBXReference.SourceTree.GROUP, pathRelativizer.outputPathToSourcePath(bridgingHeader.get()), Optional.empty());
        sourcesGroup.getOrCreateFileReferenceBySourceTreePath(bridgingHeaderSourceTreePath);
    }
    if (!sourcesBuildPhase.getFiles().isEmpty()) {
        target.getBuildPhases().add(sourcesBuildPhase);
    }
    if (!headersBuildPhase.getFiles().isEmpty()) {
        target.getBuildPhases().add(headersBuildPhase);
    }
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) PBXGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXGroup) PBXHeadersBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXHeadersBuildPhase) PBXSourcesBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXSourcesBuildPhase)

Example 2 with SourceTreePath

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

the class NewNativeTargetProjectMutator method addResourcesFileReference.

private void addResourcesFileReference(PBXGroup targetGroup, ImmutableSet<Path> resourceFiles, ImmutableSet<Path> resourceDirs, ImmutableSet<Path> variantResourceFiles, Consumer<? super PBXFileReference> resourceCallback, Consumer<? super PBXVariantGroup> variantGroupCallback) {
    if (resourceFiles.isEmpty() && resourceDirs.isEmpty() && variantResourceFiles.isEmpty()) {
        return;
    }
    PBXGroup resourcesGroup = targetGroup.getOrCreateChildGroupByName("Resources");
    for (Path path : resourceFiles) {
        PBXFileReference fileReference = resourcesGroup.getOrCreateFileReferenceBySourceTreePath(new SourceTreePath(PBXReference.SourceTree.SOURCE_ROOT, pathRelativizer.outputDirToRootRelative(path), Optional.empty()));
        resourceCallback.accept(fileReference);
    }
    for (Path path : resourceDirs) {
        PBXFileReference fileReference = resourcesGroup.getOrCreateFileReferenceBySourceTreePath(new SourceTreePath(PBXReference.SourceTree.SOURCE_ROOT, pathRelativizer.outputDirToRootRelative(path), Optional.of("folder")));
        resourceCallback.accept(fileReference);
    }
    Map<String, PBXVariantGroup> variantGroups = Maps.newHashMap();
    for (Path variantFilePath : variantResourceFiles) {
        String lprojSuffix = ".lproj";
        Path variantDirectory = variantFilePath.getParent();
        if (variantDirectory == null || !variantDirectory.toString().endsWith(lprojSuffix)) {
            throw new HumanReadableException("Variant files have to be in a directory with name ending in '.lproj', " + "but '%s' is not.", variantFilePath);
        }
        String variantDirectoryName = variantDirectory.getFileName().toString();
        String variantLocalization = variantDirectoryName.substring(0, variantDirectoryName.length() - lprojSuffix.length());
        String variantFileName = variantFilePath.getFileName().toString();
        PBXVariantGroup variantGroup = variantGroups.get(variantFileName);
        if (variantGroup == null) {
            variantGroup = resourcesGroup.getOrCreateChildVariantGroupByName(variantFileName);
            variantGroupCallback.accept(variantGroup);
            variantGroups.put(variantFileName, variantGroup);
        }
        SourceTreePath sourceTreePath = new SourceTreePath(PBXReference.SourceTree.SOURCE_ROOT, pathRelativizer.outputDirToRootRelative(variantFilePath), Optional.empty());
        variantGroup.getOrCreateVariantFileReferenceByNameAndSourceTreePath(variantLocalization, sourceTreePath);
    }
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) PBXVariantGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXVariantGroup) HumanReadableException(com.facebook.buck.util.HumanReadableException) PBXGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXGroup) NSString(com.dd.plist.NSString) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference)

Example 3 with SourceTreePath

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

the class NewNativeTargetProjectMutator method addSourcePathToHeadersBuildPhase.

private void addSourcePathToHeadersBuildPhase(SourcePath headerPath, PBXGroup headersGroup, HeaderVisibility visibility) {
    PBXFileReference fileReference = headersGroup.getOrCreateFileReferenceBySourceTreePath(new SourceTreePath(PBXReference.SourceTree.SOURCE_ROOT, pathRelativizer.outputPathToSourcePath(headerPath), Optional.empty()));
    PBXBuildFile buildFile = new PBXBuildFile(fileReference);
    if (visibility != HeaderVisibility.PRIVATE) {
        NSDictionary settings = new NSDictionary();
        settings.put("ATTRIBUTES", new NSArray(new NSString(AppleHeaderVisibilities.toXcodeAttribute(visibility))));
        buildFile.setSettings(Optional.of(settings));
    } else {
        buildFile.setSettings(Optional.empty());
    }
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) NSArray(com.dd.plist.NSArray) NSDictionary(com.dd.plist.NSDictionary) PBXBuildFile(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildFile) NSString(com.dd.plist.NSString) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference)

Example 4 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 5 with SourceTreePath

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

the class ProjectGeneratorTest method testAppleBinaryRule.

@Test
public void testAppleBinaryRule() throws IOException {
    BuildTarget depTarget = BuildTarget.builder(rootPath, "//dep", "dep").build();
    TargetNode<?, ?> depNode = AppleLibraryBuilder.createBuilder(depTarget).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("e.m")))).build();
    BuildTarget binaryTarget = BuildTarget.builder(rootPath, "//foo", "binary").build();
    TargetNode<?, ?> binaryNode = AppleBinaryBuilder.createBuilder(binaryTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo.m"), ImmutableList.of("-foo")))).setExtraXcodeSources(ImmutableList.of(new FakeSourcePath("libsomething.a"))).setHeaders(ImmutableSortedSet.of(new FakeSourcePath("foo.h"))).setFrameworks(ImmutableSortedSet.of(FrameworkPath.ofSourceTreePath(new SourceTreePath(PBXReference.SourceTree.SDKROOT, Paths.get("Foo.framework"), Optional.empty())))).setDeps(ImmutableSortedSet.of(depTarget)).setHeaderPathPrefix(Optional.empty()).setPrefixHeader(Optional.empty()).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(depNode, binaryNode));
    projectGenerator.createXcodeProjects();
    PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:binary");
    assertHasConfigurations(target, "Debug");
    assertEquals(target.getProductType(), ProductType.TOOL);
    assertEquals("Should have exact number of build phases", 2, target.getBuildPhases().size());
    assertHasSingletonSourcesPhaseWithSourcesAndFlags(target, ImmutableMap.of("foo.m", Optional.of("-foo"), "libsomething.a", Optional.empty()));
    ProjectGeneratorTestUtils.assertHasSingletonFrameworksPhaseWithFrameworkEntries(target, ImmutableList.of("$SDKROOT/Foo.framework", // Propagated library from deps.
    "$BUILT_PRODUCTS_DIR/libdep.a"));
    // this test does not have a dependency on any asset catalogs, so verify no build phase for them
    // exists.
    assertTrue(FluentIterable.from(target.getBuildPhases()).filter(PBXResourcesBuildPhase.class).isEmpty());
}
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) 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