Search in sources :

Example 6 with PBXBuildFile

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

the class PBXBuildFiles method get.

/**
   * Returns new or cached instances of PBXBuildFiles corresponding to files that may or may not
   * belong to an aggregate reference (see {@link AggregateReferenceType}). Files specified by the
   * {@code paths} argument are grouped into individual PBXBuildFiles using the given
   * {@link AggregateReferenceType}. Files that are standalone are not put in an aggregate
   * reference, but are put in a standalone PBXBuildFile in the returned sequence.
   */
public Iterable<PBXBuildFile> get(AggregateReferenceType type, Iterable<Path> paths) {
    ImmutableList.Builder<PBXBuildFile> result = new ImmutableList.Builder<>();
    SetMultimap<AggregateKey, Path> keyedPaths = type.aggregates(paths);
    for (Map.Entry<AggregateKey, Collection<Path>> aggregation : keyedPaths.asMap().entrySet()) {
        if (!aggregation.getKey().isStandalone()) {
            ImmutableSet<Path> itemPaths = ImmutableSet.copyOf(aggregation.getValue());
            result.add(aggregateBuildFile(itemPaths, type.create(aggregation.getKey(), fileReferences(itemPaths))));
        }
    }
    for (Path generalResource : keyedPaths.get(AggregateKey.standalone())) {
        result.add(getStandalone(FileReference.of(generalResource.toString(), SourceTree.GROUP)));
    }
    return result.build();
}
Also used : Path(java.nio.file.Path) ImmutableList(com.google.common.collect.ImmutableList) PBXBuildFile(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildFile) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with PBXBuildFile

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

the class Resources method fromTargetControls.

public static Resources fromTargetControls(FileSystem fileSystem, PBXBuildFiles pbxBuildFiles, Iterable<TargetControl> targetControls) {
    ImmutableSetMultimap.Builder<TargetControl, PBXBuildFile> buildFiles = new ImmutableSetMultimap.Builder<>();
    for (TargetControl targetControl : targetControls) {
        List<PBXBuildFile> targetBuildFiles = new ArrayList<>();
        Iterable<String> simpleImports = Iterables.concat(targetControl.getXcassetsDirList(), targetControl.getBundleImportList());
        // bundle and link it properly, and add the {@code lastKnownFileType} property.
        for (String simpleImport : simpleImports) {
            targetBuildFiles.add(pbxBuildFiles.getStandalone(FileReference.of(simpleImport, SourceTree.GROUP)));
        }
        Iterables.addAll(targetBuildFiles, pbxBuildFiles.get(AggregateReferenceType.PBXVariantGroup, RelativePaths.fromStrings(fileSystem, targetControl.getGeneralResourceFileList())));
        // references we generated with fileObjects will be added to the main group later.
        if (!Equaling.of(ProductType.STATIC_LIBRARY, XcodeprojGeneration.productType(targetControl))) {
            buildFiles.putAll(targetControl, targetBuildFiles);
        }
    }
    return new Resources(buildFiles.build());
}
Also used : ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) TargetControl(com.google.devtools.build.xcode.xcodegen.proto.XcodeGenProtos.TargetControl) PBXBuildFile(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildFile) ArrayList(java.util.ArrayList)

Example 8 with PBXBuildFile

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

the class PBXBuildFiles method aggregateBuildFile.

private PBXBuildFile aggregateBuildFile(ImmutableSet<Path> paths, PBXReference reference) {
    Preconditions.checkArgument(!paths.isEmpty(), "paths must be non-empty");
    for (PBXBuildFile cached : Mapping.of(aggregateBuildFiles, paths).asSet()) {
        return cached;
    }
    PBXBuildFile buildFile = new PBXBuildFile(reference);
    mainGroupReferences.add(reference);
    aggregateBuildFiles.put(paths, buildFile);
    return buildFile;
}
Also used : PBXBuildFile(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildFile)

Example 9 with PBXBuildFile

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

the class PBXBuildFiles method getStandalone.

/**
   * Returns a new or cached instance of a PBXBuildFile for a file that is not part of a variant
   * group.
   */
public PBXBuildFile getStandalone(FileReference file) {
    for (PBXBuildFile cached : Mapping.of(standaloneBuildFiles, file).asSet()) {
        return cached;
    }
    PBXBuildFile buildFile = new PBXBuildFile(pbxReferences.get(file));
    mainGroupReferences.add(pbxReferences.get(file));
    standaloneBuildFiles.put(file, buildFile);
    return buildFile;
}
Also used : PBXBuildFile(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildFile)

Example 10 with PBXBuildFile

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

the class ProjectGeneratorTest method cxxFlagsPropagatedToConfig.

@Test
public void cxxFlagsPropagatedToConfig() throws IOException {
    BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
    TargetNode<?, ?> node = AppleLibraryBuilder.createBuilder(buildTarget).setLangPreprocessorFlags(ImmutableMap.of(CxxSource.Type.C, ImmutableList.of("-std=gnu11"), CxxSource.Type.OBJC, ImmutableList.of("-std=gnu11", "-fobjc-arc"), CxxSource.Type.CXX, ImmutableList.of("-std=c++11", "-stdlib=libc++"), CxxSource.Type.OBJCXX, ImmutableList.of("-std=c++11", "-stdlib=libc++", "-fobjc-arc"))).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo1.m")), SourceWithFlags.of(new FakeSourcePath("foo2.mm")), SourceWithFlags.of(new FakeSourcePath("foo3.c")), SourceWithFlags.of(new FakeSourcePath("foo4.cc")))).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node));
    projectGenerator.createXcodeProjects();
    PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:lib");
    PBXSourcesBuildPhase sourcesBuildPhase = ProjectGeneratorTestUtils.getSingletonPhaseByType(target, PBXSourcesBuildPhase.class);
    ImmutableMap<String, String> expected = ImmutableMap.of("foo1.m", "-std=gnu11 -fobjc-arc", "foo2.mm", "-std=c++11 -stdlib=libc++ -fobjc-arc", "foo3.c", "-std=gnu11", "foo4.cc", "-std=c++11 -stdlib=libc++");
    for (PBXBuildFile file : sourcesBuildPhase.getFiles()) {
        String fileName = file.getFileRef().getName();
        NSDictionary buildFileSettings = file.getSettings().get();
        NSString compilerFlags = (NSString) buildFileSettings.get("COMPILER_FLAGS");
        assertNotNull("Build file settings should have COMPILER_FLAGS entry", compilerFlags);
        assertEquals(compilerFlags.toString(), expected.get(fileName));
    }
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) BuildTarget(com.facebook.buck.model.BuildTarget) NSDictionary(com.dd.plist.NSDictionary) PBXBuildFile(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildFile) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NSString(com.dd.plist.NSString) NSString(com.dd.plist.NSString) PBXSourcesBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXSourcesBuildPhase) Test(org.junit.Test)

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