Search in sources :

Example 41 with PathSourcePath

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

the class HaskellPrebuiltLibraryDescriptionTest method interfaces.

@Test
public void interfaces() throws Exception {
    PathSourcePath interfaces = new FakeSourcePath("interfaces");
    BuildTarget target = BuildTargetFactory.newInstance("//:rule");
    PrebuiltHaskellLibraryBuilder builder = new PrebuiltHaskellLibraryBuilder(target).setVersion("1.0.0").setDb(new FakeSourcePath("package.conf.d")).setImportDirs(ImmutableList.of(interfaces));
    TargetGraph targetGraph = TargetGraphFactory.newInstance(builder.build());
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    PrebuiltHaskellLibrary library = builder.build(resolver, filesystem, targetGraph);
    HaskellCompileInput input = library.getCompileInput(CxxPlatformUtils.DEFAULT_PLATFORM, Linker.LinkableDepType.STATIC);
    assertThat(input.getPackages().get(0).getInterfaces(), Matchers.contains(interfaces));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath) TargetGraph(com.facebook.buck.rules.TargetGraph) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 42 with PathSourcePath

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

the class DefaultJavaLibraryTest method createDefaultJavaLibraryRuleWithAbiKey.

private BuildRule createDefaultJavaLibraryRuleWithAbiKey(BuildTarget buildTarget, ImmutableSet<String> srcs, ImmutableSortedSet<BuildRule> deps, ImmutableSortedSet<BuildRule> exportedDeps, Optional<AbstractJavacOptions.SpoolMode> spoolMode, ImmutableList<String> postprocessClassesCommands) {
    ProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    ImmutableSortedSet<? extends SourcePath> srcsAsPaths = FluentIterable.from(srcs).transform(Paths::get).transform(p -> new PathSourcePath(projectFilesystem, p)).toSortedSet(Ordering.natural());
    BuildRuleParams buildRuleParams = new FakeBuildRuleParamsBuilder(buildTarget).setDeclaredDeps(ImmutableSortedSet.copyOf(deps)).build();
    JavacOptions javacOptions = spoolMode.isPresent() ? JavacOptions.builder(DEFAULT_JAVAC_OPTIONS).setSpoolMode(spoolMode.get()).build() : DEFAULT_JAVAC_OPTIONS;
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    DefaultJavaLibrary defaultJavaLibrary = new DefaultJavaLibrary(buildRuleParams, new SourcePathResolver(ruleFinder), ruleFinder, srcsAsPaths, /* resources */
    ImmutableSet.of(), javacOptions.getGeneratedSourceFolderName(), /* proguardConfig */
    Optional.empty(), postprocessClassesCommands, exportedDeps, /* providedDeps */
    ImmutableSortedSet.of(), ImmutableSortedSet.of(), javacOptions.trackClassUsage(), /* additionalClasspathEntries */
    ImmutableSet.of(), new JavacToJarStepFactory(javacOptions, JavacOptionsAmender.IDENTITY), /* resourcesRoot */
    Optional.empty(), /* manifest file */
    Optional.empty(), /* mavenCoords */
    Optional.empty(), /* tests */
    ImmutableSortedSet.of(), /* classesToRemoveFromJar */
    ImmutableSet.of()) {
    };
    ruleResolver.addToIndex(defaultJavaLibrary);
    return defaultJavaLibrary;
}
Also used : FakeBuildContext(com.facebook.buck.rules.FakeBuildContext) StepRunner(com.facebook.buck.step.StepRunner) ActionGraph(com.facebook.buck.rules.ActionGraph) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) InputBasedRuleKeyFactory(com.facebook.buck.rules.keys.InputBasedRuleKeyFactory) RichStream(com.facebook.buck.util.RichStream) GenruleBuilder(com.facebook.buck.shell.GenruleBuilder) Ansi(com.facebook.buck.util.Ansi) Assert.assertThat(org.junit.Assert.assertThat) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) ByteArrayInputStream(java.io.ByteArrayInputStream) RuleKey(com.facebook.buck.rules.RuleKey) FluentIterable(com.google.common.collect.FluentIterable) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Assert.fail(org.junit.Assert.fail) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Splitter(com.google.common.base.Splitter) Path(java.nio.file.Path) JavaPackageFinder(com.facebook.buck.jvm.core.JavaPackageFinder) AndroidPlatformTarget(com.facebook.buck.android.AndroidPlatformTarget) Verbosity(com.facebook.buck.util.Verbosity) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) AndroidLibraryBuilder(com.facebook.buck.android.AndroidLibraryBuilder) TargetGraph(com.facebook.buck.rules.TargetGraph) Set(java.util.Set) DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) DEFAULT_JAVAC_OPTIONS(com.facebook.buck.jvm.java.JavaCompilationConstants.DEFAULT_JAVAC_OPTIONS) BuildTarget(com.facebook.buck.model.BuildTarget) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) EasyMock.createNiceMock(org.easymock.EasyMock.createNiceMock) Matchers.equalTo(org.hamcrest.Matchers.equalTo) PathSourcePath(com.facebook.buck.rules.PathSourcePath) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ZipOutputStream(java.util.zip.ZipOutputStream) Iterables(com.google.common.collect.Iterables) Step(com.facebook.buck.step.Step) SourcePath(com.facebook.buck.rules.SourcePath) Hashing(com.google.common.hash.Hashing) FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) BuckEventBusFactory(com.facebook.buck.event.BuckEventBusFactory) BuildRule(com.facebook.buck.rules.BuildRule) ExecutionContext(com.facebook.buck.step.ExecutionContext) LinkOption(java.nio.file.LinkOption) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) MoreAsserts(com.facebook.buck.testutil.MoreAsserts) ImmutableList(com.google.common.collect.ImmutableList) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) BuildTargetFactory(com.facebook.buck.model.BuildTargetFactory) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) Suppliers(com.google.common.base.Suppliers) EasyMock.replay(org.easymock.EasyMock.replay) Nullable(javax.annotation.Nullable) MoreCollectors(com.facebook.buck.util.MoreCollectors) Before(org.junit.Before) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Charsets(com.google.common.base.Charsets) Assert.assertNotNull(org.junit.Assert.assertNotNull) TargetNode(com.facebook.buck.rules.TargetNode) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) Assert.assertTrue(org.junit.Assert.assertTrue) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) IOException(java.io.IOException) EasyMock.expect(org.easymock.EasyMock.expect) HashingDeterministicJarWriter(com.facebook.buck.io.HashingDeterministicJarWriter) Console(com.facebook.buck.util.Console) EasyMock(org.easymock.EasyMock) HumanReadableException(com.facebook.buck.util.HumanReadableException) File(java.io.File) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) Rule(org.junit.Rule) Ordering(com.google.common.collect.Ordering) Paths(java.nio.file.Paths) TargetGraphFactory(com.facebook.buck.testutil.TargetGraphFactory) FileHashCache(com.facebook.buck.util.cache.FileHashCache) BuildContext(com.facebook.buck.rules.BuildContext) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) TemporaryFolder(org.junit.rules.TemporaryFolder) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Paths(java.nio.file.Paths)

