Search in sources :

Example 6 with XCBuildConfiguration

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

the class ProjectGeneratorTest method testConfigurationSerializationWithoutExistingXcconfig.

@Test
public void testConfigurationSerializationWithoutExistingXcconfig() throws IOException {
    BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
    TargetNode<?, ?> node = AppleLibraryBuilder.createBuilder(buildTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of("CUSTOM_SETTING", "VALUE"))).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node), ImmutableSet.of());
    projectGenerator.createXcodeProjects();
    PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:lib");
    assertThat(target.isa(), equalTo("PBXNativeTarget"));
    assertThat(target.getProductType(), equalTo(ProductType.STATIC_LIBRARY));
    assertHasConfigurations(target, "Debug");
    assertKeepsConfigurationsInMainGroup(projectGenerator.getGeneratedProject(), target);
    XCBuildConfiguration configuration = target.getBuildConfigurationList().getBuildConfigurationsByName().asMap().get("Debug");
    assertEquals(configuration.getBuildSettings().count(), 0);
    PBXFileReference xcconfigReference = configuration.getBaseConfigurationReference();
    assertEquals(xcconfigReference.getPath(), "../buck-out/gen/foo/lib-Debug.xcconfig");
    ImmutableMap<String, String> settings = getBuildSettings(buildTarget, target, "Debug");
    assertEquals("$SYMROOT/$CONFIGURATION$EFFECTIVE_PLATFORM_NAME", settings.get("BUILT_PRODUCTS_DIR"));
    assertEquals("$BUILT_PRODUCTS_DIR", settings.get("CONFIGURATION_BUILD_DIR"));
    assertEquals("VALUE", settings.get("CUSTOM_SETTING"));
}
Also used : PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) XCBuildConfiguration(com.facebook.buck.apple.xcode.xcodeproj.XCBuildConfiguration) BuildTarget(com.facebook.buck.model.BuildTarget) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NSString(com.dd.plist.NSString) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference) Test(org.junit.Test)

Example 7 with XCBuildConfiguration

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

the class ProjectGeneratorTestUtils method getBuildSettings.

public static ImmutableMap<String, String> getBuildSettings(ProjectFilesystem projectFilesystem, BuildTarget buildTarget, PBXTarget target, String config) {
    XCBuildConfiguration configuration = target.getBuildConfigurationList().getBuildConfigurationsByName().asMap().get(config);
    assertEquals(configuration.getBuildSettings().count(), 0);
    PBXFileReference xcconfigReference = configuration.getBaseConfigurationReference();
    Path xcconfigPath = buildTarget.getBasePath().resolve(xcconfigReference.getPath());
    String contents = projectFilesystem.readFileIfItExists(xcconfigPath).get();
    // Use a HashMap to allow for duplicate keys.
    HashMap<String, String> builder = new HashMap<String, String>();
    for (String line : contents.split("\n")) {
        String[] parts = line.split(" = ");
        builder.put(parts[0], parts[1]);
    }
    return ImmutableMap.copyOf(builder);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) XCBuildConfiguration(com.facebook.buck.apple.xcode.xcodeproj.XCBuildConfiguration) HashMap(java.util.HashMap) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference)

Example 8 with XCBuildConfiguration

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

the class ProjectGenerator method setTargetBuildConfigurations.

/**
   * Create target level configuration entries.
   *
   * @param target      Xcode target for which the configurations will be set.
   * @param targetGroup Xcode group in which the configuration file references will be placed.
   * @param configurations  Configurations as extracted from the BUCK file.
   * @param overrideBuildSettings Build settings that will override ones defined elsewhere.
   * @param defaultBuildSettings  Target-inline level build settings that will be set if not already
   *                              defined.
   * @param appendBuildSettings   Target-inline level build settings that will incorporate the
   *                              existing value or values at a higher level.
   */
