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"));
}
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);
}
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);
}
}
Aggregations