use of com.facebook.buck.rules.DefaultCellPathResolver in project buck by facebook.
the class DistBuildState method createBuckConfig.
private static BuckConfig createBuckConfig(Config config, ProjectFilesystem projectFilesystem, BuildJobStateBuckConfig remoteBuckConfig) {
Architecture remoteArchitecture = Architecture.valueOf(remoteBuckConfig.getArchitecture());
Architecture localArchitecture = Architecture.detect();
Preconditions.checkState(remoteArchitecture.equals(localArchitecture), "Trying to load config with architecture %s on a machine that is %s. " + "This is not supported.", remoteArchitecture, localArchitecture);
Platform remotePlatform = Platform.valueOf(remoteBuckConfig.getPlatform());
Platform localPlatform = Platform.detect();
Preconditions.checkState(remotePlatform.equals(localPlatform), "Trying to load config with platform %s on a machine that is %s. This is not supported.", remotePlatform, localPlatform);
return new BuckConfig(config, projectFilesystem, remoteArchitecture, remotePlatform, ImmutableMap.copyOf(remoteBuckConfig.getUserEnvironment()), new DefaultCellPathResolver(projectFilesystem.getRootPath(), config));
}
use of com.facebook.buck.rules.DefaultCellPathResolver in project buck by facebook.
the class DistBuildStateTest method throwsOnPlatformMismatch.
@Test
public void throwsOnPlatformMismatch() throws IOException, InterruptedException {
ProjectFilesystem filesystem = createJavaOnlyFilesystem("/opt/buck");
Config config = new Config(ConfigBuilder.rawFromLines());
BuckConfig buckConfig = new BuckConfig(config, filesystem, Architecture.MIPSEL, Platform.UNKNOWN, ImmutableMap.<String, String>builder().putAll(System.getenv()).put("envKey", "envValue").build(), new DefaultCellPathResolver(filesystem.getRootPath(), config));
Cell cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(buckConfig).build();
BuildJobState dump = DistBuildState.dump(new DistBuildCellIndexer(cell), emptyActionGraph(), createDefaultCodec(cell, Optional.empty()), createTargetGraph(filesystem), ImmutableSet.of(BuildTargetFactory.newInstance(filesystem.getRootPath(), "//:dummy")));
expectedException.expect(IllegalStateException.class);
DistBuildState.load(Optional.empty(), dump, cell, knownBuildRuleTypesFactory);
}
use of com.facebook.buck.rules.DefaultCellPathResolver in project buck by facebook.
the class DistBuildStateTest method worksCrossCell.
@Test
public void worksCrossCell() throws IOException, InterruptedException {
ProjectFilesystem parentFs = createJavaOnlyFilesystem("/saving");
Path cell1Root = parentFs.resolve("cell1");
Path cell2Root = parentFs.resolve("cell2");
parentFs.mkdirs(cell1Root);
parentFs.mkdirs(cell2Root);
ProjectFilesystem cell1Filesystem = new ProjectFilesystem(cell1Root);
ProjectFilesystem cell2Filesystem = new ProjectFilesystem(cell2Root);
Config config = new Config(ConfigBuilder.rawFromLines("[cache]", "repository=somerepo", "[repositories]", "cell2 = " + cell2Root.toString()));
BuckConfig buckConfig = new BuckConfig(config, cell1Filesystem, Architecture.detect(), Platform.detect(), ImmutableMap.<String, String>builder().putAll(System.getenv()).put("envKey", "envValue").build(), new DefaultCellPathResolver(cell1Root, config));
Cell rootCellWhenSaving = new TestCellBuilder().setFilesystem(cell1Filesystem).setBuckConfig(buckConfig).build();
BuildJobState dump = DistBuildState.dump(new DistBuildCellIndexer(rootCellWhenSaving), emptyActionGraph(), createDefaultCodec(rootCellWhenSaving, Optional.empty()), createCrossCellTargetGraph(cell1Filesystem, cell2Filesystem), ImmutableSet.of(BuildTargetFactory.newInstance(cell1Filesystem.getRootPath(), "//:dummy")));
Cell rootCellWhenLoading = new TestCellBuilder().setFilesystem(createJavaOnlyFilesystem("/loading")).build();
Config localConfig = new Config(ConfigBuilder.rawFromLines("[cache]", "slb_server_pool=http://someserver:8080"));
BuckConfig localBuckConfig = new BuckConfig(localConfig, cell1Filesystem, Architecture.detect(), Platform.detect(), ImmutableMap.<String, String>builder().putAll(System.getenv()).put("envKey", "envValue").build(), new DefaultCellPathResolver(cell1Root, localConfig));
DistBuildState distributedBuildState = DistBuildState.load(Optional.of(localBuckConfig), dump, rootCellWhenLoading, knownBuildRuleTypesFactory);
ImmutableMap<Integer, Cell> cells = distributedBuildState.getCells();
assertThat(cells, Matchers.aMapWithSize(2));
BuckConfig rootCellBuckConfig = cells.get(0).getBuckConfig();
Optional<ImmutableMap<String, String>> cacheSection = rootCellBuckConfig.getSection("cache");
assertTrue(cacheSection.isPresent());
assertTrue(cacheSection.get().containsKey("repository"));
assertThat(cacheSection.get().get("repository"), Matchers.equalTo("somerepo"));
assertThat(cacheSection.get().get("slb_server_pool"), Matchers.equalTo("http://someserver:8080"));
}
use of com.facebook.buck.rules.DefaultCellPathResolver in project buck by facebook.
the class MissingSymbolsHandlerIntegrationTest method shouldFindNeededDependenciesFromSymbols.
@Test
public void shouldFindNeededDependenciesFromSymbols() throws IOException, InterruptedException {
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "symbol_finder", temporaryFolder);
workspace.setUp();
ProjectFilesystem projectFilesystem = new ProjectFilesystem(temporaryFolder.getRoot());
ImmutableMap<String, String> environment = ImmutableMap.copyOf(System.getenv());
Config rawConfig = Configs.createDefaultConfig(projectFilesystem.getRootPath());
BuckConfig config = new BuckConfig(rawConfig, projectFilesystem, Architecture.detect(), Platform.detect(), environment, new DefaultCellPathResolver(projectFilesystem.getRootPath(), rawConfig));
ImmutableSet<Description<?>> allDescriptions = KnownBuildRuleTypesTestUtil.getDefaultKnownBuildRuleTypes(projectFilesystem, environment).getAllDescriptions();
BuckEventBus buckEventBus = BuckEventBusFactory.newInstance();
MissingSymbolsHandler missingSymbolsHandler = MissingSymbolsHandler.create(projectFilesystem, allDescriptions, config, buckEventBus, new TestConsole(), DEFAULT_JAVAC_OPTIONS, environment);
MissingSymbolEvent missingSymbolEvent = MissingSymbolEvent.create(BuildTargetFactory.newInstance(workspace.getDestPath(), "//java/com/example/b:b"), "com.example.a.A", MissingSymbolEvent.SymbolType.Java);
ImmutableSetMultimap<BuildTarget, BuildTarget> neededDeps = missingSymbolsHandler.getNeededDependencies(ImmutableList.of(missingSymbolEvent));
assertEquals("MissingSymbolsHandler failed to find the needed dependency.", neededDeps, ImmutableSetMultimap.of(BuildTargetFactory.newInstance(workspace.getDestPath(), "//java/com/example/b:b"), BuildTargetFactory.newInstance(workspace.getDestPath(), "//java/com/example/a:a")));
}
use of com.facebook.buck.rules.DefaultCellPathResolver in project buck by facebook.
the class JavaSymbolFinderIntegrationTest method shouldFindTargetDefiningSymbol.
@Test
public void shouldFindTargetDefiningSymbol() throws IOException, InterruptedException {
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "symbol_finder", temporaryFolder);
workspace.setUp();
ProjectFilesystem projectFilesystem = new ProjectFilesystem(temporaryFolder.getRoot());
ImmutableMap<String, String> environment = ImmutableMap.copyOf(System.getenv());
Config rawConfig = Configs.createDefaultConfig(projectFilesystem.getRootPath());
BuckConfig config = new BuckConfig(rawConfig, projectFilesystem, Architecture.detect(), Platform.detect(), environment, new DefaultCellPathResolver(projectFilesystem.getRootPath(), rawConfig));
ParserConfig parserConfig = config.getView(ParserConfig.class);
PythonBuckConfig pythonBuckConfig = new PythonBuckConfig(config, new ExecutableFinder());
ImmutableSet<Description<?>> allDescriptions = KnownBuildRuleTypesTestUtil.getDefaultKnownBuildRuleTypes(projectFilesystem, environment).getAllDescriptions();
SrcRootsFinder srcRootsFinder = new SrcRootsFinder(projectFilesystem);
ProjectBuildFileParserFactory projectBuildFileParserFactory = new DefaultProjectBuildFileParserFactory(ProjectBuildFileParserOptions.builder().setProjectRoot(projectFilesystem.getRootPath()).setPythonInterpreter(pythonBuckConfig.getPythonInterpreter()).setAllowEmptyGlobs(parserConfig.getAllowEmptyGlobs()).setIgnorePaths(projectFilesystem.getIgnorePaths()).setBuildFileName(parserConfig.getBuildFileName()).setDefaultIncludes(parserConfig.getDefaultIncludes()).setDescriptions(allDescriptions).setBuildFileImportWhitelist(parserConfig.getBuildFileImportWhitelist()).build());
BuckEventBus buckEventBus = BuckEventBusFactory.newInstance();
JavaSymbolFinder finder = new JavaSymbolFinder(projectFilesystem, srcRootsFinder, DEFAULT_JAVAC_OPTIONS, new ConstructorArgMarshaller(new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance())), projectBuildFileParserFactory, config, buckEventBus, new TestConsole(), environment);
SetMultimap<String, BuildTarget> foundTargets = finder.findTargetsForSymbols(ImmutableSet.of("com.example.a.A"));
assertEquals("JavaSymbolFinder failed to find the right target.", ImmutableSetMultimap.of("com.example.a.A", BuildTargetFactory.newInstance(projectFilesystem, "//java/com/example/a:a")), foundTargets);
}
Aggregations