@Test public void shouldBeAbleToConstructACxxLibraryFromThrift() throws Exception { ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "cxx", tmp); workspace.setUp(); BuckEventBus eventBus = BuckEventBusFactory.newInstance(); ProjectFilesystem filesystem = new ProjectFilesystem(workspace.getDestPath()); Path compiler = new ExecutableFinder() .getExecutable(Paths.get("echo"), ImmutableMap.copyOf(System.getenv())); BuckConfig config = FakeBuckConfig.builder() .setFilesystem(filesystem) .setSections( "[thrift]", "compiler = " + compiler, "compiler2 = " + compiler, "cpp_library = //thrift:fake", "cpp_reflection_library = //thrift:fake") .build(); TypeCoercerFactory typeCoercerFactory = new DefaultTypeCoercerFactory(); Parser parser = new Parser( new ParserConfig(config), typeCoercerFactory, new ConstructorArgMarshaller(typeCoercerFactory)); Cell cell = Cell.createCell( filesystem, new TestConsole(), Watchman.NULL_WATCHMAN, config, new KnownBuildRuleTypesFactory( new ProcessExecutor(new TestConsole()), new FakeAndroidDirectoryResolver(), Optional.<Path>absent()), new FakeAndroidDirectoryResolver(), new DefaultClock()); BuildTarget target = BuildTargetFactory.newInstance(filesystem, "//thrift:exe"); TargetGraph targetGraph = parser.buildTargetGraph( eventBus, cell, false, Executors.newSingleThreadExecutor(), ImmutableSet.of(target)); TargetNodeToBuildRuleTransformer transformer = new BuildTargetNodeToBuildRuleTransformer(); // There was a case where the cxx library being generated wouldn't put the header into the tree // with the right flavour. This catches this case without us needing to stick a working thrift // compiler into buck's own source. Pair<ActionGraph, BuildRuleResolver> actionGraphAndResolver = new TargetGraphToActionGraph(eventBus, transformer).apply(targetGraph); // This is to cover the case where we weren't passing flavors around correctly, which ended // making the binary depend 'placeholder' BuildRules instead of real ones. This is the // regression test for that case. BuildRuleResolver ruleResolver = actionGraphAndResolver.getSecond(); BuildTarget binaryFlavor = target.withFlavors(ImmutableFlavor.of("binary")); ImmutableSortedSet<BuildRule> deps = ruleResolver.getRule(binaryFlavor).getDeps(); assertThat( FluentIterable.from(deps) .anyMatch( new Predicate<BuildRule>() { @Override public boolean apply(BuildRule input) { return input instanceof NoopBuildRule; } }), Matchers.is(false)); }