Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
Remove Cell.getCell by path
Browse files Browse the repository at this point in the history
Summary: Cleaninig `Cell` interface

Reviewed By: milend

shipit-source-id: 310f39f5ddd85e0271f3c7a2993948043874b41b
  • Loading branch information
stepancheg authored and facebook-github-bot committed Mar 9, 2020
1 parent 5fb5dbf commit 6a74817
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 34 deletions.
16 changes: 8 additions & 8 deletions src/com/facebook/buck/cli/AuditConfigCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package com.facebook.buck.cli;

import com.facebook.buck.core.cell.Cell;
import com.facebook.buck.core.cell.Cells;
import com.facebook.buck.core.cell.name.CanonicalCellName;
import com.facebook.buck.core.config.BuckConfig;
import com.facebook.buck.core.util.immutables.BuckStyleValue;
import com.facebook.buck.support.cli.args.BuckCellArg;
Expand All @@ -29,7 +29,6 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSortedSet;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
Expand Down Expand Up @@ -106,7 +105,7 @@ private ImmutableSortedSet<ConfigValue> readConfig(CommandRunnerParams params) {
.forEach(
input -> {
BuckCellArg arg = BuckCellArg.of(input);
BuckConfig buckConfig = getCellBuckConfig(cells.getRootCell(), arg.getCellName());
BuckConfig buckConfig = getCellBuckConfig(cells, arg.getCellName());
String[] parts = arg.getArg().split("\\.", 2);

DirtyPrintStreamDecorator stdErr = params.getConsole().getStdErr();
Expand Down Expand Up @@ -162,12 +161,13 @@ public ExitCode runWithoutHelp(CommandRunnerParams params) throws Exception {
return ExitCode.SUCCESS;
}

private BuckConfig getCellBuckConfig(Cell cell, Optional<String> cellName) {
Optional<Path> cellPath = cell.getCellPathResolver().getCellPath(cellName);
if (!cellPath.isPresent()) {
return cell.getBuckConfig();
private BuckConfig getCellBuckConfig(Cells cells, Optional<String> cellName) {
Optional<CanonicalCellName> canonicalCellName =
cells.getRootCell().getCellNameResolver().getNameIfResolvable(cellName);
if (!canonicalCellName.isPresent()) {
return cells.getRootCell().getBuckConfig();
}
return cell.getCell(cellPath.get()).getBuckConfig();
return cells.getCell(canonicalCellName.get()).getBuckConfig();
}

private void printTabbedOutput(
Expand Down
5 changes: 0 additions & 5 deletions src/com/facebook/buck/core/cell/Cell.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSortedSet;
import java.nio.file.Path;

/**
* Represents a single checkout of a code base. Two cells model the same code base if their
Expand Down Expand Up @@ -61,10 +60,6 @@ public interface Cell {

AbsPath getRoot();

Cell getCellIgnoringVisibilityCheck(Path cellPath);

Cell getCell(Path cellPath);

Cell getCell(CanonicalCellName cellName);

/**
Expand Down
18 changes: 0 additions & 18 deletions src/com/facebook/buck/core/cell/impl/CellImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.facebook.buck.core.cell.nameresolver.CellNameResolver;
import com.facebook.buck.core.config.BuckConfig;
import com.facebook.buck.core.config.ConfigView;
import com.facebook.buck.core.exceptions.HumanReadableException;
import com.facebook.buck.core.filesystems.AbsPath;
import com.facebook.buck.core.filesystems.RelPath;
import com.facebook.buck.core.toolchain.ToolchainProvider;
Expand All @@ -34,12 +33,10 @@
import com.facebook.buck.io.filesystem.ProjectFilesystemView;
import com.facebook.buck.io.filesystem.RecursiveFileMatcher;
import com.facebook.buck.util.stream.RichStream;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;
import java.nio.file.Path;
import org.immutables.value.Value;

@BuckStyleValue
Expand Down Expand Up @@ -97,21 +94,6 @@ public AbsPath getRoot() {
return getFilesystem().getRootPath();
}

@Override
public Cell getCellIgnoringVisibilityCheck(Path cellPath) {
return getCellProvider().getCellByPath(cellPath);
}

@Override
public Cell getCell(Path cellPath) {
if (!getKnownRootsOfAllCells().contains(AbsPath.of(cellPath))) {
throw new HumanReadableException(
"Unable to find repository rooted at %s. Known roots are:\n %s",
cellPath, Joiner.on(",\n ").join(getKnownRootsOfAllCells()));
}
return getCellIgnoringVisibilityCheck(cellPath);
}

@Override
public Cell getCell(CanonicalCellName cellName) {
return getCellProvider().getCellByCanonicalCellName(cellName);
Expand Down
3 changes: 2 additions & 1 deletion test/com/facebook/buck/parser/DaemonicCellStateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.facebook.buck.core.cell.Cell;
import com.facebook.buck.core.cell.Cells;
import com.facebook.buck.core.cell.TestCellBuilder;
import com.facebook.buck.core.cell.name.CanonicalCellName;
import com.facebook.buck.core.config.BuckConfig;
import com.facebook.buck.core.config.FakeBuckConfig;
import com.facebook.buck.core.filesystems.AbsPath;
Expand Down Expand Up @@ -99,7 +100,7 @@ public void setUp() throws IOException {
.setSections(ImmutableMap.of("repositories", ImmutableMap.of("xplat", "../xplat")))
.build();
cells = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
childCell = cells.getRootCell().getCell(filesystem.resolve("../xplat").toAbsolutePath());
childCell = cells.getCell(CanonicalCellName.of(Optional.of("xplat")));
state = new DaemonicCellState(cells.getRootCell(), 1);
childState = new DaemonicCellState(childCell, 1);
}
Expand Down
3 changes: 2 additions & 1 deletion test/com/facebook/buck/parser/PerBuildStateCacheTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.facebook.buck.core.cell.Cell;
import com.facebook.buck.core.cell.Cells;
import com.facebook.buck.core.cell.TestCellBuilder;
import com.facebook.buck.core.cell.name.CanonicalCellName;
import com.facebook.buck.core.config.BuckConfig;
import com.facebook.buck.core.config.FakeBuckConfig;
import com.facebook.buck.core.filesystems.AbsPath;
Expand Down Expand Up @@ -61,7 +62,7 @@ public void setUp() throws IOException {
.setSections(ImmutableMap.of("repositories", ImmutableMap.of("xplat", "xplat")))
.build();
cells = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
childCell = cells.getRootCell().getCell(filesystem.resolve("xplat").toAbsolutePath());
childCell = cells.getCell(CanonicalCellName.of(Optional.of("xplat")));
}

Package createPackage(Cell cell, AbsPath packageFile) {
Expand Down
4 changes: 3 additions & 1 deletion test/com/facebook/buck/parser/spec/TargetNodeSpecTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.facebook.buck.core.cell.Cell;
import com.facebook.buck.core.cell.Cells;
import com.facebook.buck.core.cell.TestCellBuilder;
import com.facebook.buck.core.cell.name.CanonicalCellName;
import com.facebook.buck.core.config.BuckConfig;
import com.facebook.buck.core.config.FakeBuckConfig;
import com.facebook.buck.core.parser.buildtargetpattern.BuildTargetPattern;
Expand All @@ -30,6 +31,7 @@
import java.io.IOException;
import java.nio.file.Path;
import java.util.Map;
import java.util.Optional;
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
import org.hamcrest.Matchers;
Expand Down Expand Up @@ -124,7 +126,7 @@ public void gettingBuildTargetPatternFailsIfGivenCellDoesNotMatch(String pattern

Cells defaultCell =
getDefaultCell(rootFileSystem, ImmutableMap.of("cell-a", cellAPath, "cell-b", cellBPath));
Cell cellB = defaultCell.getRootCell().getCell(cellBPath);
Cell cellB = defaultCell.getCell(CanonicalCellName.of(Optional.of("cell-b")));

TargetNodeSpec spec = parseTargetNodeSpec(defaultCell.getRootCell(), pattern);
thrown.expectMessage(Matchers.containsString("cell-a"));
Expand Down

0 comments on commit 6a74817

Please sign in to comment.