use of com.google.common.collect.ImmutableSortedSet in project buck by facebook.
the class CxxBinaryIntegrationTest method testInferCxxBinaryWithoutDeps.
@Test
public void testInferCxxBinaryWithoutDeps() throws IOException, InterruptedException {
assumeTrue(Platform.detect() != Platform.WINDOWS);
ProjectWorkspace workspace = InferHelper.setupCxxInferWorkspace(this, tmp, Optional.empty());
workspace.setupCxxSandboxing(sandboxSources);
CxxBuckConfig cxxBuckConfig = new CxxBuckConfig(workspace.asCell().getBuckConfig());
CxxPlatform cxxPlatform = CxxPlatformUtils.build(cxxBuckConfig);
BuildTarget inputBuildTarget = BuildTargetFactory.newInstance(workspace.getDestPath(), "//foo:simple");
String inputBuildTargetName = inputBuildTarget.withFlavors(CxxInferEnhancer.InferFlavors.INFER.get()).getFullyQualifiedName();
/*
* Build the given target and check that it succeeds.
*/
workspace.runBuckCommand("build", inputBuildTargetName).assertSuccess();
/*
* Check that all the required build targets have been generated.
*/
String sourceName = "simple.cpp";
String sourceFull = "foo/" + sourceName;
CxxSourceRuleFactory cxxSourceRuleFactory = CxxSourceRuleFactoryHelper.of(workspace.getDestPath(), inputBuildTarget, cxxPlatform, cxxBuckConfig);
// this is unflavored, but bounded to the InferCapture build rule
BuildTarget captureBuildTarget = cxxSourceRuleFactory.createInferCaptureBuildTarget(sourceName);
// this is unflavored, but necessary to run the compiler successfully
BuildTarget headerSymlinkTreeTarget = CxxDescriptionEnhancer.createHeaderSymlinkTreeTarget(inputBuildTarget, HeaderVisibility.PRIVATE, cxxPlatform.getFlavor());
BuildTarget sandboxTreeTarget = CxxDescriptionEnhancer.createSandboxSymlinkTreeTarget(inputBuildTarget, cxxPlatform.getFlavor());
// this is flavored, and denotes the analysis step (generates a local report)
BuildTarget inferAnalysisTarget = inputBuildTarget.withFlavors(CxxInferEnhancer.InferFlavors.INFER_ANALYZE.get());
// this is flavored and corresponds to the top level target (the one give in input to buck)
BuildTarget inferReportTarget = inputBuildTarget.withFlavors(CxxInferEnhancer.InferFlavors.INFER.get());
BuildTarget aggregatedDepsTarget = cxxSourceRuleFactory.createAggregatedPreprocessDepsBuildTarget();
ImmutableSortedSet.Builder<BuildTarget> targetsBuilder = ImmutableSortedSet.<BuildTarget>naturalOrder().add(aggregatedDepsTarget, headerSymlinkTreeTarget, captureBuildTarget, inferAnalysisTarget, inferReportTarget);
if (sandboxSources) {
targetsBuilder.add(sandboxTreeTarget);
}
BuckBuildLog buildLog = workspace.getBuildLog();
assertThat(buildLog.getAllTargets(), containsInAnyOrder(targetsBuilder.build().toArray()));
buildLog.assertTargetBuiltLocally(aggregatedDepsTarget.toString());
buildLog.assertTargetBuiltLocally(headerSymlinkTreeTarget.toString());
buildLog.assertTargetBuiltLocally(captureBuildTarget.toString());
buildLog.assertTargetBuiltLocally(inferAnalysisTarget.toString());
buildLog.assertTargetBuiltLocally(inferReportTarget.toString());
/*
* Check that running a build again results in no builds since nothing has changed.
*/
// clear for new build
workspace.resetBuildLogFile();
workspace.runBuckCommand("build", inputBuildTargetName).assertSuccess();
buildLog = workspace.getBuildLog();
assertEquals(ImmutableSet.of(inferReportTarget), buildLog.getAllTargets());
buildLog.assertTargetHadMatchingRuleKey(inferReportTarget.toString());
/*
* Check that changing the source file results in running the capture/analysis rules again.
*/
workspace.resetBuildLogFile();
workspace.replaceFileContents(sourceFull, "*s = 42;", "");
workspace.runBuckCommand("build", inputBuildTargetName).assertSuccess();
buildLog = workspace.getBuildLog();
targetsBuilder = ImmutableSortedSet.<BuildTarget>naturalOrder().add(aggregatedDepsTarget, captureBuildTarget, inferAnalysisTarget, inferReportTarget);
if (sandboxSources) {
targetsBuilder.add(headerSymlinkTreeTarget, sandboxTreeTarget);
}
assertEquals(buildLog.getAllTargets(), targetsBuilder.build());
buildLog.assertTargetBuiltLocally(captureBuildTarget.toString());
buildLog.assertTargetBuiltLocally(inferAnalysisTarget.toString());
if (sandboxSources) {
buildLog.assertTargetHadMatchingRuleKey(headerSymlinkTreeTarget.toString());
buildLog.assertTargetHadMatchingInputRuleKey(sandboxTreeTarget.toString());
buildLog.assertTargetBuiltLocally(aggregatedDepsTarget.toString());
} else {
buildLog.assertTargetHadMatchingRuleKey(aggregatedDepsTarget.toString());
}
}
use of com.google.common.collect.ImmutableSortedSet 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;
}
use of com.google.common.collect.ImmutableSortedSet in project buck by facebook.
the class LuaBinaryDescriptionTest method platformDeps.
@Test
public void platformDeps() throws Exception {
FlavorDomain<PythonPlatform> pythonPlatforms = FlavorDomain.of("Python Platform", PY2, PY3);
CxxBuckConfig cxxBuckConfig = new CxxBuckConfig(FakeBuckConfig.builder().build());
CxxLibraryBuilder py2LibBuilder = new CxxLibraryBuilder(PYTHON2_DEP_TARGET);
CxxLibraryBuilder py3LibBuilder = new CxxLibraryBuilder(PYTHON3_DEP_TARGET);
CxxLibraryBuilder py2CxxLibraryBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:py2_library")).setSoname("libpy2.so").setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("hello.c"))));
CxxLibraryBuilder py3CxxLibraryBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:py3_library")).setSoname("libpy3.so").setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("hello.c"))));
CxxPythonExtensionBuilder cxxPythonExtensionBuilder = new CxxPythonExtensionBuilder(BuildTargetFactory.newInstance("//:extension"), pythonPlatforms, cxxBuckConfig, CxxTestBuilder.createDefaultPlatforms()).setPlatformDeps(PatternMatchedCollection.<ImmutableSortedSet<BuildTarget>>builder().add(Pattern.compile(PY2.getFlavor().toString()), ImmutableSortedSet.of(py2CxxLibraryBuilder.getTarget())).add(Pattern.compile(PY3.getFlavor().toString()), ImmutableSortedSet.of(py3CxxLibraryBuilder.getTarget())).build());
LuaBinaryBuilder luaBinaryBuilder = new LuaBinaryBuilder(new LuaBinaryDescription(FakeLuaConfig.DEFAULT, cxxBuckConfig, CxxPlatformUtils.DEFAULT_PLATFORM, CxxPlatformUtils.DEFAULT_PLATFORMS, pythonPlatforms), BuildTargetFactory.newInstance("//:binary")).setMainModule("main").setDeps(ImmutableSortedSet.of(cxxPythonExtensionBuilder.getTarget()));
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(py2LibBuilder.build(), py3LibBuilder.build(), py2CxxLibraryBuilder.build(), py3CxxLibraryBuilder.build(), cxxPythonExtensionBuilder.build(), luaBinaryBuilder.build()), new DefaultTargetNodeToBuildRuleTransformer());
py2LibBuilder.build(resolver);
py3LibBuilder.build(resolver);
py2CxxLibraryBuilder.build(resolver);
py3CxxLibraryBuilder.build(resolver);
cxxPythonExtensionBuilder.build(resolver);
LuaBinary luaBinary = luaBinaryBuilder.build(resolver);
LuaPackageComponents components = luaBinary.getComponents();
assertThat(components.getNativeLibraries().keySet(), Matchers.hasItem("libpy2.so"));
assertThat(components.getNativeLibraries().keySet(), Matchers.not(Matchers.hasItem("libpy3.so")));
}
use of com.google.common.collect.ImmutableSortedSet in project buck by facebook.
the class AbstractNodeBuilder method getDepsFromArg.
@SuppressWarnings("unchecked")
private ImmutableSortedSet<BuildTarget> getDepsFromArg() {
// Grab them in the unsafest way I know.
try {
Field depsField = arg.getClass().getField("deps");
Object deps = depsField.get(arg);
if (deps == null) {
return ImmutableSortedSet.of();
}
// Here's a whole series of assumptions in one lump of a Bad Idea.
return (ImmutableSortedSet<BuildTarget>) deps;
} catch (ReflectiveOperationException ignored) {
// Field doesn't exist: no deps.
return ImmutableSortedSet.of();
}
}
use of com.google.common.collect.ImmutableSortedSet in project buck by facebook.
the class ClasspathMacroExpanderTest method extractRuleKeyAppendables.
@Test
public void extractRuleKeyAppendables() throws Exception {
TargetNode<?, ?> depNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//exciting:dep")).addSrc(Paths.get("Dep.java")).build();
TargetNode<?, ?> ruleNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//exciting:target")).addSrc(Paths.get("Other.java")).addDep(depNode.getBuildTarget()).build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(depNode, ruleNode);
BuildRuleResolver ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
BuildRule rule = ruleResolver.requireRule(ruleNode.getBuildTarget());
BuildRule dep = ruleResolver.requireRule(depNode.getBuildTarget());
BuildTarget forTarget = BuildTargetFactory.newInstance("//:rule");
Object ruleKeyAppendables = expander.extractRuleKeyAppendables(forTarget, createCellRoots(filesystem), ruleResolver, ImmutableList.of(rule.getBuildTarget().toString()));
assertThat(ruleKeyAppendables, Matchers.instanceOf(ImmutableSortedSet.class));
Set<BuildTarget> seenBuildTargets = new LinkedHashSet<>();
for (Object appendable : ((ImmutableSortedSet<?>) ruleKeyAppendables)) {
assertThat(appendable, Matchers.instanceOf(BuildTargetSourcePath.class));
seenBuildTargets.add(((BuildTargetSourcePath<?>) appendable).getTarget());
}
assertThat(seenBuildTargets, Matchers.equalTo(ImmutableSortedSet.of(rule.getBuildTarget(), dep.getBuildTarget())));
}
Aggregations