use of com.facebook.buck.rules.BuildContext in project buck by facebook.
the class AppleTestDescription method getXctool.
private Optional<SourcePath> getXctool(BuildRuleParams params, BuildRuleResolver resolver) {
// can use that directly.
if (appleConfig.getXctoolZipTarget().isPresent()) {
final BuildRule xctoolZipBuildRule = resolver.getRule(appleConfig.getXctoolZipTarget().get());
BuildTarget unzipXctoolTarget = BuildTarget.builder(xctoolZipBuildRule.getBuildTarget()).addFlavors(UNZIP_XCTOOL_FLAVOR).build();
final Path outputDirectory = BuildTargets.getGenPath(params.getProjectFilesystem(), unzipXctoolTarget, "%s/unzipped");
if (!resolver.getRuleOptional(unzipXctoolTarget).isPresent()) {
BuildRuleParams unzipXctoolParams = params.withBuildTarget(unzipXctoolTarget).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(xctoolZipBuildRule)), Suppliers.ofInstance(ImmutableSortedSet.of()));
resolver.addToIndex(new AbstractBuildRule(unzipXctoolParams) {
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
buildableContext.recordArtifact(outputDirectory);
return ImmutableList.of(new MakeCleanDirectoryStep(getProjectFilesystem(), outputDirectory), new UnzipStep(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(Preconditions.checkNotNull(xctoolZipBuildRule.getSourcePathToOutput())), outputDirectory));
}
@Override
public SourcePath getSourcePathToOutput() {
return new ExplicitBuildTargetSourcePath(getBuildTarget(), outputDirectory);
}
});
}
return Optional.of(new ExplicitBuildTargetSourcePath(unzipXctoolTarget, outputDirectory.resolve("bin/xctool")));
} else if (appleConfig.getXctoolPath().isPresent()) {
return Optional.of(new PathSourcePath(params.getProjectFilesystem(), appleConfig.getXctoolPath().get()));
} else {
return Optional.empty();
}
}
use of com.facebook.buck.rules.BuildContext in project buck by facebook.
the class JavaBuildGraphProcessor method run.
/**
* Creates the appropriate target graph and other resources needed for the {@link Processor} and
* runs it. This method will take responsibility for cleaning up the executor service after it
* runs.
*/
static void run(final CommandRunnerParams params, final AbstractCommand command, final Processor processor) throws ExitCodeException, InterruptedException, IOException {
final ConcurrencyLimit concurrencyLimit = command.getConcurrencyLimit(params.getBuckConfig());
try (CommandThreadManager pool = new CommandThreadManager(command.getClass().getName(), concurrencyLimit)) {
Cell cell = params.getCell();
WeightedListeningExecutorService executorService = pool.getExecutor();
// Ideally, we should be able to construct the TargetGraph quickly assuming most of it is
// already in memory courtesy of buckd. Though we could make a performance optimization where
// we pass an option to buck.py that tells it to ignore reading the BUCK.autodeps files when
// parsing the BUCK files because we never need to consider the existing auto-generated deps
// when creating the new auto-generated deps. If we did so, we would have to make sure to keep
// the nodes for that version of the graph separate from the ones that are actually used for
// building.
TargetGraph graph;
try {
graph = params.getParser().buildTargetGraphForTargetNodeSpecs(params.getBuckEventBus(), cell, command.getEnableParserProfiling(), executorService, ImmutableList.of(TargetNodePredicateSpec.of(x -> true, BuildFileSpec.fromRecursivePath(Paths.get(""), cell.getRoot()))), /* ignoreBuckAutodepsFiles */
true).getTargetGraph();
} catch (BuildTargetException | BuildFileParseException e) {
params.getBuckEventBus().post(ConsoleEvent.severe(MoreExceptions.getHumanReadableOrLocalizedMessage(e)));
throw new ExitCodeException(1);
}
BuildRuleResolver buildRuleResolver = new BuildRuleResolver(graph, new DefaultTargetNodeToBuildRuleTransformer());
CachingBuildEngineBuckConfig cachingBuildEngineBuckConfig = params.getBuckConfig().getView(CachingBuildEngineBuckConfig.class);
LocalCachingBuildEngineDelegate cachingBuildEngineDelegate = new LocalCachingBuildEngineDelegate(params.getFileHashCache());
BuildEngine buildEngine = new CachingBuildEngine(cachingBuildEngineDelegate, executorService, executorService, new DefaultStepRunner(), CachingBuildEngine.BuildMode.SHALLOW, cachingBuildEngineBuckConfig.getBuildDepFiles(), cachingBuildEngineBuckConfig.getBuildMaxDepFileCacheEntries(), cachingBuildEngineBuckConfig.getBuildArtifactCacheSizeLimit(), params.getObjectMapper(), buildRuleResolver, cachingBuildEngineBuckConfig.getResourceAwareSchedulingInfo(), new RuleKeyFactoryManager(params.getBuckConfig().getKeySeed(), fs -> cachingBuildEngineDelegate.getFileHashCache(), buildRuleResolver, cachingBuildEngineBuckConfig.getBuildInputRuleKeyFileSizeLimit(), new DefaultRuleKeyCache<>()));
// Create a BuildEngine because we store symbol information as build artifacts.
BuckEventBus eventBus = params.getBuckEventBus();
ExecutionContext executionContext = ExecutionContext.builder().setConsole(params.getConsole()).setConcurrencyLimit(concurrencyLimit).setBuckEventBus(eventBus).setEnvironment(/* environment */
ImmutableMap.of()).setExecutors(ImmutableMap.<ExecutorPool, ListeningExecutorService>of(ExecutorPool.CPU, executorService)).setJavaPackageFinder(params.getJavaPackageFinder()).setObjectMapper(params.getObjectMapper()).setPlatform(params.getPlatform()).setCellPathResolver(params.getCell().getCellPathResolver()).build();
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(buildRuleResolver));
BuildEngineBuildContext buildContext = BuildEngineBuildContext.builder().setBuildContext(BuildContext.builder().setActionGraph(new ActionGraph(ImmutableList.of())).setSourcePathResolver(pathResolver).setJavaPackageFinder(executionContext.getJavaPackageFinder()).setEventBus(eventBus).build()).setClock(params.getClock()).setArtifactCache(params.getArtifactCacheFactory().newInstance()).setBuildId(eventBus.getBuildId()).setObjectMapper(params.getObjectMapper()).setEnvironment(executionContext.getEnvironment()).setKeepGoing(false).build();
// Traverse the TargetGraph to find all of the auto-generated dependencies.
JavaDepsFinder javaDepsFinder = JavaDepsFinder.createJavaDepsFinder(params.getBuckConfig(), params.getCell().getCellPathResolver(), params.getObjectMapper(), buildContext, executionContext, buildEngine);
processor.process(graph, javaDepsFinder, executorService);
}
}
use of com.facebook.buck.rules.BuildContext in project buck by facebook.
the class AndroidManifestTest method testBuildInternal.
@Test
public void testBuildInternal() throws IOException {
AndroidManifest androidManifest = createSimpleAndroidManifestRule();
ProjectFilesystem filesystem = androidManifest.getProjectFilesystem();
Path skeletonPath = Paths.get("java/com/example/AndroidManifestSkeleton.xml");
// Mock out a BuildContext whose DependencyGraph will be traversed.
BuildContext buildContext = FakeBuildContext.NOOP_CONTEXT;
SourcePathResolver pathResolver = buildContext.getSourcePathResolver();
expect(pathResolver.getAbsolutePath(new PathSourcePath(filesystem, skeletonPath))).andStubReturn(filesystem.resolve(skeletonPath));
expect(pathResolver.getAllAbsolutePaths(ImmutableSortedSet.of())).andStubReturn(ImmutableSortedSet.of());
Path outPath = Paths.get("foo/bar");
expect(pathResolver.getRelativePath(androidManifest.getSourcePathToOutput())).andStubReturn(outPath);
replay(pathResolver);
List<Step> steps = androidManifest.getBuildSteps(buildContext, new FakeBuildableContext());
Step generateManifestStep = steps.get(2);
assertEquals(new GenerateManifestStep(filesystem, filesystem.resolve(skeletonPath), /* libraryManifestPaths */
ImmutableSet.of(), outPath), generateManifestStep);
}
use of com.facebook.buck.rules.BuildContext in project buck by facebook.
the class NdkLibraryTest method testSimpleNdkLibraryRule.
@Test
public void testSimpleNdkLibraryRule() throws Exception {
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
BuildContext context = FakeBuildContext.NOOP_CONTEXT;
String basePath = "java/src/com/facebook/base";
BuildTarget target = BuildTargetFactory.newInstance(String.format("//%s:base", basePath));
NdkLibrary ndkLibrary = new NdkLibraryBuilder(target).setFlags(ImmutableList.of("flag1", "flag2")).setIsAsset(true).build(ruleResolver, projectFilesystem);
assertEquals("ndk_library", ndkLibrary.getType());
assertTrue(ndkLibrary.getProperties().is(ANDROID));
assertTrue(ndkLibrary.isAsset());
assertEquals(projectFilesystem.getBuckPaths().getGenDir().resolve(basePath).resolve("__libbase"), ndkLibrary.getLibraryPath());
List<Step> steps = ndkLibrary.getBuildSteps(context, new FakeBuildableContext());
String libbase = projectFilesystem.getBuckPaths().getScratchDir().resolve(basePath).resolve("__libbase").toString();
MoreAsserts.assertShellCommands("ndk_library() should invoke ndk-build on the given path with some -j value", ImmutableList.of(String.format("%s -j %d -C %s flag1 flag2 " + "APP_PROJECT_PATH=%s " + "APP_BUILD_SCRIPT=%s " + "NDK_OUT=%s " + "NDK_LIBS_OUT=%s " + "BUCK_PROJECT_DIR=../../../../.. " + "host-echo-build-step=%s " + "--silent", ndkBuildCommand, Runtime.getRuntime().availableProcessors(), Paths.get(basePath).toString(), /* APP_PROJECT_PATH */
projectFilesystem.resolve(libbase) + File.separator, /* APP_BUILD_SCRIPT */
projectFilesystem.resolve(NdkLibraryDescription.getGeneratedMakefilePath(target, projectFilesystem)), /* NDK_OUT */
projectFilesystem.resolve(libbase) + File.separator, /* NDK_LIBS_OUT */
projectFilesystem.resolve(Paths.get(libbase, "libs")), /* host-echo-build-step */
Platform.detect() == Platform.WINDOWS ? "@REM" : "@#")), steps.subList(3, 4), executionContext);
}
use of com.facebook.buck.rules.BuildContext in project buck by facebook.
the class ArchiveTest method flagsArePropagated.
@Test
public void flagsArePropagated() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
Archive archive = Archive.from(target, params, ruleFinder, DEFAULT_ARCHIVER, ImmutableList.of("-foo"), DEFAULT_RANLIB, ImmutableList.of("-bar"), Archive.Contents.NORMAL, DEFAULT_OUTPUT, ImmutableList.of(new FakeSourcePath("simple.o")));
BuildContext buildContext = BuildContext.builder().from(FakeBuildContext.NOOP_CONTEXT).setSourcePathResolver(pathResolver).build();
ImmutableList<Step> steps = archive.getBuildSteps(buildContext, new FakeBuildableContext());
Step archiveStep = FluentIterable.from(steps).filter(ArchiveStep.class).first().get();
assertThat(archiveStep.getDescription(TestExecutionContext.newInstance()), containsString("-foo"));
Step ranlibStep = FluentIterable.from(steps).filter(RanlibStep.class).first().get();
assertThat(ranlibStep.getDescription(TestExecutionContext.newInstance()), containsString("-bar"));
}
Aggregations