use of com.facebook.buck.cli.BuckConfig in project buck by facebook.
the class DoctorCommandIntegrationTest method createDoctorConfig.
private static DoctorConfig createDoctorConfig(HttpdForTests httpd) {
String uri = "http://localhost:" + httpd.getRootUri().getPort();
BuckConfig buckConfig = FakeBuckConfig.builder().setSections(ImmutableMap.of(DoctorConfig.DOCTOR_SECTION, ImmutableMap.of(DoctorConfig.URL_FIELD, uri))).build();
return DoctorConfig.of(buckConfig);
}
use of com.facebook.buck.cli.BuckConfig in project buck by facebook.
the class ParserTest method whenEnvRemovedThenCachedRulesAreInvalidated.
@Test
public void whenEnvRemovedThenCachedRulesAreInvalidated() throws Exception {
Path buckFile = cellRoot.resolve("BUCK");
Files.write(buckFile, Joiner.on("").join(ImmutableList.of("import os\n", "os.getenv('FOO')\n", "genrule(name = 'cake', out = 'file.txt', cmd = 'touch $OUT')\n")).getBytes(UTF_8));
BuckConfig config = FakeBuckConfig.builder().setEnvironment(ImmutableMap.<String, String>builder().putAll(System.getenv()).put("FOO", "value").build()).setFilesystem(filesystem).build();
Cell cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
parser.getAllTargetNodes(eventBus, cell, false, executorService, buckFile);
// Call filterAllTargetsInProject to request cached rules.
config = FakeBuckConfig.builder().setFilesystem(filesystem).build();
cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
parser.getAllTargetNodes(eventBus, cell, false, executorService, buckFile);
// Test that the second parseBuildFile call repopulated the cache.
assertEquals("Should have invalidated.", 2, counter.calls);
}
use of com.facebook.buck.cli.BuckConfig in project buck by facebook.
the class ParserTest method setUp.
@Before
public void setUp() throws IOException, InterruptedException {
tempDir.newFolder("java", "com", "facebook");
defaultIncludeFile = tempDir.newFile("java/com/facebook/defaultIncludeFile").toRealPath();
Files.write(defaultIncludeFile, "\n".getBytes(UTF_8));
includedByIncludeFile = tempDir.newFile("java/com/facebook/includedByIncludeFile").toRealPath();
Files.write(includedByIncludeFile, "\n".getBytes(UTF_8));
includedByBuildFile = tempDir.newFile("java/com/facebook/includedByBuildFile").toRealPath();
Files.write(includedByBuildFile, "include_defs('//java/com/facebook/includedByIncludeFile')\n".getBytes(UTF_8));
testBuildFile = tempDir.newFile("java/com/facebook/BUCK").toRealPath();
Files.write(testBuildFile, ("include_defs('//java/com/facebook/includedByBuildFile')\n" + "java_library(name = 'foo')\n" + "java_library(name = 'bar')\n" + "genrule(name = 'baz', out = '')\n").getBytes(UTF_8));
tempDir.newFile("bar.py");
// Create a temp directory with some build files.
Path root = tempDir.getRoot().toRealPath();
filesystem = new ProjectFilesystem(root);
cellRoot = filesystem.getRootPath();
eventBus = BuckEventBusFactory.newInstance();
ImmutableMap.Builder<String, ImmutableMap<String, String>> configSectionsBuilder = ImmutableMap.builder();
configSectionsBuilder.put("buildfile", ImmutableMap.of("includes", "//java/com/facebook/defaultIncludeFile"));
if (parallelParsing) {
configSectionsBuilder.put("project", ImmutableMap.of("temp_files", ".*\\.swp$", "parallel_parsing", "true", "parsing_threads", Integer.toString(threads)));
} else {
configSectionsBuilder.put("project", ImmutableMap.of("temp_files", ".*\\.swp$"));
}
configSectionsBuilder.put("unknown_flavors_messages", ImmutableMap.of("macosx*", "This is an error message read by the .buckconfig"));
BuckConfig config = FakeBuckConfig.builder().setFilesystem(filesystem).setSections(configSectionsBuilder.build()).build();
cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
DefaultTypeCoercerFactory typeCoercerFactory = new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance());
BroadcastEventListener broadcastEventListener = new BroadcastEventListener();
broadcastEventListener.addEventBus(eventBus);
parser = new Parser(broadcastEventListener, cell.getBuckConfig().getView(ParserConfig.class), typeCoercerFactory, new ConstructorArgMarshaller(typeCoercerFactory));
counter = new ParseEventStartedCounter();
eventBus.register(counter);
executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(threads));
}
use of com.facebook.buck.cli.BuckConfig in project buck by facebook.
the class ParserTest method whenSymlinksForbiddenThenParseFailsOnSymlinkInSources.
@Test
public void whenSymlinksForbiddenThenParseFailsOnSymlinkInSources() throws Exception {
// This test depends on creating symbolic links which we cannot do on Windows.
assumeTrue(Platform.detect() != Platform.WINDOWS);
thrown.expect(HumanReadableException.class);
thrown.expectMessage("Target //foo:lib contains input files under a path which contains a symbolic link (" + "{foo/bar=bar}). To resolve this, use separate rules and declare dependencies instead of " + "using symbolic links.");
BuckConfig config = FakeBuckConfig.builder().setFilesystem(filesystem).setSections("[project]", "allow_symlinks = forbid").build();
cell = new TestCellBuilder().setBuckConfig(config).setFilesystem(filesystem).build();
tempDir.newFolder("bar");
tempDir.newFile("bar/Bar.java");
tempDir.newFolder("foo");
Path rootPath = tempDir.getRoot().toRealPath();
Files.createSymbolicLink(rootPath.resolve("foo/bar"), rootPath.resolve("bar"));
Path testBuckFile = rootPath.resolve("foo").resolve("BUCK");
Files.write(testBuckFile, "java_library(name = 'lib', srcs=glob(['bar/*.java']))\n".getBytes(UTF_8));
BuildTarget libTarget = BuildTarget.builder(cellRoot, "//foo", "lib").build();
Iterable<BuildTarget> buildTargets = ImmutableList.of(libTarget);
parser.buildTargetGraph(eventBus, cell, false, executorService, buildTargets);
}
use of com.facebook.buck.cli.BuckConfig in project buck by facebook.
the class ParserTest method whenAllRulesAreRequestedWithDifferingCellsThenRulesAreParsedOnce.
@Test
public void whenAllRulesAreRequestedWithDifferingCellsThenRulesAreParsedOnce() throws BuildFileParseException, BuildTargetException, IOException, InterruptedException {
filterAllTargetsInProject(parser, cell, x -> true, eventBus, executorService);
assertEquals("Should have parsed once.", 1, counter.calls);
Path newTempDir = Files.createTempDirectory("junit-temp-path").toRealPath();
Files.createFile(newTempDir.resolve("bar.py"));
ProjectFilesystem newFilesystem = new ProjectFilesystem(newTempDir);
BuckConfig config = FakeBuckConfig.builder().setFilesystem(newFilesystem).setSections(ImmutableMap.of(ParserConfig.BUILDFILE_SECTION_NAME, ImmutableMap.of(ParserConfig.INCLUDES_PROPERTY_NAME, "//bar.py"))).build();
Cell cell = new TestCellBuilder().setFilesystem(newFilesystem).setBuckConfig(config).build();
filterAllTargetsInProject(parser, cell, x -> true, eventBus, executorService);
assertEquals("Should not have invalidated cache.", 1, counter.calls);
}
Aggregations