Example 43 with PathSourcePath

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

the class Jsr199JavacIntegrationTest method createJavac.

private Jsr199Javac createJavac(boolean withSyntaxError, Optional<Path> javacJar) throws IOException {
    Path exampleJava = tmp.newFile("Example.java");
    Files.write(exampleJava, Joiner.on('\n').join("package com.example;", "", "public class Example {" + (withSyntaxError ? "" : "}")).getBytes(Charsets.UTF_8));
    Path pathToOutputDirectory = Paths.get("out");
    tmp.newFolder(pathToOutputDirectory.toString());
    Optional<SourcePath> jar = javacJar.map(p -> new PathSourcePath(new FakeProjectFilesystem(), p));
    if (jar.isPresent()) {
        return new JarBackedJavac(JavacOptions.COM_SUN_TOOLS_JAVAC_API_JAVAC_TOOL, ImmutableSet.of(jar.get()));
    }
    return new JdkProvidedInMemoryJavac();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath)

Example 44 with PathSourcePath

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

the class JavaLibrarySymbolsFinderTest method extractSymbolsFromSrcs.

@Test
public void extractSymbolsFromSrcs() throws IOException {
    TestDataHelper.createProjectWorkspaceForScenario(this, "java_library_symbols_finder", tmp).setUp();
    ProjectFilesystem projectFilesystem = new ProjectFilesystem(tmp.getRoot());
    ImmutableSortedSet<SourcePath> srcs = ImmutableSortedSet.<SourcePath>naturalOrder().addAll(Stream.of("Example1.java", "Example2.java").map(Paths::get).map(p -> new PathSourcePath(projectFilesystem, p)).iterator()).add(new DefaultBuildTargetSourcePath(BuildTargetFactory.newInstance("//foo:bar"))).build();
    JavaLibrarySymbolsFinder finder = new JavaLibrarySymbolsFinder(srcs, javaFileParser, /* shouldRecordRequiredSymbols */
    true);
    Symbols symbols = finder.extractSymbols();
    assertEquals(ImmutableSet.of("com.example.Example1", "com.example.Example2"), ImmutableSet.copyOf(symbols.provided));
    assertEquals(ImmutableSet.of("com.example.other.Bar", "com.example.other.Foo"), ImmutableSet.copyOf(symbols.required));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) Test(org.junit.Test)

Example 45 with PathSourcePath

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

the class JavaLibrarySymbolsFinderTest method onlyNonGeneratedSrcsShouldAffectRuleKey.

