use of com.facebook.buck.cxx.CxxCompilationDatabaseEntry in project buck by facebook.
the class CompilationDatabaseIntegrationTest method assertFlags.
private void assertFlags(ProjectFilesystem filesystem, String source, BuildTarget outputTarget, Path outputPath, boolean isLibrary, Map<String, CxxCompilationDatabaseEntry> fileToEntry, ImmutableSet<String> additionalFrameworks, Iterable<String> includes) throws IOException {
Path tmpRoot = tmp.getRoot().toRealPath();
String key = tmpRoot.resolve(source).toString();
CxxCompilationDatabaseEntry entry = fileToEntry.get(key);
assertNotNull("There should be an entry for " + key + ".", entry);
Path xcodeDeveloperDir = tmpRoot.resolve(XCODE_DEVELOPER_DIR);
Path platformDir = xcodeDeveloperDir.resolve("Platforms/iPhoneSimulator.platform");
Path sdkRoot = platformDir.resolve("Developer/SDKs/iPhoneSimulator.sdk");
String clang = xcodeDeveloperDir.resolve("Toolchains/XcodeDefault.xctoolchain/usr/bin/clang").toString();
String language = "objective-c";
String languageStandard = "-std=gnu11";
if (source.endsWith(".mm")) {
language = "objective-c++";
languageStandard = "-std=c++11";
clang += "++";
}
ImmutableList<String> commandArgs1 = ImmutableList.of("'" + languageStandard + "'", "-Wno-deprecated", "-Wno-conversion");
ImmutableList<String> commandArgs2 = ImmutableList.of("-isysroot", sdkRoot.toString(), "-iquote", tmpRoot.toString(), "-arch", "x86_64", "'-mios-simulator-version-min=8.0'");
List<String> commandArgs = Lists.newArrayList();
commandArgs.add(clang);
if (isLibrary) {
commandArgs.add("-fPIC");
commandArgs.add("-fPIC");
}
// TODO(Coneko, k21): It seems like a bug that this set of flags gets inserted twice.
// Perhaps this has something to do with how the [cxx] section in .buckconfig is processed.
// (Err, it's probably adding both the preprocessor and regular rule command suffixes. Should
// be harmless.)
commandArgs.addAll(commandArgs2);
commandArgs.addAll(commandArgs1);
commandArgs.addAll(commandArgs2);
for (String include : includes) {
commandArgs.add("-I");
commandArgs.add(include);
}
for (String framework : additionalFrameworks) {
commandArgs.add("-F");
commandArgs.add(sdkRoot + framework);
}
String output = BuildTargets.getGenPath(filesystem, outputTarget, "%s").resolve(outputPath).toString();
commandArgs.add("-Xclang");
commandArgs.add("-fdebug-compilation-dir");
commandArgs.add("-Xclang");
commandArgs.add("." + Strings.repeat("/", 399));
commandArgs.add("-x");
commandArgs.add(language);
commandArgs.add("'-fdebug-prefix-map=" + tmpRoot + "=.'");
commandArgs.add("'-fdebug-prefix-map=" + xcodeDeveloperDir + "=APPLE_DEVELOPER_DIR'");
commandArgs.add("'-fdebug-prefix-map=" + platformDir + "=APPLE_PLATFORM_DIR'");
commandArgs.add("'-fdebug-prefix-map=" + sdkRoot + "=APPLE_SDKROOT'");
commandArgs.add("-c");
commandArgs.add("-MD");
commandArgs.add("-MF");
commandArgs.add(output + ".dep");
commandArgs.add(source);
commandArgs.add("-o");
commandArgs.add(output);
assertThat(ImmutableList.copyOf(entry.getCommand().split(" ")), equalTo(commandArgs));
}
use of com.facebook.buck.cxx.CxxCompilationDatabaseEntry in project buck by facebook.
the class CompilationDatabaseIntegrationTest method testCreateCompilationDatabaseForAppleBinaryWithDeps.
@Test
public void testCreateCompilationDatabaseForAppleBinaryWithDeps() throws IOException {
// buck build the #compilation-database.
BuildTarget target = BuildTargetFactory.newInstance("//Apps/Weather:Weather#iphonesimulator-x86_64,compilation-database");
Path compilationDatabase = workspace.buildAndReturnOutput(target.getFullyQualifiedName());
ProjectFilesystem filesystem = new FakeProjectFilesystem();
// Parse the compilation_database.json file.
Map<String, CxxCompilationDatabaseEntry> fileToEntry = CxxCompilationDatabaseUtils.parseCompilationDatabaseJsonFile(compilationDatabase);
ImmutableSet<String> frameworks = ImmutableSet.of(Paths.get("/System/Library/Frameworks/Foundation.framework").getParent().toString(), Paths.get("/System/Library/Frameworks/UIKit.framework").getParent().toString());
String pathToPrivateHeaders = BuildTargets.getGenPath(filesystem, target.withFlavors(InternalFlavor.of("iphonesimulator-x86_64"), CxxDescriptionEnhancer.HEADER_SYMLINK_TREE_FLAVOR), "%s.hmap").toString();
String pathToPublicHeaders = BuildTargets.getGenPath(filesystem, BuildTargetFactory.newInstance("//Libraries/EXExample:EXExample").withAppendedFlavors(CxxDescriptionEnhancer.EXPORTED_HEADER_SYMLINK_TREE_FLAVOR, CxxPlatformUtils.getHeaderModeForDefaultPlatform(tmp.getRoot()).getFlavor()), "%s.hmap").toString();
Iterable<String> includes = ImmutableList.of(pathToPrivateHeaders, pathToPublicHeaders, filesystem.getBuckPaths().getBuckOut().toString());
assertFlags(filesystem, "Apps/Weather/Weather/EXViewController.m", target.withFlavors(InternalFlavor.of("iphonesimulator-x86_64"), InternalFlavor.of("compile-" + sanitize("Weather/EXViewController.m.o"))), Paths.get("Weather/EXViewController.m.o"), /* isLibrary */
false, fileToEntry, frameworks, includes);
assertFlags(filesystem, "Apps/Weather/Weather/main.m", target.withFlavors(InternalFlavor.of("iphonesimulator-x86_64"), InternalFlavor.of("compile-" + sanitize("Weather/main.m.o"))), Paths.get("Weather/main.m.o"), /* isLibrary */
false, fileToEntry, frameworks, includes);
}
use of com.facebook.buck.cxx.CxxCompilationDatabaseEntry in project buck by facebook.
the class CompilationDatabaseIntegrationTest method testCreateCompilationDatabaseForAppleLibraryWithNoDeps.
@Test
public void testCreateCompilationDatabaseForAppleLibraryWithNoDeps() throws IOException {
// buck build the #compilation-database.
BuildTarget target = BuildTargetFactory.newInstance("//Libraries/EXExample:EXExample#compilation-database,iphonesimulator-x86_64");
Path compilationDatabase = workspace.buildAndReturnOutput(target.getFullyQualifiedName());
ProjectFilesystem filesystem = new FakeProjectFilesystem();
// Parse the compilation_database.json file.
Map<String, CxxCompilationDatabaseEntry> fileToEntry = CxxCompilationDatabaseUtils.parseCompilationDatabaseJsonFile(compilationDatabase);
ImmutableSet<String> frameworks = ImmutableSet.of(Paths.get("/System/Library/Frameworks/Foundation.framework").getParent().toString());
String pathToPrivateHeaders = BuildTargets.getGenPath(filesystem, target.withFlavors(InternalFlavor.of("iphonesimulator-x86_64"), CxxDescriptionEnhancer.HEADER_SYMLINK_TREE_FLAVOR), "%s.hmap").toString();
String pathToPublicHeaders = BuildTargets.getGenPath(filesystem, target.withFlavors(CxxDescriptionEnhancer.EXPORTED_HEADER_SYMLINK_TREE_FLAVOR, CxxPlatformUtils.getHeaderModeForDefaultPlatform(tmp.getRoot()).getFlavor()), "%s.hmap").toString();
Iterable<String> includes = ImmutableList.of(pathToPrivateHeaders, pathToPublicHeaders, filesystem.getBuckPaths().getBuckOut().toString());
// Verify the entries in the compilation database.
assertFlags(filesystem, "Libraries/EXExample/EXExample/EXExampleModel.m", target.withFlavors(InternalFlavor.of("iphonesimulator-x86_64"), InternalFlavor.of("compile-pic-" + sanitize("EXExample/EXExampleModel.m.o"))), Paths.get("EXExample/EXExampleModel.m.o"), /* isLibrary */
true, fileToEntry, frameworks, includes);
assertFlags(filesystem, "Libraries/EXExample/EXExample/EXUser.mm", target.withFlavors(InternalFlavor.of("iphonesimulator-x86_64"), InternalFlavor.of("compile-pic-" + sanitize("EXExample/EXUser.mm.o"))), Paths.get("EXExample/EXUser.mm.o"), /* isLibrary */
true, fileToEntry, frameworks, includes);
assertFlags(filesystem, "Libraries/EXExample/EXExample/Categories/NSString+Palindrome.m", target.withFlavors(InternalFlavor.of("iphonesimulator-x86_64"), InternalFlavor.of("compile-pic-" + sanitize("EXExample/Categories/NSString+Palindrome.m.o"))), Paths.get("EXExample/Categories/NSString+Palindrome.m.o"), /* isLibrary */
true, fileToEntry, frameworks, includes);
}
Aggregations