use of com.facebook.buck.cxx.CxxPlatform in project buck by facebook.
the class DBinaryDescriptionTest method cxxLinkerInImplicitTimeDeps.
@Test
public void cxxLinkerInImplicitTimeDeps() {
CxxPlatform cxxPlatform = CxxPlatformUtils.DEFAULT_PLATFORM;
DBinaryBuilder builder = new DBinaryBuilder(BuildTargetFactory.newInstance("//:rule"), new DBuckConfig(FakeBuckConfig.builder().build()), cxxPlatform);
ImmutableList<BuildTarget> implicitDeps = ImmutableList.copyOf(builder.findImplicitDeps());
for (BuildTarget target : cxxPlatform.getLd().getParseTimeDeps()) {
assertThat(implicitDeps, Matchers.hasItem(target));
}
}
use of com.facebook.buck.cxx.CxxPlatform in project buck by facebook.
the class ProjectGenerator method getBuildWithBuckShellScript.
private String getBuildWithBuckShellScript(TargetNode<?, ?> targetNode) {
ST template;
try {
template = new ST(Resources.toString(Resources.getResource(ProjectGenerator.class, BUILD_WITH_BUCK_TEMPLATE), Charsets.UTF_8));
} catch (IOException e) {
throw new RuntimeException("There was an error loading '" + BUILD_WITH_BUCK_TEMPLATE + "' template", e);
}
String buildFlags = getBuildFlags();
String escapedBuildTarget = Escaper.escapeAsBashString(targetNode.getBuildTarget().getFullyQualifiedName());
Optional<String> productName = getProductNameForTargetNode(targetNode);
String binaryName = AppleBundle.getBinaryName(targetNode.getBuildTarget(), productName);
Path bundleDestination = getScratchPathForAppBundle(projectFilesystem, targetNode.getBuildTarget(), binaryName);
Path dsymDestination = getScratchPathForDsymBundle(projectFilesystem, targetNode.getBuildTarget(), binaryName);
Path resolvedBundleDestination = projectFilesystem.resolve(bundleDestination);
Path resolvedDsymDestination = projectFilesystem.resolve(dsymDestination);
ImmutableSet<Flavor> flavors = ImmutableSet.copyOf(targetNode.getBuildTarget().getFlavors());
CxxPlatform cxxPlatform = cxxPlatforms.getValue(flavors).orElse(defaultCxxPlatform);
String oldCompDir = cxxPlatform.getCompilerDebugPathSanitizer().getCompilationDirectory();
// Use the hostname for padding instead of the directory, this way the directory matches without
// having to resolve it.
String dsymPaddedCompDirWithHost = Strings.padStart(":" + projectFilesystem.getRootPath().toString(), oldCompDir.length(), 'f');
template.add("path_to_build_with_buck_py", getBuildWithBuckPythonScriptPath(projectFilesystem));
template.add("path_to_fix_uuid_script", getFixUUIDScriptPath(projectFilesystem));
template.add("repo_root", projectFilesystem.getRootPath());
template.add("path_to_buck", getPathToBuck(executableFinder, environment));
template.add("build_flags", buildFlags);
template.add("escaped_build_target", escapedBuildTarget);
template.add("buck_dwarf_flavor", (appleConfig.forceDsymModeInBuildWithBuck() ? AppleDebugFormat.DWARF_AND_DSYM : AppleDebugFormat.DWARF).getFlavor().getName());
template.add("buck_dsym_flavor", AppleDebugFormat.DWARF_AND_DSYM.getFlavor().getName());
template.add("binary_name", binaryName);
template.add("comp_dir", oldCompDir);
template.add("new_comp_dir", projectFilesystem.getRootPath().toString());
template.add("padded_source_dir", dsymPaddedCompDirWithHost);
template.add("resolved_bundle_destination", resolvedBundleDestination);
template.add("resolved_bundle_destination_parent", resolvedBundleDestination.getParent());
template.add("resolved_dsym_destination", resolvedDsymDestination);
template.add("force_dsym", appleConfig.forceDsymModeInBuildWithBuck() ? "true" : "false");
return template.render();
}
use of com.facebook.buck.cxx.CxxPlatform in project buck by facebook.
the class AppleCxxPlatformsTest method iphoneOSSdkPathsBuiltFromDirectory.
@Test
public void iphoneOSSdkPathsBuiltFromDirectory() throws Exception {
AppleSdkPaths appleSdkPaths = AppleSdkPaths.builder().setDeveloperPath(Paths.get(".")).addToolchainPaths(Paths.get("Toolchains/XcodeDefault.xctoolchain")).setPlatformPath(Paths.get("Platforms/iPhoneOS.platform")).setSdkPath(Paths.get("Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.0.sdk")).build();
AppleToolchain toolchain = AppleToolchain.builder().setIdentifier("com.apple.dt.XcodeDefault").setPath(Paths.get("Toolchains/XcodeDefault.xctoolchain")).setVersion("1").build();
AppleSdk targetSdk = AppleSdk.builder().setApplePlatform(ApplePlatform.IPHONEOS).setName("iphoneos8.0").setVersion("8.0").setToolchains(ImmutableList.of(toolchain)).build();
ImmutableSet<Path> paths = ImmutableSet.<Path>builder().addAll(COMMON_KNOWN_PATHS).add(Paths.get("Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate")).add(Paths.get("Platforms/iPhoneOS.platform/Developer/usr/bin/libtool")).add(Paths.get("Platforms/iPhoneOS.platform/Developer/usr/bin/ar")).add(Paths.get("Tools/otest")).build();
AppleCxxPlatform appleCxxPlatform = AppleCxxPlatforms.buildWithExecutableChecker(projectFilesystem, targetSdk, "7.0", "armv7", appleSdkPaths, FakeBuckConfig.builder().build(), new FakeAppleConfig(), new FakeExecutableFinder(paths), Optional.empty(), Optional.empty());
CxxPlatform cxxPlatform = appleCxxPlatform.getCxxPlatform();
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver resolver = new SourcePathResolver(new SourcePathRuleFinder(ruleResolver));
assertEquals(ImmutableList.of("usr/bin/actool"), appleCxxPlatform.getActool().getCommandPrefix(resolver));
assertEquals(ImmutableList.of("usr/bin/ibtool"), appleCxxPlatform.getIbtool().getCommandPrefix(resolver));
assertEquals(ImmutableList.of("usr/bin/lldb"), appleCxxPlatform.getLldb().getCommandPrefix(resolver));
assertEquals(ImmutableList.of("Toolchains/XcodeDefault.xctoolchain/usr/bin/dsymutil"), appleCxxPlatform.getDsymutil().getCommandPrefix(resolver));
assertEquals(ImmutableList.of("Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate"), appleCxxPlatform.getCodesignAllocate().get().getCommandPrefix(resolver));
assertEquals(ImmutableList.of("usr/bin/xctest"), appleCxxPlatform.getXctest().getCommandPrefix(resolver));
assertEquals(InternalFlavor.of("iphoneos8.0-armv7"), cxxPlatform.getFlavor());
assertEquals(Paths.get("Toolchains/XcodeDefault.xctoolchain/usr/bin/clang").toString(), cxxPlatform.getCc().resolve(ruleResolver).getCommandPrefix(resolver).get(0));
assertThat(ImmutableList.<String>builder().addAll(cxxPlatform.getCc().resolve(ruleResolver).getCommandPrefix(resolver)).addAll(cxxPlatform.getCflags()).build(), hasConsecutiveItems("-isysroot", Paths.get("Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.0.sdk").toString()));
assertThat(cxxPlatform.getCflags(), hasConsecutiveItems("-arch", "armv7"));
assertThat(cxxPlatform.getAsflags(), hasConsecutiveItems("-arch", "armv7"));
assertThat(cxxPlatform.getCflags(), hasConsecutiveItems("-mios-version-min=7.0"));
assertThat(cxxPlatform.getLdflags(), hasConsecutiveItems("-Wl,-sdk_version", "-Wl,8.0"));
assertEquals(Paths.get("Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++").toString(), cxxPlatform.getCxx().resolve(ruleResolver).getCommandPrefix(resolver).get(0));
assertEquals(Paths.get("Platforms/iPhoneOS.platform/Developer/usr/bin/ar").toString(), cxxPlatform.getAr().getCommandPrefix(resolver).get(0));
}
use of com.facebook.buck.cxx.CxxPlatform in project buck by facebook.
the class AppleCxxPlatformsTest method iphoneOSSimulatorPlatformSetsLinkerFlags.
@Test
public void iphoneOSSimulatorPlatformSetsLinkerFlags() throws Exception {
AppleSdkPaths appleSdkPaths = AppleSdkPaths.builder().setDeveloperPath(Paths.get(".")).addToolchainPaths(Paths.get("Toolchains/XcodeDefault.xctoolchain")).setPlatformPath(Paths.get("Platforms/iPhoneOS.platform")).setSdkPath(Paths.get("Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneSimulator8.0.sdk")).build();
ImmutableSet<Path> paths = ImmutableSet.<Path>builder().addAll(COMMON_KNOWN_PATHS).add(Paths.get("Platforms/iPhoneSimulator.platform/Developer/usr/bin/libtool")).add(Paths.get("Platforms/iPhoneSimulator.platform/Developer/usr/bin/ar")).add(Paths.get("Tools/otest")).build();
AppleToolchain toolchain = AppleToolchain.builder().setIdentifier("com.apple.dt.XcodeDefault").setPath(Paths.get("Toolchains/XcodeDefault.xctoolchain")).setVersion("1").build();
AppleSdk targetSdk = AppleSdk.builder().setApplePlatform(ApplePlatform.IPHONESIMULATOR).setName("iphonesimulator8.0").setVersion("8.0").setToolchains(ImmutableList.of(toolchain)).build();
AppleCxxPlatform appleCxxPlatform = AppleCxxPlatforms.buildWithExecutableChecker(projectFilesystem, targetSdk, "7.0", "armv7", appleSdkPaths, FakeBuckConfig.builder().build(), new FakeAppleConfig(), new FakeExecutableFinder(paths), Optional.empty(), Optional.empty());
CxxPlatform cxxPlatform = appleCxxPlatform.getCxxPlatform();
assertThat(cxxPlatform.getCflags(), hasItem("-mios-simulator-version-min=7.0"));
assertThat(cxxPlatform.getLdflags(), hasItem("-mios-simulator-version-min=7.0"));
}
use of com.facebook.buck.cxx.CxxPlatform in project buck by facebook.
the class LuaBinaryIntegrationTest method setUp.
@Before
public void setUp() throws Exception {
// We don't currently support windows.
assumeThat(Platform.detect(), Matchers.not(Platform.WINDOWS));
// Verify that a Lua interpreter is available on the system.
LuaBuckConfig fakeConfig = new LuaBuckConfig(FakeBuckConfig.builder().build(), new ExecutableFinder());
Optional<Path> luaOptional = fakeConfig.getSystemLua();
assumeTrue(luaOptional.isPresent());
lua = luaOptional.get();
// Try to detect if a Lua devel package is available, which is needed to C/C++ support.
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
CxxPlatform cxxPlatform = DefaultCxxPlatforms.build(Platform.detect(), new FakeProjectFilesystem(), new CxxBuckConfig(FakeBuckConfig.builder().build()));
ProcessExecutorParams params = ProcessExecutorParams.builder().setCommand(ImmutableList.<String>builder().addAll(cxxPlatform.getCc().resolve(resolver).getCommandPrefix(new SourcePathResolver(new SourcePathRuleFinder(resolver)))).add("-includelua.h", "-E", "-").build()).setRedirectInput(ProcessBuilder.Redirect.PIPE).build();
ProcessExecutor executor = new DefaultProcessExecutor(Console.createNullConsole());
ProcessExecutor.LaunchedProcess launchedProcess = executor.launchProcess(params);
launchedProcess.getOutputStream().close();
int exitCode = executor.waitForLaunchedProcess(launchedProcess).getExitCode();
luaDevel = exitCode == 0;
if (starterType == LuaBinaryDescription.StarterType.NATIVE) {
assumeTrue("Lua devel package required for native starter", luaDevel);
}
// Setup the workspace.
workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "lua_binary", tmp);
workspace.setUp();
workspace.writeContentsToPath(Joiner.on(System.lineSeparator()).join(ImmutableList.of("[lua]", " starter_type = " + starterType.toString().toLowerCase(), " native_link_strategy = " + nativeLinkStrategy.toString().toLowerCase(), "[cxx]", " sandbox_sources =" + sandboxSources)), ".buckconfig");
LuaBuckConfig config = getLuaBuckConfig();
assertThat(config.getStarterType(), Matchers.equalTo(Optional.of(starterType)));
assertThat(config.getNativeLinkStrategy(), Matchers.equalTo(nativeLinkStrategy));
}
Aggregations