Search in sources :

Example 6 with ImmutableBiMap

use of com.google.common.collect.ImmutableBiMap in project buck by facebook.

the class DistBuildState method load.

public static DistBuildState load(// e.g. the slave's .buckconfig
Optional<BuckConfig> localBuckConfig, BuildJobState jobState, Cell rootCell, KnownBuildRuleTypesFactory knownBuildRuleTypesFactory) throws IOException {
    ProjectFilesystem rootCellFilesystem = rootCell.getFilesystem();
    ImmutableMap.Builder<Path, BuckConfig> cellConfigs = ImmutableMap.builder();
    ImmutableMap.Builder<Path, ProjectFilesystem> cellFilesystems = ImmutableMap.builder();
    ImmutableMap.Builder<Integer, Path> cellIndex = ImmutableMap.builder();
    Path sandboxPath = rootCellFilesystem.getRootPath().resolve(rootCellFilesystem.getBuckPaths().getRemoteSandboxDir());
    rootCellFilesystem.mkdirs(sandboxPath);
    Path uniqueBuildRoot = Files.createTempDirectory(sandboxPath, "build");
    for (Map.Entry<Integer, BuildJobStateCell> remoteCellEntry : jobState.getCells().entrySet()) {
        BuildJobStateCell remoteCell = remoteCellEntry.getValue();
        Path cellRoot = uniqueBuildRoot.resolve(remoteCell.getNameHint());
        Files.createDirectories(cellRoot);
        Config config = createConfig(remoteCell.getConfig(), localBuckConfig);
        ProjectFilesystem projectFilesystem = new ProjectFilesystem(cellRoot, config);
        BuckConfig buckConfig = createBuckConfig(config, projectFilesystem, remoteCell.getConfig());
        cellConfigs.put(cellRoot, buckConfig);
        cellFilesystems.put(cellRoot, projectFilesystem);
        cellIndex.put(remoteCellEntry.getKey(), cellRoot);
    }
    CellProvider cellProvider = CellProvider.createForDistributedBuild(cellConfigs.build(), cellFilesystems.build(), knownBuildRuleTypesFactory);
    ImmutableBiMap<Integer, Cell> cells = ImmutableBiMap.copyOf(Maps.transformValues(cellIndex.build(), cellProvider::getCellByPath));
    return new DistBuildState(jobState, cells);
}
Also used : Path(java.nio.file.Path) CellProvider(com.facebook.buck.rules.CellProvider) Config(com.facebook.buck.config.Config) BuckConfig(com.facebook.buck.cli.BuckConfig) RawConfig(com.facebook.buck.config.RawConfig) BuildJobStateBuckConfig(com.facebook.buck.distributed.thrift.BuildJobStateBuckConfig) ImmutableMap(com.google.common.collect.ImmutableMap) BuildJobStateCell(com.facebook.buck.distributed.thrift.BuildJobStateCell) BuckConfig(com.facebook.buck.cli.BuckConfig) BuildJobStateBuckConfig(com.facebook.buck.distributed.thrift.BuildJobStateBuckConfig) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) ImmutableBiMap(com.google.common.collect.ImmutableBiMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Cell(com.facebook.buck.rules.Cell) BuildJobStateCell(com.facebook.buck.distributed.thrift.BuildJobStateCell)

Example 7 with ImmutableBiMap

use of com.google.common.collect.ImmutableBiMap in project buck by facebook.

the class ResourcesFilter method createFilterResourcesStep.

/**
   * Sets up filtering of resources, images/drawables and strings in particular, based on build
   * rule parameters {@link #resourceFilter} and {@link #resourceCompressionMode}.
   *
   * {@link com.facebook.buck.android.FilterResourcesStep.ResourceFilter} {@code resourceFilter}
   * determines which drawables end up in the APK (based on density - mdpi, hdpi etc), and also
   * whether higher density drawables get scaled down to the specified density (if not present).
   *
   * {@link #resourceCompressionMode} determines whether non-english string resources are packaged
   * separately as assets (and not bundled together into the {@code resources.arsc} file).
   *
   * @param whitelistedStringDirs overrides storing non-english strings as assets for resources
   *     inside these directories.
   */
@VisibleForTesting
FilterResourcesStep createFilterResourcesStep(ImmutableList<Path> resourceDirectories, ImmutableSet<Path> whitelistedStringDirs, ImmutableSet<String> locales, ImmutableList.Builder<Path> filteredResDirectories) {
    ImmutableBiMap.Builder<Path, Path> filteredResourcesDirMapBuilder = ImmutableBiMap.builder();
    String resDestinationBasePath = getResDestinationBasePath();
    int count = 0;
    for (Path resDir : resourceDirectories) {
        Path filteredResourceDir = Paths.get(resDestinationBasePath, String.valueOf(count++));
        filteredResourcesDirMapBuilder.put(resDir, filteredResourceDir);
        filteredResDirectories.add(filteredResourceDir);
    }
    ImmutableBiMap<Path, Path> resSourceToDestDirMap = filteredResourcesDirMapBuilder.build();
    FilterResourcesStep.Builder filterResourcesStepBuilder = FilterResourcesStep.builder().setProjectFilesystem(getProjectFilesystem()).setInResToOutResDirMap(resSourceToDestDirMap).setResourceFilter(resourceFilter);
    if (resourceCompressionMode.isStoreStringsAsAssets()) {
        filterResourcesStepBuilder.enableStringWhitelisting();
        filterResourcesStepBuilder.setWhitelistedStringDirs(whitelistedStringDirs);
    }
    filterResourcesStepBuilder.setLocales(locales);
    return filterResourcesStepBuilder.build();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ImmutableBiMap(com.google.common.collect.ImmutableBiMap) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 8 with ImmutableBiMap

use of com.google.common.collect.ImmutableBiMap in project binnavi by google.

the class CPostgreSQLModuleContentTest method testCModuleContentConstructor.

@Test
public void testCModuleContentConstructor() throws LoadCancelledException, CouldntLoadDataException {
    final CModule module = (CModule) getDatabase().getContent().getModules().get(0);
    module.load();
    final ListenerProvider<IModuleListener> listeners = new ListenerProvider<IModuleListener>();
    final CCallgraph callgraph = module.getContent().getNativeCallgraph();
    final IFilledList<INaviFunction> functions = new FilledList<INaviFunction>();
    functions.add(module.getContent().getFunctionContainer().getFunctions().get(0));
    final ICallgraphView nativeCallgraph = module.getContent().getViewContainer().getNativeCallgraphView();
    final ImmutableList<IFlowgraphView> nativeFlowgraphs = module.getContent().getViewContainer().getNativeFlowgraphViews();
    final List<INaviView> customViews = new ArrayList<INaviView>();
    final ImmutableBiMap<INaviView, INaviFunction> viewFunctionMap = new ImmutableBiMap.Builder<INaviView, INaviFunction>().build();
    new Pair<HashMap<INaviView, INaviFunction>, HashMap<INaviFunction, INaviView>>(null, null);
    final IFilledList<TraceList> traces = new FilledList<TraceList>();
    final SectionContainer sections = new SectionContainer(new SectionContainerBackend(getProvider(), module));
    final TypeInstanceContainer instances = new TypeInstanceContainer(new TypeInstanceContainerBackend(getProvider(), module, module.getTypeManager(), sections), getProvider());
    final CModuleContent moduleContent1 = new CModuleContent(module, getProvider(), listeners, callgraph, functions, nativeCallgraph, nativeFlowgraphs, customViews, viewFunctionMap, traces, sections, instances);
    assertNotNull(moduleContent1);
    try {
        @SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(null, null, null, null, null, null, null, null, null, null, sections, instances);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        @SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(module, null, null, null, null, null, null, null, null, null, null, null);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        @SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(module, getProvider(), null, null, null, null, null, null, null, null, null, null);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        @SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(module, getProvider(), listeners, null, null, null, null, null, null, null, null, null);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        @SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(module, getProvider(), listeners, callgraph, null, null, null, null, null, null, null, null);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        @SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(module, getProvider(), listeners, callgraph, functions, null, null, null, null, null, null, null);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        @SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(module, getProvider(), listeners, callgraph, functions, nativeCallgraph, null, null, null, null, null, null);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        @SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(module, getProvider(), listeners, callgraph, functions, nativeCallgraph, nativeFlowgraphs, null, null, null, null, null);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        @SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(module, getProvider(), listeners, callgraph, functions, nativeCallgraph, nativeFlowgraphs, customViews, null, null, null, null);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        @SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(module, getProvider(), listeners, callgraph, functions, nativeCallgraph, nativeFlowgraphs, customViews, viewFunctionMap, null, null, null);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        @SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(module, getProvider(), listeners, callgraph, functions, nativeCallgraph, nativeFlowgraphs, customViews, viewFunctionMap, traces, null, null);
        fail();
    } catch (final NullPointerException e) {
    }
}
Also used : IFlowgraphView(com.google.security.zynamics.binnavi.disassembly.IFlowgraphView) FilledList(com.google.security.zynamics.zylib.types.lists.FilledList) IFilledList(com.google.security.zynamics.zylib.types.lists.IFilledList) ArrayList(java.util.ArrayList) TypeInstanceContainerBackend(com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceContainerBackend) Pair(com.google.security.zynamics.zylib.general.Pair) SectionContainerBackend(com.google.security.zynamics.binnavi.disassembly.types.SectionContainerBackend) CCallgraph(com.google.security.zynamics.binnavi.disassembly.CCallgraph) ICallgraphView(com.google.security.zynamics.binnavi.disassembly.ICallgraphView) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) ImmutableBiMap(com.google.common.collect.ImmutableBiMap) SectionContainer(com.google.security.zynamics.binnavi.disassembly.types.SectionContainer) TraceList(com.google.security.zynamics.binnavi.debug.models.trace.TraceList) ListenerProvider(com.google.security.zynamics.zylib.general.ListenerProvider) TypeInstanceContainer(com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceContainer) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 9 with ImmutableBiMap

use of com.google.common.collect.ImmutableBiMap in project error-prone by google.

the class ScannerSupplier method fromBugCheckerInfos.

/**
   * Returns a {@link ScannerSupplier} built from a list of {@link BugCheckerInfo}s.
   */
public static ScannerSupplier fromBugCheckerInfos(Iterable<BugCheckerInfo> checkers) {
    ImmutableBiMap.Builder<String, BugCheckerInfo> builder = ImmutableBiMap.builder();
    for (BugCheckerInfo checker : checkers) {
        builder.put(checker.canonicalName(), checker);
    }
    ImmutableBiMap<String, BugCheckerInfo> allChecks = builder.build();
    return new ScannerSupplierImpl(allChecks, defaultSeverities(allChecks.values()), ImmutableSet.<String>of());
}
Also used : ImmutableBiMap(com.google.common.collect.ImmutableBiMap) BugCheckerInfo(com.google.errorprone.BugCheckerInfo)

Aggregations

ImmutableBiMap (com.google.common.collect.ImmutableBiMap)9 Path (java.nio.file.Path)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 SourcePath (com.facebook.buck.rules.SourcePath)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 BugCheckerInfo (com.google.errorprone.BugCheckerInfo)2 BuckConfig (com.facebook.buck.cli.BuckConfig)1 Config (com.facebook.buck.config.Config)1 RawConfig (com.facebook.buck.config.RawConfig)1 CompilerProvider (com.facebook.buck.cxx.CompilerProvider)1 CxxPlatform (com.facebook.buck.cxx.CxxPlatform)1 CxxToolProvider (com.facebook.buck.cxx.CxxToolProvider)1 DefaultLinkerProvider (com.facebook.buck.cxx.DefaultLinkerProvider)1 GnuArchiver (com.facebook.buck.cxx.GnuArchiver)1 HeaderVerification (com.facebook.buck.cxx.HeaderVerification)1 MungingDebugPathSanitizer (com.facebook.buck.cxx.MungingDebugPathSanitizer)1 PosixNmSymbolNameTool (com.facebook.buck.cxx.PosixNmSymbolNameTool)1 PrefixMapDebugPathSanitizer (com.facebook.buck.cxx.PrefixMapDebugPathSanitizer)1 PreprocessorProvider (com.facebook.buck.cxx.PreprocessorProvider)1 BuildJobStateBuckConfig (com.facebook.buck.distributed.thrift.BuildJobStateBuckConfig)1