protected void addEnvironmentVariables(ExecutionContext context, ImmutableMap.Builder<String, String> environmentVariablesBuilder) { environmentVariablesBuilder.put("SRCS", Joiner.on(' ').join(srcsToAbsolutePaths.values())); environmentVariablesBuilder.put("OUT", getAbsoluteOutputFilePath()); final Set<String> depFiles = Sets.newHashSet(); final Set<BuildRule> processedBuildRules = Sets.newHashSet(); for (BuildRule dep : getDeps()) { transformNames(processedBuildRules, depFiles, dep); } environmentVariablesBuilder.put( "GEN_DIR", relativeToAbsolutePathFunction.apply(BuckConstant.GEN_PATH).toString()); environmentVariablesBuilder.put("DEPS", Joiner.on(' ').skipNulls().join(depFiles)); environmentVariablesBuilder.put("SRCDIR", absolutePathToSrcDirectory.toString()); environmentVariablesBuilder.put("TMP", absolutePathToTmpDirectory.toString()); Optional<AndroidPlatformTarget> optionalAndroid = context.getAndroidPlatformTargetOptional(); if (optionalAndroid.isPresent()) { AndroidPlatformTarget android = optionalAndroid.get(); environmentVariablesBuilder.put("DX", android.getDxExecutable().toString()); environmentVariablesBuilder.put("ZIPALIGN", android.getZipalignExecutable().toString()); } }
private void createSampleAndroidBinaryRule(BuildRuleResolver ruleResolver) { // Create a java_binary that depends on a java_library so it is possible to create a // java_binary rule with a classpath entry and a main class. BuildTarget libAndroidTarget = BuildTargetFactory.newInstance("//:lib-android"); BuildRule androidLibRule = JavaLibraryBuilder.createBuilder(libAndroidTarget) .addSrc(Paths.get("java/com/facebook/util/Facebook.java")) .build(ruleResolver); BuildTarget keystoreTarget = BuildTargetFactory.newInstance("//keystore:debug"); Keystore keystore = (Keystore) KeystoreBuilder.createBuilder(keystoreTarget) .setStore(Paths.get("keystore/debug.keystore")) .setProperties(Paths.get("keystore/debug.keystore.properties")) .build(ruleResolver); AndroidBinaryBuilder.createBuilder(BuildTargetFactory.newInstance("//:fb4a")) .setManifest(new TestSourcePath("AndroidManifest.xml")) .setTarget("Google Inc.:Google APIs:16") .setOriginalDeps(ImmutableSortedSet.of(androidLibRule)) .setKeystore(keystore) .build(ruleResolver); }
/** * Setup a build rule that updates whenever any header or header dependency changes. * This includes the hash of the header contents and all corresponding transitive * header dependencies. This should be depended on by any compile rules generated * for this higher level rule to make sure we re-compile if any headers change. */ public static CxxHeader createHeaderBuildRule( BuildTarget target, BuildRuleParams params, ImmutableMap<Path, SourcePath> headers) { // TODO(agallagher): In the common case, C/C++ sources only actually use a small // subset of all the headers in their transitive include search space, so this setup // will cause a lot of false rebuilds. Long-term, we should add some sort of dep-file // support to avoid this. BuildRuleParams headerParams = params.copyWithChanges( HEADERS_TYPE, target, /* declaredDeps */ ImmutableSortedSet.copyOf( SourcePaths.filterBuildRuleInputs(headers.values())), /* declaredDeps */ ImmutableSortedSet.<BuildRule>of()); return new CxxHeader(headerParams, headers); }
/** * @return a set of {@link CxxCompile} rules preprocessing, compiling, and assembling the * given input {@link CxxSource} sources. */ public static ImmutableSortedSet<BuildRule> createCompileBuildRules( BuildRuleParams params, BuildRuleResolver resolver, Path compiler, CxxPreprocessorInput preprocessorInput, ImmutableList<String> compilerFlags, Iterable<CxxSource> sources) { ImmutableSortedSet.Builder<BuildRule> rules = ImmutableSortedSet.naturalOrder(); // Iterate over the input C/C++ sources that we need to preprocess, assemble, and compile, // and generate compile rules for them. for (CxxSource source : sources) { rules.add(createCompileBuildRule( params, resolver, compiler, preprocessorInput, compilerFlags, source)); } return rules.build(); }
@Test public void replaceLocationOfFullyQualifiedBuildTarget() throws IOException { ProjectFilesystem filesystem = new FakeProjectFilesystem(); BuildRuleResolver ruleResolver = new BuildRuleResolver(); BuildRule javaBinary = createSampleJavaBinaryRule(ruleResolver); Path outputPath = javaBinary.getPathToOutputFile(); Path absolutePath = outputPath.toAbsolutePath(); String originalCmd = String.format("$(location :%s) $(location %s) $OUT", javaBinary.getBuildTarget().getShortName(), javaBinary.getBuildTarget().getFullyQualifiedName()); Path contextBasePath = javaBinary.getBuildTarget().getBasePath(); Set<? extends BuildRule> deps = ImmutableSet.of(javaBinary); Genrule buildable = (Genrule) createGenrule(ruleResolver, originalCmd, contextBasePath, deps); AbstractGenruleStep genruleStep = buildable.createGenruleStep(); // Interpolate the build target in the genrule cmd string. String transformedString = genruleStep.replaceMatches(filesystem, originalCmd); // Verify that the correct cmd was created. String expectedCmd = String.format("%s %s $OUT", absolutePath, absolutePath); assertEquals(expectedCmd, transformedString); }
@Test public void testAndroidAnnotation() throws IOException { BuildRuleResolver ruleResolver = new BuildRuleResolver(); BuildTarget processorTarget = BuildTargetFactory.newInstance("//java/processor:processor"); BuildRule processorRule = JavaLibraryBuilder .createBuilder(processorTarget) .addSrc(Paths.get("java/processor/processor.java")) .build(ruleResolver); BuildTarget libTarget = BuildTargetFactory.newInstance("//java/lib:lib"); AndroidLibrary library = (AndroidLibrary) AndroidLibraryBuilder .createBuilder(libTarget) .addProcessor("MyProcessor") .addProcessorBuildTarget(processorRule) .build(ruleResolver); AnnotationProcessingData processingData = library.getAnnotationProcessingData(); assertNotNull(processingData.getGeneratedSourceFolderName()); }
@Test public void testDoNotIgnoreAllOfBuckOut() { ProjectFilesystem projectFilesystem = EasyMock.createMock(ProjectFilesystem.class); ImmutableSet<Path> ignorePaths = ImmutableSet.of(Paths.get("buck-out"), Paths.get(".git")); EasyMock.expect(projectFilesystem.getIgnorePaths()).andReturn(ignorePaths); EasyMock.replay(projectFilesystem); BuildTarget buildTarget = BuildTarget.builder("//", "base").build(); BuildRule buildRule = new FakeBuildRule(JavaLibraryDescription.TYPE, buildTarget); Module module = new Module(buildRule, buildTarget); Project.addRootExcludes(module, buildRule, projectFilesystem); ImmutableSortedSet<SourceFolder> expectedExcludeFolders = ImmutableSortedSet.orderedBy(Module.ALPHABETIZER) .add(new SourceFolder("file://$MODULE_DIR$/.git", /* isTestSource */ false)) .add(new SourceFolder("file://$MODULE_DIR$/buck-out/bin", /* isTestSource */ false)) .add(new SourceFolder("file://$MODULE_DIR$/buck-out/log", /* isTestSource */ false)) .build(); assertEquals("Specific subfolders of buck-out should be excluded rather than all of buck-out.", expectedExcludeFolders, module.excludeFolders); EasyMock.verify(projectFilesystem); }
private static int getNumRulesToBuild( ImmutableSet<BuildTarget> buildTargets, final ActionGraph actionGraph) { Set<BuildRule> baseBuildRules = FluentIterable .from(buildTargets) .transform(new Function<HasBuildTarget, BuildRule>() { @Override public BuildRule apply(HasBuildTarget hasBuildTarget) { return actionGraph.findBuildRuleByTarget(hasBuildTarget.getBuildTarget()); } }) .toSet(); Set<BuildRule> allBuildRules = Sets.newHashSet(); for (BuildRule rule : baseBuildRules) { addTransitiveDepsForRule(rule, allBuildRules); } allBuildRules.addAll(baseBuildRules); return allBuildRules.size(); }
/** * Returns a sorted set containing the dependencies which will be hashed in the final ABI key. * @return the dependencies to be hashed in the final ABI key. */ private SortedSet<HasBuildTarget> getDepsForAbiKey() { SortedSet<HasBuildTarget> rulesWithAbiToConsider = Sets.newTreeSet(BUILD_TARGET_COMPARATOR); for (BuildRule dep : Iterables.concat(getDepsForTransitiveClasspathEntries(), providedDeps)) { // This looks odd. DummyJavaAbiRule contains a Buildable that isn't a JavaAbiRule. if (dep instanceof HasJavaAbi) { if (dep instanceof JavaLibrary) { JavaLibrary javaRule = (JavaLibrary) dep; rulesWithAbiToConsider.addAll(javaRule.getOutputClasspathEntries().keys()); } else { rulesWithAbiToConsider.add(dep); } } } // We also need to iterate over inputs that are SourcePaths, since they're only listed as // compile-time deps and not in the "deps" field. If any of these change, we should recompile // the library, since we will (at least) need to repack it. rulesWithAbiToConsider.addAll( SourcePaths.filterBuildRuleInputs(Iterables.concat(srcs, resources))); return rulesWithAbiToConsider; }
private AnnotationProcessingParams( @Nullable BuildTarget ownerTarget, @Nullable ProjectFilesystem filesystem, Set<Path> searchPathElements, Set<String> names, Set<String> parameters, Set<BuildRule> rules, boolean processOnly) { this.ownerTarget = ownerTarget; this.filesystem = filesystem; this.searchPathElements = ImmutableSortedSet.copyOf(searchPathElements); this.names = ImmutableSortedSet.copyOf(names); this.parameters = ImmutableSortedSet.copyOf(parameters); this.rules = ImmutableSortedSet.copyOf(rules); this.processOnly = processOnly; if (!isEmpty() && ownerTarget != null) { Preconditions.checkNotNull(filesystem); } }
@Override public RuleKey.Builder appendToRuleKey(RuleKey.Builder builder) { if (!isEmpty()) { // searchPathElements is not needed here since it comes from rules, which is appended below. String owner = (ownerTarget == null) ? null : ownerTarget.getFullyQualifiedName(); builder.set("owner", owner) .set("names", names) .set("parameters", parameters) .set("processOnly", processOnly); ImmutableList.Builder<String> ruleKeyStrings = ImmutableList.builder(); for (BuildRule rule : rules) { ruleKeyStrings.add(rule.getRuleKey().toString()); } builder.set("annotationProcessorRuleKeys", ruleKeyStrings.build()); } return builder; }
/** * A {@link JavaLibrary} registers the ability to create {@link JavaLibrary#SRC_JAR}s when source * is present and also {@link JavaLibrary#GWT_MODULE_FLAVOR}, if appropriate. */ @Override public void registerFlavors( Arg arg, BuildRule buildRule, ProjectFilesystem projectFilesystem, RuleKeyBuilderFactory ruleKeyBuilderFactory, BuildRuleResolver ruleResolver) { BuildTarget originalBuildTarget = buildRule.getBuildTarget(); Optional<GwtModule> gwtModuleOptional = tryCreateGwtModule( originalBuildTarget, projectFilesystem, ruleKeyBuilderFactory, arg); if (!gwtModuleOptional.isPresent()) { return; } GwtModule gwtModule = gwtModuleOptional.get(); ruleResolver.addToIndex(gwtModule.getBuildTarget(), gwtModule); }
@Test public void testJsonClassPathOutput() throws IOException { // Build a DependencyGraph of build rules manually. BuildRuleResolver ruleResolver = new BuildRuleResolver(); ImmutableList<String> targets = ImmutableList.of( "//:test-android-library", "//:test-java-library"); BuildRule library = JavaLibraryBuilder .createBuilder(BuildTargetFactory.newInstance("//:test-java-library")) .addSrc(Paths.get("src/com/facebook/TestJavaLibrary.java")) .build(ruleResolver); AndroidLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:test-android-library")) .addSrc(Paths.get("src/com/facebook/TestAndroidLibrary.java")) .addDep(library) .build(ruleResolver); PartialGraph partialGraph = createGraphFromBuildRules(ruleResolver, targets); auditClasspathCommand.printJsonClasspath(partialGraph); assertEquals(EXPECTED_JSON, console.getTextWrittenToStdOut()); assertEquals("", console.getTextWrittenToStdErr()); }
@Test public void testReplaceRelativeBinaryBuildRuleRefsInCmd() { BuildRuleResolver ruleResolver = new BuildRuleResolver(); BuildRule javaBinary = createSampleJavaBinaryRule(ruleResolver); String originalCmd = "$(exe :ManifestGenerator) $OUT"; Path contextBasePath = Paths.get("java/com/facebook/util"); Set<? extends BuildRule> deps = ImmutableSet.of(javaBinary); Genrule buildable = (Genrule) createGenrule(ruleResolver, originalCmd, contextBasePath, deps); AbstractGenruleStep genruleStep = buildable.createGenruleStep(); // Interpolate the build target in the genrule cmd string. String transformedString = genruleStep.replaceMatches(fakeFilesystem, originalCmd); // Verify that the correct cmd was created. Path expectedClasspath = getAbsolutePathInBase( GEN_DIR + "/java/com/facebook/util/ManifestGenerator.jar"); String expectedCmd = String.format( "java -jar %s $OUT", expectedClasspath); assertEquals(expectedCmd, transformedString); }
@VisibleForTesting static void addRootExcludes(Module module, BuildRule buildRule, ProjectFilesystem projectFilesystem) { // If in the root of the project, specify ignored paths. if (buildRule != null && buildRule.getBuildTarget().getBasePathWithSlash().isEmpty()) { for (Path path : projectFilesystem.getIgnorePaths()) { // It turns out that ignoring all of buck-out causes problems in IntelliJ: it forces an // extra "modules" folder to appear at the top of the navigation pane that competes with the // ordinary file tree, making navigation a real pain. The hypothesis is that this is because // there are files in buck-out/gen and buck-out/android that IntelliJ freaks out about if it // cannot find them. Therefore, if "buck-out" is listed in the default list of paths to // ignore (which makes sense for other parts of Buck, such as Watchman), then we will ignore // only the appropriate subfolders of buck-out instead. if (BuckConstant.BUCK_OUTPUT_PATH.equals(path)) { addRootExclude(module, BuckConstant.BIN_PATH); addRootExclude(module, BuckConstant.LOG_PATH); } else { addRootExclude(module, path); } } module.isRootModule = true; } }
@Test public void thatMainSourcePathPropagatesToDeps() { BuildRuleResolver resolver = new BuildRuleResolver(); Genrule genrule = GenruleBuilder.createGenrule(BuildTargetFactory.newInstance("//:gen")) .setOut("blah.py") .build(); BuildRuleParams params = BuildRuleParamsFactory.createTrivialBuildRuleParams( BuildTargetFactory.newInstance("//:bin")); PythonBinaryDescription desc = new PythonBinaryDescription(PEX_PATH); PythonBinaryDescription.Arg arg = desc.createUnpopulatedConstructorArg(); arg.deps = Optional.of(ImmutableSortedSet.<BuildRule>of()); arg.main = new BuildRuleSourcePath(genrule); BuildRule rule = desc.createBuildRule(params, resolver, arg); assertEquals( ImmutableSortedSet.<BuildRule>of(genrule), rule.getDeps()); }
@Test public void testShouldWarnUsersWhenThereIsNoOutputForARuleButLocationRequested() { BuildRule ruleWithNoOutput = JavaLibraryBuilder .createBuilder(BuildTarget.builder("//cheese", "java").build()) .build(new BuildRuleResolver()); BuildRule genrule = GenruleBuilder.createGenrule(BuildTarget.builder("//cheese", "cake").build()) .setCmd("$(location //cheese:java") .setOut("cake") .addDep(ruleWithNoOutput) .build(); try { ((Genrule) genrule).createGenruleStep() .replaceMatches(new FakeProjectFilesystem(), "$(location //cheese:java)"); fail("Location was null. Expected HumanReadableException with helpful message."); } catch (HumanReadableException e) { assertTrue( e.getMessage(), e.getMessage().contains("there is no output generated by //cheese:java")); } }
@VisibleForTesting void printTargetsList(SortedMap<String, BuildRule> matchingBuildRules, boolean showOutput, boolean showRuleKey) throws IOException { for (Map.Entry<String, BuildRule> target : matchingBuildRules.entrySet()) { String output = target.getKey(); BuildRule buildRule = target.getValue(); if (showRuleKey) { output += " " + buildRule.getRuleKey(); } if (showOutput) { Path outputPath = buildRule.getPathToOutputFile(); if (outputPath != null) { output += " " + outputPath; } } getStdOut().println(output); } }
private String getObjectOutputPathForRule(BuildRule rule) { if (rule.getType().equals(AppleLibraryDescription.TYPE)) { return Joiner.on('/').join( "$SYMROOT", BaseEncoding .base32() .omitPadding() .encode(rule.getFullyQualifiedName().getBytes()), // $EFFECTIVE_PLATFORM_NAME starts with a dash, so this expands to something like: // Debug-iphonesimulator "$CONFIGURATION$EFFECTIVE_PLATFORM_NAME"); } else if (rule.getType().equals(XcodeNativeDescription.TYPE)) { return "$BUILT_PRODUCTS_DIR"; } else { throw new RuntimeException("Unexpected type: " + rule.getType()); } }
@Test public void testReplaceBinaryBuildRuleRefsInCmd() { BuildRuleResolver ruleResolver = new BuildRuleResolver(); BuildRule javaBinary = createSampleJavaBinaryRule(ruleResolver); String originalCmd = "$(exe //java/com/facebook/util:ManifestGenerator) $OUT"; Path contextBasePath = Paths.get("java/com/facebook/util"); Set<? extends BuildRule> deps = ImmutableSet.of(javaBinary); Genrule buildable = (Genrule) createGenrule(ruleResolver, originalCmd, contextBasePath, deps); AbstractGenruleStep genruleStep = buildable.createGenruleStep(); // Interpolate the build target in the genrule cmd string. String transformedString = genruleStep.replaceMatches(fakeFilesystem, originalCmd); // Verify that the correct cmd was created. Path expectedClasspath = getAbsolutePathInBase( GEN_DIR + "/java/com/facebook/util/ManifestGenerator.jar"); String expectedCmd = String.format( "java -jar %s $OUT", expectedClasspath); assertEquals(expectedCmd, transformedString); }
@Test public void testLabelConjunctionsWithInclude() throws CmdLineException { TestCommandOptions options = getOptions("--include", "windows+linux"); TestRule rule1 = new FakeTestRule( JavaTestDescription.TYPE, ImmutableSet.of(new Label("windows"), new Label("linux")), BuildTargetFactory.newInstance("//:for"), ImmutableSortedSet.<BuildRule>of(), ImmutableSet.<BuildTargetPattern>of()); TestRule rule2 = new FakeTestRule( JavaTestDescription.TYPE, ImmutableSet.of(new Label("windows")), BuildTargetFactory.newInstance("//:lulz"), ImmutableSortedSet.<BuildRule>of(), ImmutableSet.<BuildTargetPattern>of()); List<TestRule> testRules = ImmutableList.of(rule1, rule2); Iterable<TestRule> result = TestCommand.filterTestRules(options, testRules); assertEquals(ImmutableSet.of(rule1), result); }
@VisibleForTesting SortedMap<String, BuildRule> getMatchingBuildRules( final ActionGraph graph, final TargetsCommandPredicate predicate) { // Traverse the DependencyGraph and select all of the rules that accepted by Predicate. AbstractBottomUpTraversal<BuildRule, SortedMap<String, BuildRule>> traversal = new AbstractBottomUpTraversal<BuildRule, SortedMap<String, BuildRule>>(graph) { final SortedMap<String, BuildRule> matchingBuildRules = Maps.newTreeMap(); @Override public void visit(BuildRule rule) { if (predicate.apply(rule)) { matchingBuildRules.put(rule.getFullyQualifiedName(), rule); } } @Override public SortedMap<String, BuildRule> getResult() { return matchingBuildRules; } }; traversal.traverse(); return traversal.getResult(); }
private static FakeCxxPreprocessorDep createFakeCxxPreprocessorDep( BuildTarget target, CxxPreprocessorInput input, BuildRule... deps) { return new FakeCxxPreprocessorDep( new FakeBuildRuleParamsBuilder(target) .setDeps(ImmutableSortedSet.copyOf(deps)) .build(), input); }
@Test public void testThatBuildTargetsFromNativeLinkableDepsContributeToActualDeps() { BuildRuleResolver resolver = new BuildRuleResolver(); BuildTarget target = BuildTargetFactory.newInstance("//foo:bar"); BuildRuleParams params = BuildRuleParamsFactory.createTrivialBuildRuleParams(target); // Create a dummy build rule and add it to the resolver. BuildTarget fakeBuildTarget = BuildTargetFactory.newInstance("//:fake"); FakeBuildRule fakeBuildRule = new FakeBuildRule( new FakeBuildRuleParamsBuilder(fakeBuildTarget).build()); resolver.addToIndex(fakeBuildRule); // Create a native linkable dep and have it list the fake build rule above as a link // time dependency. FakeNativeLinkable nativeLinkable = createNativeLinkable( "//:dep", new NativeLinkableInput( ImmutableSet.of(fakeBuildTarget), ImmutableList.<Path>of(), ImmutableList.<String>of())); // Construct a CxxLink object and pass the native linkable above as the dep. CxxLink cxxLink = CxxLinkableEnhancer.createCxxLinkableBuildRule( params, resolver, DEFAULT_LINKER, ImmutableList.<String>of(), ImmutableList.<String>of(), target, DEFAULT_OUTPUT, DEFAULT_INPUTS, ImmutableSortedSet.<BuildRule>of(nativeLinkable)); // Verify that the fake build rule made it in as a dep. assertTrue(cxxLink.getDeps().contains(fakeBuildRule)); }
@VisibleForTesting int printJsonInputs(PartialGraph partialGraph) throws IOException { final Multimap<String, String> targetInputs = TreeMultimap.create(); new AbstractBottomUpTraversal<BuildRule, Void>(partialGraph.getActionGraph()) { @Override public void visit(BuildRule rule) { for (Path input : rule.getInputs()) { // TODO(user) remove `toString` once Jackson supports serializing Path instances targetInputs.put(rule.getFullyQualifiedName(), input.toString()); } } @Override public Void getResult() { return null; } }.traverse(); // Note: using `asMap` here ensures that the keys are sorted getObjectMapper().writeValue( console.getStdOut(), targetInputs.asMap()); return 0; }
@Nullable private Path getLocationReplacementFrom(ProjectFilesystem filesystem, BuildRule matchingRule) { Path output = matchingRule.getPathToOutputFile(); if (output == null) { return null; } return filesystem.resolve(output); }
private static FakeBuildRule createFakeBuildRule( String target, BuildRule... deps) { return new FakeBuildRule( new FakeBuildRuleParamsBuilder(BuildTargetFactory.newInstance(target)) .setDeps(ImmutableSortedSet.copyOf(deps)) .build()); }
public FakeJavaLibrary( BuildRuleType type, BuildTarget target, ImmutableSortedSet<BuildRule> deps, ImmutableSet<BuildTargetPattern> visibilityPatterns) { super(type, target, deps, visibilityPatterns); this.visibilityPatterns = visibilityPatterns; }
private BuildContext createBuildContext(BuildRule javaLibrary, @Nullable String bootclasspath, @Nullable ProjectFilesystem projectFilesystem) { AndroidPlatformTarget platformTarget = EasyMock.createMock(AndroidPlatformTarget.class); ImmutableList<Path> bootclasspathEntries = (bootclasspath == null) ? ImmutableList.<Path>of(Paths.get("I am not used")) : ImmutableList.of(Paths.get(bootclasspath)); expect(platformTarget.getBootclasspathEntries()).andReturn(bootclasspathEntries) .anyTimes(); replay(platformTarget); if (projectFilesystem == null) { projectFilesystem = EasyMock.createMock(ProjectFilesystem.class); } // TODO(mbolin): Create a utility that populates a BuildContext.Builder with fakes. return BuildContext.builder() .setActionGraph(RuleMap.createGraphFromSingleRule(javaLibrary)) .setStepRunner(EasyMock.createMock(StepRunner.class)) .setProjectFilesystem(projectFilesystem) .setArtifactCache(new NoopArtifactCache()) .setBuildDependencies(BuildDependencies.TRANSITIVE) .setJavaPackageFinder(EasyMock.createMock(JavaPackageFinder.class)) .setAndroidBootclasspathForAndroidPlatformTarget(Optional.of(platformTarget)) .setEventBus(BuckEventBusFactory.newInstance()) .build(); }
private ActionGraph createDependencyGraphFromBuildRules(Iterable<? extends BuildRule> rules) { MutableDirectedGraph<BuildRule> graph = new MutableDirectedGraph<>(); for (BuildRule rule : rules) { for (BuildRule dep : rule.getDeps()) { graph.addEdge(rule, dep); } } return new ActionGraph(graph); }
public Optional<DummyRDotJava> createBuildableForAndroidResources( BuildRuleResolver ruleResolver, boolean createBuildableIfEmptyDeps) { ImmutableSortedSet<BuildRule> originalDeps = originalBuildRuleParams.getDeps(); ImmutableSet<HasAndroidResourceDeps> androidResourceDeps = UnsortedAndroidResourceDeps.createFrom(originalDeps, Optional.<Callback>absent()) .getResourceDeps(); if (androidResourceDeps.isEmpty() && !createBuildableIfEmptyDeps) { return Optional.absent(); } // The androidResourceDeps may contain Buildables, but we need the actual BuildRules. Since this // is going to be used to modify the build graph, we can't just wrap the buildables. Fortunately // we know that the buildables come from the originalDeps. ImmutableSortedSet.Builder<BuildRule> actualDeps = ImmutableSortedSet.naturalOrder(); for (HasAndroidResourceDeps dep : androidResourceDeps) { // If this ever returns null, something has gone horrifically awry. actualDeps.add(ruleResolver.get(dep.getBuildTarget())); } BuildRuleParams dummyRDotJavaParams = originalBuildRuleParams.copyWithChanges( BuildRuleType.DUMMY_R_DOT_JAVA, dummyRDotJavaBuildTarget, actualDeps.build(), /* extraDeps */ ImmutableSortedSet.<BuildRule>of()); DummyRDotJava dummyRDotJava = new DummyRDotJava( dummyRDotJavaParams, androidResourceDeps, javacOptions); ruleResolver.addToIndex(dummyRDotJavaBuildTarget, dummyRDotJava); return Optional.of(dummyRDotJava); }
private BuildRule createSampleJavaBinaryRule(BuildRuleResolver ruleResolver) { // Create a java_binary that depends on a java_library so it is possible to create a // java_binary rule with a classpath entry and a main class. BuildRule javaLibrary = JavaLibraryBuilder .createBuilder(BuildTargetFactory.newInstance("//java/com/facebook/util:util")) .addSrc(Paths.get("java/com/facebook/util/ManifestGenerator.java")) .build(ruleResolver); BuildTarget buildTarget = BuildTargetFactory.newInstance("//java/com/facebook/util:ManifestGenerator"); return new JavaBinaryRuleBuilder(buildTarget) .setDeps(ImmutableSortedSet.of(javaLibrary)) .setMainClass("com.facebook.util.ManifestGenerator") .build(ruleResolver); }
@Override public <A extends Arg> BuildRule createBuildRule( BuildRuleParams params, BuildRuleResolver resolver, A args) { BuildTarget target = params.getBuildTarget(); // We know that the flavour we're being asked to create is valid, since the check is done when // creating the action graph from the target graph. if (JavaLibrary.SRC_JAR.equals(target.getFlavor())) { return new JavaSourceJar(params, args.srcs.get()); } JavacOptions.Builder javacOptions = JavaLibraryDescription.getJavacOptions(args, javacEnv); AnnotationProcessingParams annotationParams = args.buildAnnotationProcessingParams(target, params.getProjectFilesystem()); javacOptions.setAnnotationProcessingData(annotationParams); return new DefaultJavaLibrary( params, args.srcs.get(), validateResources(args, params.getProjectFilesystem()), args.proguardConfig, args.postprocessClassesCommands.get(), args.exportedDeps.get(), args.providedDeps.get(), /* additionalClasspathEntries */ ImmutableSet.<Path>of(), javacOptions.build(), args.resourcesRoot); }
private FakeTestRule getFakeTestRule(String suffix, BuildRule... dependencies) { String name = String.format("//:%s", suffix); return new FakeTestRule( JavaTestDescription.TYPE, ImmutableSet.<Label>of(), BuildTargetFactory.newInstance(name), ImmutableSortedSet.copyOf(dependencies), ImmutableSet.<BuildTargetPattern>of()); }
private ImmutableSortedSet<BuildRule> getDexMergeDeps( UberRDotJava uberRDotJava, ImmutableSet<DexProducedFromJavaLibrary> preDexDeps) { ImmutableSet.Builder<BuildTarget> targets = ImmutableSet.builder(); targets.add(uberRDotJava.getBuildTarget()); for (DexProducedFromJavaLibrary preDex : preDexDeps) { targets.add(preDex.getBuildTarget()); } return getTargetsAsRules(targets.build()); }
@Override public RuleKey.Builder appendDetailsToRuleKey(RuleKey.Builder builder) { ImmutableSortedSet<? extends BuildRule> srcUnderTest = ImmutableSortedSet.copyOf( sourceUnderTest); super.appendDetailsToRuleKey(builder) .setReflectively("vmArgs", vmArgs) .setReflectively("sourceUnderTest", srcUnderTest); return builder; }
@VisibleForTesting CommandRunnerParams( Console console, Repository repository, AndroidDirectoryResolver androidDirectoryResolver, ArtifactCacheFactory artifactCacheFactory, BuckEventBus eventBus, String pythonInterpreter, Platform platform, ImmutableMap<String, String> environment, JavaPackageFinder javaPackageFinder, ObjectMapper objectMapper) { this( console, repository, androidDirectoryResolver, new CachingBuildEngine(), artifactCacheFactory, eventBus, new Parser(repository, pythonInterpreter, /* tempFilePatterns */ ImmutableSet.<Pattern>of(), new RuleKeyBuilderFactory() { @Override public Builder newInstance(BuildRule buildRule) { return RuleKey.builder(buildRule, new NullFileHashCache()); } }), platform, environment, javaPackageFinder, objectMapper); }
@VisibleForTesting public AndroidLibrary( BuildRuleParams params, Set<? extends SourcePath> srcs, Set<? extends SourcePath> resources, Optional<Path> proguardConfig, ImmutableList<String> postprocessClassesCommands, ImmutableSortedSet<BuildRule> exportedDeps, ImmutableSortedSet<BuildRule> providedDeps, ImmutableSet<Path> additionalClasspathEntries, JavacOptions javacOptions, Optional<Path> resourcesRoot, Optional<SourcePath> manifestFile, boolean isPrebuiltAar) { super( params, srcs, resources, proguardConfig, postprocessClassesCommands, exportedDeps, providedDeps, additionalClasspathEntries, javacOptions, resourcesRoot); this.manifestFile = Preconditions.checkNotNull(manifestFile); this.isPrebuiltAar = isPrebuiltAar; }
private SerializablePrebuiltJarRule(BuildRule rule) { Preconditions.checkState(rule instanceof PrebuiltJar); this.name = getIntellijNameForRule(rule, null /* basePathToAliasMap */); PrebuiltJar prebuiltJar = (PrebuiltJar) rule; this.binaryJar = prebuiltJar.getBinaryJar().resolve().toString(); if (prebuiltJar.getSourceJar().isPresent()) { this.sourceJar = prebuiltJar.getSourceJar().get().toString(); } else { this.sourceJar = null; } this.javadocUrl = prebuiltJar.getJavadocUrl().orNull(); }
public PythonTest( BuildRuleParams params, SourcePath binary, ImmutableSet<BuildRule> sourceUnderTest, ImmutableSet<Label> labels, ImmutableSet<String> contacts) { super(params); this.binary = Preconditions.checkNotNull(binary); this.sourceUnderTest = Preconditions.checkNotNull(sourceUnderTest); this.labels = Preconditions.checkNotNull(labels); this.contacts = Preconditions.checkNotNull(contacts); }