use of com.facebook.buck.rules.ExplicitBuildTargetSourcePath in project buck by facebook.
the class OcamlStaticLibrary method getLinkableInput.
private NativeLinkableInput getLinkableInput(boolean isBytecode) {
NativeLinkableInput.Builder inputBuilder = NativeLinkableInput.builder();
// Add linker flags.
inputBuilder.addAllArgs(StringArg.from(linkerFlags));
// Add arg and input for static library.
UnflavoredBuildTarget staticBuildTarget = staticLibraryTarget.getUnflavoredBuildTarget();
inputBuilder.addArgs(SourcePathArg.of(new ExplicitBuildTargetSourcePath(ocamlLibraryBuild.getBuildTarget(), isBytecode ? OcamlBuildContext.getBytecodeOutputPath(staticBuildTarget, getProjectFilesystem(), /* isLibrary */
true) : OcamlBuildContext.getNativeOutputPath(staticBuildTarget, getProjectFilesystem(), /* isLibrary */
true))));
// Add args and inputs for C object files.
for (SourcePath objFile : objFiles) {
inputBuilder.addArgs(SourcePathArg.of(objFile));
}
return inputBuilder.build();
}
use of com.facebook.buck.rules.ExplicitBuildTargetSourcePath in project buck by facebook.
the class CxxTestTest method interpretResults.
@Test
public void interpretResults() throws Exception {
final Path expectedExitCode = Paths.get("output");
final Path expectedOutput = Paths.get("output");
final Path expectedResults = Paths.get("results");
FakeCxxTest cxxTest = new FakeCxxTest() {
@Override
public SourcePath getSourcePathToOutput() {
return new ExplicitBuildTargetSourcePath(getBuildTarget(), Paths.get("output"));
}
@Override
protected Path getPathToTestExitCode() {
return expectedExitCode;
}
@Override
protected Path getPathToTestOutput() {
return expectedOutput;
}
@Override
protected Path getPathToTestResults() {
return expectedResults;
}
@Override
protected ImmutableList<TestResultSummary> parseResults(Path exitCode, Path output, Path results) throws Exception {
assertEquals(expectedExitCode, exitCode);
assertEquals(expectedOutput, output);
assertEquals(expectedResults, results);
return ImmutableList.of();
}
};
ExecutionContext executionContext = TestExecutionContext.newInstance();
Callable<TestResults> result = cxxTest.interpretTestResults(executionContext, /* isUsingTestSelectors */
false);
result.call();
}
use of com.facebook.buck.rules.ExplicitBuildTargetSourcePath in project buck by facebook.
the class CxxTestTest method runTests.
@Test
public void runTests() {
final ImmutableList<String> command = ImmutableList.of("hello", "world");
FakeCxxTest cxxTest = new FakeCxxTest() {
@Override
public SourcePath getSourcePathToOutput() {
return new ExplicitBuildTargetSourcePath(getBuildTarget(), Paths.get("output"));
}
@Override
protected ImmutableList<String> getShellCommand(SourcePathResolver resolver, Path output) {
return command;
}
@Override
public Tool getExecutableCommand() {
CommandTool.Builder builder = new CommandTool.Builder();
command.forEach(builder::addArg);
return builder.build();
}
};
ExecutionContext executionContext = TestExecutionContext.newInstance();
TestRunningOptions options = TestRunningOptions.builder().setTestSelectorList(TestSelectorList.empty()).build();
ImmutableList<Step> actualSteps = cxxTest.runTests(executionContext, options, createMock(SourcePathResolver.class), FakeTestRule.NOOP_REPORTING_CALLBACK);
CxxTestStep cxxTestStep = new CxxTestStep(new FakeProjectFilesystem(), command, ImmutableMap.of(), cxxTest.getPathToTestExitCode(), cxxTest.getPathToTestOutput(), TEST_TIMEOUT_MS);
assertEquals(cxxTestStep, Iterables.getLast(actualSteps));
}
use of com.facebook.buck.rules.ExplicitBuildTargetSourcePath in project buck by facebook.
the class HalideLibraryDescriptionTest method testCreateBuildRule.
@Test
public void testCreateBuildRule() throws Exception {
// Set up a #halide-compiler rule, then set up a halide_library rule, and
// check that the library rule depends on the compiler rule.
BuildTarget compilerTarget = BuildTargetFactory.newInstance("//:rule").withFlavors(HalideLibraryDescription.HALIDE_COMPILER_FLAVOR);
BuildTarget libTarget = BuildTargetFactory.newInstance("//:rule");
ProjectFilesystem filesystem = new FakeProjectFilesystem();
HalideLibraryBuilder compilerBuilder = new HalideLibraryBuilder(compilerTarget);
compilerBuilder.setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("main.cpp"))));
HalideLibraryBuilder libBuilder = new HalideLibraryBuilder(libTarget);
TargetGraph targetGraph = TargetGraphFactory.newInstance(compilerBuilder.build(), libBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
HalideLibrary lib = (HalideLibrary) libBuilder.build(resolver, filesystem, targetGraph);
// Check that the library rule has the correct preprocessor input.
CxxPlatform cxxPlatform = CxxLibraryBuilder.createDefaultPlatform();
String headerName = "rule.h";
BuildTarget flavoredLibTarget = libTarget.withFlavors(HalideLibraryDescription.HALIDE_COMPILE_FLAVOR, cxxPlatform.getFlavor());
Path headerPath = HalideCompile.headerOutputPath(flavoredLibTarget, lib.getProjectFilesystem(), Optional.empty());
CxxSymlinkTreeHeaders publicHeaders = (CxxSymlinkTreeHeaders) lib.getCxxPreprocessorInput(cxxPlatform, HeaderVisibility.PUBLIC).getIncludes().get(0);
assertThat(publicHeaders.getIncludeType(), Matchers.equalTo(CxxPreprocessables.IncludeType.SYSTEM));
assertThat(publicHeaders.getNameToPathMap(), Matchers.equalTo(ImmutableMap.<Path, SourcePath>of(Paths.get(headerName), new ExplicitBuildTargetSourcePath(flavoredLibTarget, headerPath))));
// Check that the library rule has the correct native linkable input.
NativeLinkableInput input = lib.getNativeLinkableInput(cxxPlatform, Linker.LinkableDepType.STATIC);
BuildRule buildRule = FluentIterable.from(input.getArgs()).transformAndConcat(arg -> arg.getDeps(new SourcePathRuleFinder(resolver))).get(0);
assertThat(buildRule, is(instanceOf(Archive.class)));
}
use of com.facebook.buck.rules.ExplicitBuildTargetSourcePath 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);
}
Aggregations