use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class AssembleDirectoriesTest method testAssembleFoldersWithRelativePath.
@Test
public void testAssembleFoldersWithRelativePath() throws IOException, InterruptedException {
Path tmp = filesystem.getRootPath();
Files.createDirectories(tmp.resolve("folder_a"));
Files.write(tmp.resolve("folder_a/a.txt"), "".getBytes(UTF_8));
Files.write(tmp.resolve("folder_a/b.txt"), "".getBytes(UTF_8));
Files.createDirectories(tmp.resolve("folder_b"));
Files.write(tmp.resolve("folder_b/c.txt"), "".getBytes(UTF_8));
Files.write(tmp.resolve("folder_b/d.txt"), "".getBytes(UTF_8));
BuildTarget target = BuildTargetFactory.newInstance(filesystem.getRootPath(), "//:output_folder");
BuildRuleParams buildRuleParams = new FakeBuildRuleParamsBuilder(target).setProjectFilesystem(filesystem).build();
ImmutableList<SourcePath> directories = ImmutableList.of(new FakeSourcePath(filesystem, "folder_a"), new FakeSourcePath(filesystem, "folder_b"));
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(ruleResolver));
AssembleDirectories assembleDirectories = new AssembleDirectories(buildRuleParams, directories);
ruleResolver.addToIndex(assembleDirectories);
ImmutableList<Step> steps = assembleDirectories.getBuildSteps(FakeBuildContext.withSourcePathResolver(pathResolver), new FakeBuildableContext());
for (Step step : steps) {
assertEquals(0, step.execute(context).getExitCode());
}
Path outputFile = pathResolver.getAbsolutePath(assembleDirectories.getSourcePathToOutput());
try (DirectoryStream<Path> dir = Files.newDirectoryStream(outputFile)) {
assertEquals(4, Iterables.size(dir));
}
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class NdkCxxPlatformTest method constructLinkRuleKeys.
// Create and return some rule keys from a dummy source for the given platforms.
private ImmutableMap<NdkCxxPlatforms.TargetCpuType, RuleKey> constructLinkRuleKeys(ImmutableMap<NdkCxxPlatforms.TargetCpuType, NdkCxxPlatform> cxxPlatforms) throws NoSuchBuildTargetException {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, FakeFileHashCache.createFromStrings(ImmutableMap.<String, String>builder().put("input.o", Strings.repeat("a", 40)).build()), pathResolver, ruleFinder);
BuildTarget target = BuildTargetFactory.newInstance("//:target");
ImmutableMap.Builder<NdkCxxPlatforms.TargetCpuType, RuleKey> ruleKeys = ImmutableMap.builder();
for (Map.Entry<NdkCxxPlatforms.TargetCpuType, NdkCxxPlatform> entry : cxxPlatforms.entrySet()) {
BuildRule rule = CxxLinkableEnhancer.createCxxLinkableBuildRule(CxxPlatformUtils.DEFAULT_CONFIG, entry.getValue().getCxxPlatform(), new FakeBuildRuleParamsBuilder(target).build(), resolver, pathResolver, ruleFinder, target, Linker.LinkType.EXECUTABLE, Optional.empty(), Paths.get("output"), Linker.LinkableDepType.SHARED, ImmutableList.of(), Optional.empty(), Optional.empty(), ImmutableSet.of(), NativeLinkableInput.builder().setArgs(SourcePathArg.from(new FakeSourcePath("input.o"))).build());
ruleKeys.put(entry.getKey(), ruleKeyFactory.build(rule));
}
return ruleKeys.build();
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class NdkCxxPlatformTest method constructCompileRuleKeys.
// Create and return some rule keys from a dummy source for the given platforms.
private ImmutableMap<NdkCxxPlatforms.TargetCpuType, RuleKey> constructCompileRuleKeys(Operation operation, ImmutableMap<NdkCxxPlatforms.TargetCpuType, NdkCxxPlatform> cxxPlatforms) {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
String source = "source.cpp";
DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, FakeFileHashCache.createFromStrings(ImmutableMap.<String, String>builder().put("source.cpp", Strings.repeat("a", 40)).build()), pathResolver, ruleFinder);
BuildTarget target = BuildTargetFactory.newInstance("//:target");
ImmutableMap.Builder<NdkCxxPlatforms.TargetCpuType, RuleKey> ruleKeys = ImmutableMap.builder();
for (Map.Entry<NdkCxxPlatforms.TargetCpuType, NdkCxxPlatform> entry : cxxPlatforms.entrySet()) {
CxxSourceRuleFactory cxxSourceRuleFactory = CxxSourceRuleFactory.builder().setParams(new FakeBuildRuleParamsBuilder(target).build()).setResolver(resolver).setPathResolver(pathResolver).setRuleFinder(ruleFinder).setCxxBuckConfig(CxxPlatformUtils.DEFAULT_CONFIG).setCxxPlatform(entry.getValue().getCxxPlatform()).setPicType(CxxSourceRuleFactory.PicType.PIC).build();
CxxPreprocessAndCompile rule;
switch(operation) {
case PREPROCESS_AND_COMPILE:
rule = cxxSourceRuleFactory.createPreprocessAndCompileBuildRule(source, CxxSource.of(CxxSource.Type.CXX, new FakeSourcePath(source), ImmutableList.of()));
break;
case COMPILE:
rule = cxxSourceRuleFactory.createCompileBuildRule(source, CxxSource.of(CxxSource.Type.CXX_CPP_OUTPUT, new FakeSourcePath(source), ImmutableList.of()));
break;
default:
throw new IllegalStateException();
}
ruleKeys.put(entry.getKey(), ruleKeyFactory.build(rule));
}
return ruleKeys.build();
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class CopyNativeLibrariesTest method testCopyNativeLibrariesCopiesLibDirsInReverseTopoOrder.
@Test
public void testCopyNativeLibrariesCopiesLibDirsInReverseTopoOrder() {
BuildTarget target = BuildTargetFactory.newInstance("//:test");
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
CopyNativeLibraries copyNativeLibraries = new CopyNativeLibraries(new FakeBuildRuleParamsBuilder(target).build(), ImmutableSet.of(new FakeSourcePath("lib1"), new FakeSourcePath("lib2")), ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of(), "dex");
ImmutableList<Step> steps = copyNativeLibraries.getBuildSteps(FakeBuildContext.withSourcePathResolver(pathResolver), new FakeBuildableContext());
Iterable<String> descriptions = Iterables.transform(steps, step -> step.getDescription(TestExecutionContext.newInstance()));
assertThat("lib1 contents should be copied *after* lib2", Iterables.indexOf(descriptions, Predicates.containsPattern("lib1")), Matchers.greaterThan(Iterables.indexOf(descriptions, Predicates.containsPattern("lib2"))));
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class CxxPrecompiledHeaderTest method generatesPchStepShouldUseCorrectLang.
@Test
public void generatesPchStepShouldUseCorrectLang() throws Exception {
BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
Preprocessor preprocessorSupportingPch = new GccPreprocessor(CxxPlatformUtils.DEFAULT_PLATFORM.getCpp().resolve(resolver)) {
@Override
public boolean supportsPrecompiledHeaders() {
return true;
}
};
Compiler compiler = CxxPlatformUtils.DEFAULT_PLATFORM.getCxx().resolve(resolver);
SourcePathResolver sourcePathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
CxxPrecompiledHeader precompiledHeader = new CxxPrecompiledHeader(params, Paths.get("foo.hash1.hash2.gch"), new PreprocessorDelegate(sourcePathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_PLATFORM.getHeaderVerification(), Paths.get("./"), preprocessorSupportingPch, PreprocessorFlags.builder().build(), CxxDescriptionEnhancer.frameworkPathToSearchPath(CxxPlatformUtils.DEFAULT_PLATFORM, sourcePathResolver), Optional.empty(), /* leadingIncludePaths */
Optional.empty()), new CompilerDelegate(sourcePathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, compiler, CxxToolFlags.of()), CxxToolFlags.of(), new FakeSourcePath("foo.h"), CxxSource.Type.C, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_ASSEMBLER_DEBUG_PATH_SANITIZER);
resolver.addToIndex(precompiledHeader);
BuildContext buildContext = FakeBuildContext.withSourcePathResolver(sourcePathResolver);
ImmutableList<Step> postBuildSteps = precompiledHeader.getBuildSteps(buildContext, new FakeBuildableContext());
CxxPreprocessAndCompileStep step = Iterables.getOnlyElement(Iterables.filter(postBuildSteps, CxxPreprocessAndCompileStep.class));
assertThat("step that generates pch should have correct flags", step.getCommand(), hasItem(CxxSource.Type.C.getPrecompiledHeaderLanguage().get()));
}
Aggregations