@Test
@SuppressWarnings("PMD.PrematureDeclaration")
public void onlyNonGeneratedSrcsShouldAffectRuleKey() throws IOException {
    TestDataHelper.createProjectWorkspaceForScenario(this, "java_library_symbols_finder", tmp).setUp();
    final ProjectFilesystem projectFilesystem = new ProjectFilesystem(tmp.getRoot());
    Function<String, SourcePath> convert = src -> new PathSourcePath(projectFilesystem, Paths.get(src));
    SourcePath example1 = convert.apply("Example1.java");
    SourcePath example2 = convert.apply("Example2.java");
    final BuildTarget fakeBuildTarget = BuildTargetFactory.newInstance("//foo:GenEx.java");
    SourcePath generated = new DefaultBuildTargetSourcePath(fakeBuildTarget);
    final boolean shouldRecordRequiredSymbols = true;
    JavaLibrarySymbolsFinder example1Finder = new JavaLibrarySymbolsFinder(ImmutableSortedSet.of(example1), javaFileParser, shouldRecordRequiredSymbols);
    JavaLibrarySymbolsFinder example2Finder = new JavaLibrarySymbolsFinder(ImmutableSortedSet.of(example2), javaFileParser, shouldRecordRequiredSymbols);
    JavaLibrarySymbolsFinder example1AndGeneratedSrcFinder = new JavaLibrarySymbolsFinder(ImmutableSortedSet.of(example1, generated), javaFileParser, shouldRecordRequiredSymbols);
    // Mock out calls to a SourcePathResolver so we can create a legitimate
    // DefaultRuleKeyFactory.
    final SourcePathRuleFinder ruleFinder = createMock(SourcePathRuleFinder.class);
    final SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    expect(ruleFinder.getRule(anyObject(SourcePath.class))).andAnswer(() -> {
        SourcePath input = (SourcePath) EasyMock.getCurrentArguments()[0];
        if (input instanceof ExplicitBuildTargetSourcePath) {
            return Optional.of(new FakeBuildRule(fakeBuildTarget, pathResolver));
        } else {
            return Optional.empty();
        }
    }).anyTimes();
    // Calculates the RuleKey for a JavaSymbolsRule with the specified JavaLibrarySymbolsFinder.
    final FileHashCache fileHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(projectFilesystem)));
    final DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, fileHashCache, pathResolver, ruleFinder);
    Function<JavaLibrarySymbolsFinder, RuleKey> createRuleKey = finder -> {
        JavaSymbolsRule javaSymbolsRule = new JavaSymbolsRule(BuildTargetFactory.newInstance("//foo:rule"), finder, ImmutableSortedSet.of(), ObjectMappers.newDefaultInstance(), projectFilesystem);
        return ruleKeyFactory.build(javaSymbolsRule);
    };
    RuleKey key1 = createRuleKey.apply(example1Finder);
    RuleKey key2 = createRuleKey.apply(example2Finder);
    RuleKey key3 = createRuleKey.apply(example1AndGeneratedSrcFinder);
    assertNotNull(key1);
    assertNotNull(key2);
    assertNotNull(key3);
    assertNotEquals("Two instances of a JavaSymbolsRule with different srcs should change the RuleKey.", key1, key2);
    assertEquals("Introducing an extra generated .java file to the srcs should not change the RuleKey.", key1, key3);
}
Also used : FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) ObjectMappers(com.facebook.buck.util.ObjectMappers) SourcePath(com.facebook.buck.rules.SourcePath) TestDataHelper(com.facebook.buck.testutil.integration.TestDataHelper) TemporaryPaths(com.facebook.buck.testutil.integration.TemporaryPaths) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) ImmutableList(com.google.common.collect.ImmutableList) JavaFileParser(com.facebook.buck.jvm.java.JavaFileParser) RuleKey(com.facebook.buck.rules.RuleKey) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildTargetFactory(com.facebook.buck.model.BuildTargetFactory) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) EasyMock.createMock(org.easymock.EasyMock.createMock) EasyMock.anyObject(org.easymock.EasyMock.anyObject) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) Assert.assertNotNull(org.junit.Assert.assertNotNull) Test(org.junit.Test) IOException(java.io.IOException) EasyMock.expect(org.easymock.EasyMock.expect) JavacOptions(com.facebook.buck.jvm.java.JavacOptions) EasyMock(org.easymock.EasyMock) DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) BuildTarget(com.facebook.buck.model.BuildTarget) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) Rule(org.junit.Rule) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) FileHashCache(com.facebook.buck.util.cache.FileHashCache) PathSourcePath(com.facebook.buck.rules.PathSourcePath) Optional(java.util.Optional) Assert.assertEquals(org.junit.Assert.assertEquals) DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) FileHashCache(com.facebook.buck.util.cache.FileHashCache) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) RuleKey(com.facebook.buck.rules.RuleKey) PathSourcePath(com.facebook.buck.rules.PathSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) Test(org.junit.Test)

Aggregations

PathSourcePath (com.facebook.buck.rules.PathSourcePath)114 Test (org.junit.Test)82 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)69 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)68 SourcePath (com.facebook.buck.rules.SourcePath)65 Path (java.nio.file.Path)63 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)60 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)58 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)56 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)52 BuildTarget (com.facebook.buck.model.BuildTarget)51 TargetGraph (com.facebook.buck.rules.TargetGraph)37 BuildRule (com.facebook.buck.rules.BuildRule)26 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)23 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)21 StackedFileHashCache (com.facebook.buck.util.cache.StackedFileHashCache)16 RuleKey (com.facebook.buck.rules.RuleKey)15 DefaultFileHashCache (com.facebook.buck.util.cache.DefaultFileHashCache)15 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)14 ImmutableList (com.google.common.collect.ImmutableList)14