Search in sources :

Example 11 with PBXBuildFile

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

the class NewNativeTargetProjectMutator method addSourcePathToSourcesBuildPhase.

private void addSourcePathToSourcesBuildPhase(SourceWithFlags sourceWithFlags, PBXGroup sourcesGroup, PBXSourcesBuildPhase sourcesBuildPhase) {
    SourceTreePath sourceTreePath = new SourceTreePath(PBXReference.SourceTree.SOURCE_ROOT, pathRelativizer.outputDirToRootRelative(sourcePathResolver.apply(sourceWithFlags.getSourcePath())), Optional.empty());
    PBXFileReference fileReference = sourcesGroup.getOrCreateFileReferenceBySourceTreePath(sourceTreePath);
    PBXBuildFile buildFile = new PBXBuildFile(fileReference);
    sourcesBuildPhase.getFiles().add(buildFile);
    ImmutableList<String> customLangPreprocessorFlags = ImmutableList.of();
    Optional<CxxSource.Type> sourceType = CxxSource.Type.fromExtension(Files.getFileExtension(sourceTreePath.toString()));
    if (sourceType.isPresent() && langPreprocessorFlags.containsKey(sourceType.get())) {
        customLangPreprocessorFlags = langPreprocessorFlags.get(sourceType.get());
    }
    ImmutableList<String> customFlags = ImmutableList.copyOf(Iterables.concat(customLangPreprocessorFlags, sourceWithFlags.getFlags()));
    if (!customFlags.isEmpty()) {
        NSDictionary settings = new NSDictionary();
        settings.put("COMPILER_FLAGS", Joiner.on(' ').join(customFlags));
        buildFile.setSettings(Optional.of(settings));
    }
    LOG.verbose("Added source path %s to group %s, flags %s, PBXFileReference %s", sourceWithFlags, sourcesGroup.getName(), customFlags, fileReference);
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) ProductType(com.facebook.buck.apple.xcode.xcodeproj.ProductType) 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 12 with PBXBuildFile

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

the class ProjectGenerator method getSingleCopyFilesBuildPhase.

private PBXCopyFilesBuildPhase getSingleCopyFilesBuildPhase(CopyFilePhaseDestinationSpec destinationSpec, Iterable<TargetNode<?, ?>> targetNodes) {
    PBXCopyFilesBuildPhase copyFilesBuildPhase = new PBXCopyFilesBuildPhase(destinationSpec);
    HashSet<UnflavoredBuildTarget> frameworkTargets = new HashSet<UnflavoredBuildTarget>();
    for (TargetNode<?, ?> targetNode : targetNodes) {
        PBXFileReference fileReference = getLibraryFileReference(targetNode);
        PBXBuildFile buildFile = new PBXBuildFile(fileReference);
        if (fileReference.getExplicitFileType().equals(Optional.of("wrapper.framework"))) {
            UnflavoredBuildTarget buildTarget = targetNode.getBuildTarget().getUnflavoredBuildTarget();
            if (frameworkTargets.contains(buildTarget)) {
                continue;
            }
            frameworkTargets.add(buildTarget);
            NSDictionary settings = new NSDictionary();
            settings.put("ATTRIBUTES", new String[] { "CodeSignOnCopy", "RemoveHeadersOnCopy" });
            buildFile.setSettings(Optional.of(settings));
        }
        copyFilesBuildPhase.getFiles().add(buildFile);
    }
    return copyFilesBuildPhase;
}
Also used : NSDictionary(com.dd.plist.NSDictionary) PBXBuildFile(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildFile) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) PBXCopyFilesBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXCopyFilesBuildPhase) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference) HashSet(java.util.HashSet)

Example 13 with PBXBuildFile

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

the class NewNativeTargetProjectMutator method addResourcesBuildPhase.

