Search in sources :

Example 46 with SourcePathRuleFinder

use of com.facebook.buck.rules.SourcePathRuleFinder in project buck by facebook.

the class MultiarchFileTest method descriptionWithMultiplePlatformArgsShouldGenerateMultiarchFile.

@SuppressWarnings({ "unchecked" })
@Test
public void descriptionWithMultiplePlatformArgsShouldGenerateMultiarchFile() throws Exception {
    BuildTarget target = BuildTargetFactory.newInstance("//foo:thing#iphoneos-i386,iphoneos-x86_64");
    BuildTarget sandboxTarget = BuildTargetFactory.newInstance("//foo:thing#iphoneos-i386,iphoneos-x86_64,sandbox");
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(new AppleLibraryBuilder(sandboxTarget).build()), new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    BuildRule multiarchRule = nodeBuilderFactory.getNodeBuilder(target).build(resolver, filesystem);
    assertThat(multiarchRule, instanceOf(MultiarchFile.class));
    ImmutableList<Step> steps = multiarchRule.getBuildSteps(FakeBuildContext.withSourcePathResolver(pathResolver), new FakeBuildableContext());
    ShellStep step = Iterables.getLast(Iterables.filter(steps, ShellStep.class));
    ExecutionContext executionContext = TestExecutionContext.newInstance();
    ImmutableList<String> command = step.getShellCommand(executionContext);
    assertThat(command, Matchers.contains(endsWith("lipo"), equalTo("-create"), equalTo("-output"), containsString("foo/thing#"), containsString("/thing#"), containsString("/thing#")));
}
Also used : FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) Step(com.facebook.buck.step.Step) ShellStep(com.facebook.buck.shell.ShellStep) Matchers.containsString(org.hamcrest.Matchers.containsString) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) BuildTarget(com.facebook.buck.model.BuildTarget) ShellStep(com.facebook.buck.shell.ShellStep) BuildRule(com.facebook.buck.rules.BuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 47 with SourcePathRuleFinder

use of com.facebook.buck.rules.SourcePathRuleFinder in project buck by facebook.

the class AppleCxxPlatformsTest method watchOSSdkPathsBuiltFromDirectory.

@Test
public void watchOSSdkPathsBuiltFromDirectory() throws Exception {
    AppleSdkPaths appleSdkPaths = AppleSdkPaths.builder().setDeveloperPath(Paths.get(".")).addToolchainPaths(Paths.get("Toolchains/XcodeDefault.xctoolchain")).setPlatformPath(Paths.get("Platforms/WatchOS.platform")).setSdkPath(Paths.get("Platforms/WatchOS.platform/Developer/SDKs/WatchOS2.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.WATCHOS).setName("watchos2.0").setVersion("2.0").setToolchains(ImmutableList.of(toolchain)).build();
    ImmutableSet<Path> paths = ImmutableSet.<Path>builder().addAll(COMMON_KNOWN_PATHS).add(Paths.get("Platforms/WatchOS.platform/Developer/usr/bin/libtool")).add(Paths.get("Platforms/WatchOS.platform/Developer/usr/bin/ar")).build();
    AppleCxxPlatform appleCxxPlatform = AppleCxxPlatforms.buildWithExecutableChecker(projectFilesystem, targetSdk, "2.0", "armv7k", 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("usr/bin/xctest"), appleCxxPlatform.getXctest().getCommandPrefix(resolver));
    assertEquals(InternalFlavor.of("watchos2.0-armv7k"), 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/WatchOS.platform/Developer/SDKs/WatchOS2.0.sdk").toString()));
    assertThat(cxxPlatform.getCflags(), hasConsecutiveItems("-arch", "armv7k"));
    assertThat(cxxPlatform.getCflags(), hasConsecutiveItems("-mwatchos-version-min=2.0"));
    assertThat(cxxPlatform.getLdflags(), hasConsecutiveItems("-Wl,-sdk_version", "-Wl,2.0"));
    assertEquals(Paths.get("Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++").toString(), cxxPlatform.getCxx().resolve(ruleResolver).getCommandPrefix(resolver).get(0));
    assertEquals(Paths.get("Platforms/WatchOS.platform/Developer/usr/bin/ar").toString(), cxxPlatform.getAr().getCommandPrefix(resolver).get(0));
}
Also used : Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) Matchers.containsString(org.hamcrest.Matchers.containsString) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) FakeExecutableFinder(com.facebook.buck.io.FakeExecutableFinder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 48 with SourcePathRuleFinder

use of com.facebook.buck.rules.SourcePathRuleFinder in project buck by facebook.

the class AppleCxxPlatformsTest method appleTVOSSdkPathsBuiltFromDirectory.

@Test
public void appleTVOSSdkPathsBuiltFromDirectory() throws Exception {
    AppleSdkPaths appleSdkPaths = AppleSdkPaths.builder().setDeveloperPath(Paths.get(".")).addToolchainPaths(Paths.get("Toolchains/XcodeDefault.xctoolchain")).setPlatformPath(Paths.get("Platforms/AppleTVOS.platform")).setSdkPath(Paths.get("Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS9.1.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.APPLETVOS).setName("appletvos9.1").setVersion("9.1").setToolchains(ImmutableList.of(toolchain)).build();
    ImmutableSet<Path> paths = ImmutableSet.<Path>builder().addAll(COMMON_KNOWN_PATHS).add(Paths.get("Platforms/AppleTVOS.platform/Developer/usr/bin/libtool")).add(Paths.get("Platforms/AppleTVOS.platform/Developer/usr/bin/ar")).build();
    AppleCxxPlatform appleCxxPlatform = AppleCxxPlatforms.buildWithExecutableChecker(projectFilesystem, targetSdk, "9.1", "arm64", 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());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
    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("usr/bin/xctest"), appleCxxPlatform.getXctest().getCommandPrefix(resolver));
    assertEquals(InternalFlavor.of("appletvos9.1-arm64"), 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/AppleTVOS.platform/Developer/SDKs/AppleTVOS9.1.sdk").toString()));
    assertThat(cxxPlatform.getCflags(), hasConsecutiveItems("-arch", "arm64"));
    assertThat(cxxPlatform.getCflags(), hasConsecutiveItems("-mtvos-version-min=9.1"));
    assertThat(cxxPlatform.getLdflags(), hasConsecutiveItems("-Wl,-sdk_version", "-Wl,9.1"));
    assertEquals(Paths.get("Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++").toString(), cxxPlatform.getCxx().resolve(ruleResolver).getCommandPrefix(resolver).get(0));
    assertEquals(Paths.get("Platforms/AppleTVOS.platform/Developer/usr/bin/ar").toString(), cxxPlatform.getAr().getCommandPrefix(resolver).get(0));
}
Also used : Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) Matchers.containsString(org.hamcrest.Matchers.containsString) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) FakeExecutableFinder(com.facebook.buck.io.FakeExecutableFinder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 49 with SourcePathRuleFinder

use of com.facebook.buck.rules.SourcePathRuleFinder in project buck by facebook.

the class AppleCxxPlatformsTest method constructCompileRuleKeys.

// Create and return some rule keys from a dummy source for the given platforms.
private ImmutableMap<Flavor, RuleKey> constructCompileRuleKeys(Operation operation, ImmutableMap<Flavor, AppleCxxPlatform> cxxPlatforms) {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    String source = "source.cpp";
    DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, FakeFileHashCache.createFromStrings(ImmutableMap.<String, String>builder().put("source.cpp", Strings.repeat("a", 40)).build()), pathResolver, ruleFinder);
    BuildTarget target = BuildTargetFactory.newInstance("//:target");
    ImmutableMap.Builder<Flavor, RuleKey> ruleKeys = ImmutableMap.builder();
    for (Map.Entry<Flavor, AppleCxxPlatform> entry : cxxPlatforms.entrySet()) {
        CxxSourceRuleFactory cxxSourceRuleFactory = CxxSourceRuleFactory.builder().setParams(new FakeBuildRuleParamsBuilder(target).build()).setResolver(resolver).setPathResolver(pathResolver).setRuleFinder(ruleFinder).setCxxBuckConfig(CxxPlatformUtils.DEFAULT_CONFIG).setCxxPlatform(entry.getValue().getCxxPlatform()).setPicType(CxxSourceRuleFactory.PicType.PIC).build();
        CxxPreprocessAndCompile rule;
        switch(operation) {
            case PREPROCESS_AND_COMPILE:
                rule = cxxSourceRuleFactory.createPreprocessAndCompileBuildRule(source, CxxSource.of(CxxSource.Type.CXX, new FakeSourcePath(source), ImmutableList.of()));
                break;
            case COMPILE:
                rule = cxxSourceRuleFactory.createCompileBuildRule(source, CxxSource.of(CxxSource.Type.CXX_CPP_OUTPUT, new FakeSourcePath(source), ImmutableList.of()));
                break;
            default:
                throw new IllegalStateException();
        }
        ruleKeys.put(entry.getKey(), ruleKeyFactory.build(rule));
    }
    return ruleKeys.build();
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) CxxPreprocessAndCompile(com.facebook.buck.cxx.CxxPreprocessAndCompile) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) RuleKey(com.facebook.buck.rules.RuleKey) Matchers.containsString(org.hamcrest.Matchers.containsString) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ImmutableMap(com.google.common.collect.ImmutableMap) CxxSourceRuleFactory(com.facebook.buck.cxx.CxxSourceRuleFactory) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 50 with SourcePathRuleFinder

use of com.facebook.buck.rules.SourcePathRuleFinder in project buck by facebook.

the class AppleDescriptionsTest method convertToFlatCxxHeadersWithPrefix.

@Test
public void convertToFlatCxxHeadersWithPrefix() {
    SourcePathResolver resolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    assertEquals(ImmutableMap.<String, SourcePath>of("prefix/some_file.h", new FakeSourcePath("path/to/some_file.h"), "prefix/another_file.h", new FakeSourcePath("path/to/another_file.h"), "prefix/a_file.h", new FakeSourcePath("different/path/to/a_file.h"), "prefix/file.h", new FakeSourcePath("file.h")), AppleDescriptions.convertToFlatCxxHeaders(Paths.get("prefix"), resolver::getRelativePath, ImmutableSet.of(new FakeSourcePath("path/to/some_file.h"), new FakeSourcePath("path/to/another_file.h"), new FakeSourcePath("different/path/to/a_file.h"), new FakeSourcePath("file.h"))));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Aggregations

SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)517 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)466 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)405 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)376 Test (org.junit.Test)352 BuildTarget (com.facebook.buck.model.BuildTarget)250 BuildRule (com.facebook.buck.rules.BuildRule)188 SourcePath (com.facebook.buck.rules.SourcePath)151 Path (java.nio.file.Path)151 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)149 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)139 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)131 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)94 PathSourcePath (com.facebook.buck.rules.PathSourcePath)92 TargetGraph (com.facebook.buck.rules.TargetGraph)91 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)87 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)73 RuleKey (com.facebook.buck.rules.RuleKey)72 ImmutableList (com.google.common.collect.ImmutableList)52 ExecutionContext (com.facebook.buck.step.ExecutionContext)50