private void setTargetBuildConfigurations(Function<String, Path> configurationNameToXcconfigPath, PBXTarget target, PBXGroup targetGroup, ImmutableMap<String, ImmutableMap<String, String>> configurations, ImmutableMap<String, String> overrideBuildSettings, ImmutableMap<String, String> defaultBuildSettings, ImmutableMap<String, String> appendBuildSettings) throws IOException {
    if (shouldGenerateHeaderSymlinkTreesOnly()) {
        return;
    }
    for (Map.Entry<String, ImmutableMap<String, String>> configurationEntry : configurations.entrySet()) {
        targetConfigNamesBuilder.add(configurationEntry.getKey());
        ImmutableMap<String, String> targetLevelInlineSettings = configurationEntry.getValue();
        XCBuildConfiguration outputConfiguration = target.getBuildConfigurationList().getBuildConfigurationsByName().getUnchecked(configurationEntry.getKey());
        HashMap<String, String> combinedOverrideConfigs = Maps.newHashMap(overrideBuildSettings);
        for (Map.Entry<String, String> entry : defaultBuildSettings.entrySet()) {
            String existingSetting = targetLevelInlineSettings.get(entry.getKey());
            if (existingSetting == null) {
                combinedOverrideConfigs.put(entry.getKey(), entry.getValue());
            }
        }
        for (Map.Entry<String, String> entry : appendBuildSettings.entrySet()) {
            String existingSetting = targetLevelInlineSettings.get(entry.getKey());
            String settingPrefix = existingSetting != null ? existingSetting : "$(inherited)";
            combinedOverrideConfigs.put(entry.getKey(), settingPrefix + " " + entry.getValue());
        }
        ImmutableSortedMap<String, String> mergedSettings = MoreMaps.mergeSorted(targetLevelInlineSettings, combinedOverrideConfigs);
        Path xcconfigPath = configurationNameToXcconfigPath.apply(configurationEntry.getKey());
        projectFilesystem.mkdirs(Preconditions.checkNotNull(xcconfigPath).getParent());
        StringBuilder stringBuilder = new StringBuilder();
        for (Map.Entry<String, String> entry : mergedSettings.entrySet()) {
            stringBuilder.append(entry.getKey());
            stringBuilder.append(" = ");
            stringBuilder.append(entry.getValue());
            stringBuilder.append('\n');
        }
        String xcconfigContents = stringBuilder.toString();
        if (MoreProjectFilesystems.fileContentsDiffer(new ByteArrayInputStream(xcconfigContents.getBytes(Charsets.UTF_8)), xcconfigPath, projectFilesystem)) {
            if (shouldGenerateReadOnlyFiles()) {
                projectFilesystem.writeContentsToPath(xcconfigContents, xcconfigPath, READ_ONLY_FILE_ATTRIBUTE);
            } else {
                projectFilesystem.writeContentsToPath(xcconfigContents, xcconfigPath);
            }
        }
        PBXFileReference fileReference = getConfigurationFileReference(targetGroup, xcconfigPath);
        outputConfiguration.setBaseConfigurationReference(fileReference);
    }
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) XCBuildConfiguration(com.facebook.buck.apple.xcode.xcodeproj.XCBuildConfiguration) NSString(com.dd.plist.NSString) ImmutableMap(com.google.common.collect.ImmutableMap) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) HeaderMap(com.facebook.buck.apple.clang.HeaderMap) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference)

Aggregations

XCBuildConfiguration (com.facebook.buck.apple.xcode.xcodeproj.XCBuildConfiguration)8 NSString (com.dd.plist.NSString)7 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 PBXFileReference (com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference)3 BuildTarget (com.facebook.buck.model.BuildTarget)3 NSDictionary (com.dd.plist.NSDictionary)2 PBXGroup (com.facebook.buck.apple.xcode.xcodeproj.PBXGroup)2 PBXTarget (com.facebook.buck.apple.xcode.xcodeproj.PBXTarget)2 PathSourcePath (com.facebook.buck.rules.PathSourcePath)2 SourcePath (com.facebook.buck.rules.SourcePath)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 AppleBundleDescription (com.facebook.buck.apple.AppleBundleDescription)1 AppleNativeTargetDescriptionArg (com.facebook.buck.apple.AppleNativeTargetDescriptionArg)1 AppleWrapperResourceArg (com.facebook.buck.apple.AppleWrapperResourceArg)1 HeaderMap (com.facebook.buck.apple.clang.HeaderMap)1 PBXAggregateTarget (com.facebook.buck.apple.xcode.xcodeproj.PBXAggregateTarget)1 PBXProject (com.facebook.buck.apple.xcode.xcodeproj.PBXProject)1