private PBXBuildPhase addResourcesBuildPhase(PBXNativeTarget target, PBXGroup targetGroup) {
    ImmutableSet.Builder<Path> resourceFiles = ImmutableSet.builder();
    ImmutableSet.Builder<Path> resourceDirs = ImmutableSet.builder();
    ImmutableSet.Builder<Path> variantResourceFiles = ImmutableSet.builder();
    collectResourcePathsFromConstructorArgs(recursiveResources, recursiveAssetCatalogs, wrapperResources, resourceFiles, resourceDirs, variantResourceFiles);
    final PBXBuildPhase phase = new PBXResourcesBuildPhase();
    addResourcesFileReference(targetGroup, resourceFiles.build(), resourceDirs.build(), variantResourceFiles.build(), input -> {
        PBXBuildFile buildFile = new PBXBuildFile(input);
        phase.getFiles().add(buildFile);
    }, input -> {
        PBXBuildFile buildFile = new PBXBuildFile(input);
        phase.getFiles().add(buildFile);
    });
    if (!phase.getFiles().isEmpty()) {
        target.getBuildPhases().add(phase);
        LOG.debug("Added resources build phase %s", phase);
    }
    return phase;
}
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) ImmutableSet(com.google.common.collect.ImmutableSet) PBXBuildFile(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildFile) PBXBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase) PBXResourcesBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXResourcesBuildPhase)

Example 14 with PBXBuildFile

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

the class NewNativeTargetProjectMutator method addFrameworksBuildPhase.

private void addFrameworksBuildPhase(PBXProject project, PBXNativeTarget target) {
    if (frameworks.isEmpty() && archives.isEmpty()) {
        return;
    }
    PBXGroup sharedFrameworksGroup = project.getMainGroup().getOrCreateChildGroupByName("Frameworks");
    PBXFrameworksBuildPhase frameworksBuildPhase = new PBXFrameworksBuildPhase();
    target.getBuildPhases().add(frameworksBuildPhase);
    for (FrameworkPath framework : frameworks) {
        SourceTreePath sourceTreePath;
        if (framework.getSourceTreePath().isPresent()) {
            sourceTreePath = framework.getSourceTreePath().get();
        } else if (framework.getSourcePath().isPresent()) {
            sourceTreePath = new SourceTreePath(PBXReference.SourceTree.SOURCE_ROOT, pathRelativizer.outputPathToSourcePath(framework.getSourcePath().get()), Optional.empty());
        } else {
            throw new RuntimeException();
        }
        PBXFileReference fileReference = sharedFrameworksGroup.getOrCreateFileReferenceBySourceTreePath(sourceTreePath);
        frameworksBuildPhase.getFiles().add(new PBXBuildFile(fileReference));
    }
    for (PBXFileReference archive : archives) {
        frameworksBuildPhase.getFiles().add(new PBXBuildFile(archive));
    }
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) PBXBuildFile(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildFile) PBXGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXGroup) PBXFrameworksBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXFrameworksBuildPhase) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference)

Aggregations

PBXBuildFile (com.facebook.buck.apple.xcode.xcodeproj.PBXBuildFile)14 NSDictionary (com.dd.plist.NSDictionary)6 NSString (com.dd.plist.NSString)6 PBXFileReference (com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference)5 SourceTreePath (com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath)4 PBXResourcesBuildPhase (com.facebook.buck.apple.xcode.xcodeproj.PBXResourcesBuildPhase)3 PBXSourcesBuildPhase (com.facebook.buck.apple.xcode.xcodeproj.PBXSourcesBuildPhase)3 Path (java.nio.file.Path)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 NSArray (com.dd.plist.NSArray)2 PBXBuildPhase (com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase)2 PBXFrameworksBuildPhase (com.facebook.buck.apple.xcode.xcodeproj.PBXFrameworksBuildPhase)2 PBXReference (com.facebook.buck.apple.xcode.xcodeproj.PBXReference)2 FrameworkPath (com.facebook.buck.rules.coercer.FrameworkPath)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 TargetControl (com.google.devtools.build.xcode.xcodegen.proto.XcodeGenProtos.TargetControl)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 HeaderMap (com.facebook.buck.apple.clang.HeaderMap)1