Skip to content

Commit

Permalink
Simplify PackageFactoryApparatus.
Browse files Browse the repository at this point in the history
--
MOS_MIGRATED_REVID=104086390
  • Loading branch information
hanwen committed Sep 28, 2015
1 parent a51b3f7 commit 75eca13
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public TestMapper(Package pkg, RuleClass ruleClass, Label ruleLabel,
protected Rule createRule(String pkgPath, String ruleName, String... ruleDef) throws Exception {
Scratch scratch = new Scratch();
EventCollectionApparatus events = new EventCollectionApparatus();
PackageFactoryApparatus packages = new PackageFactoryApparatus(events, scratch);
PackageFactoryApparatus packages = new PackageFactoryApparatus(events.reporter());

Path buildFile = scratch.file(pkgPath + "/BUILD", ruleDef);
pkg = packages.createPackage(pkgPath, buildFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class ExportsFilesTest {

private Scratch scratch = new Scratch("/workspace");
private EventCollectionApparatus events = new EventCollectionApparatus();
private PackageFactoryApparatus packages = new PackageFactoryApparatus(events, scratch);
private PackageFactoryApparatus packages = new PackageFactoryApparatus(events.reporter());

private Package pkg() throws Exception {
Path buildFile = scratch.file("pkg/BUILD",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.Reporter;
import com.google.devtools.build.lib.events.util.EventCollectionApparatus;
import com.google.devtools.build.lib.packages.CachingPackageLocator;
import com.google.devtools.build.lib.packages.ConstantRuleVisibility;
import com.google.devtools.build.lib.packages.GlobCache;
Expand All @@ -32,7 +31,6 @@
import com.google.devtools.build.lib.syntax.BuildFileAST;
import com.google.devtools.build.lib.syntax.Environment.Extension;
import com.google.devtools.build.lib.syntax.ParserInputSource;
import com.google.devtools.build.lib.testutil.Scratch;
import com.google.devtools.build.lib.testutil.TestRuleClassProvider;
import com.google.devtools.build.lib.testutil.TestUtils;
import com.google.devtools.build.lib.util.Pair;
Expand All @@ -46,16 +44,14 @@
*/
public class PackageFactoryApparatus {

private final EventCollectionApparatus events;
private final Scratch scratch;
private final Reporter reporter;
private final CachingPackageLocator locator;

private final PackageFactory factory;

public PackageFactoryApparatus(EventCollectionApparatus events, Scratch scratch,
PackageFactory.EnvironmentExtension... environmentExtensions) {
this.events = events;
this.scratch = scratch;
public PackageFactoryApparatus(
Reporter reporter, PackageFactory.EnvironmentExtension... environmentExtensions) {
this.reporter = reporter;
RuleClassProvider ruleClassProvider = TestRuleClassProvider.getRuleClassProvider();

// This is used only in globbing and will cause us to always traverse
Expand All @@ -82,7 +78,7 @@ public CachingPackageLocator getPackageLocator() {
*/
public Package createPackage(String packageName, Path buildFile)
throws Exception {
return createPackage(packageName, buildFile, events.reporter());
return createPackage(packageName, buildFile, reporter);
}

/**
Expand All @@ -106,16 +102,7 @@ public Package createPackage(String packageName, Path buildFile,
*/
public BuildFileAST ast(Path buildFile) throws IOException {
ParserInputSource inputSource = ParserInputSource.create(buildFile);
return BuildFileAST.parseBuildFile(inputSource, events.reporter(), /*parsePython=*/false);
}

/**
* Parses the {@code lines} into a {@link BuildFileAST}.
*/
public BuildFileAST ast(String fileName, String... lines)
throws IOException {
Path file = scratch.file(fileName, lines);
return ast(file);
return BuildFileAST.parseBuildFile(inputSource, reporter, /*parsePython=*/ false);
}

/**
Expand Down Expand Up @@ -145,7 +132,7 @@ public Pair<Package, GlobCache> evalAndReturnGlobCache(String packageName, Path
ImmutableMap.<PathFragment, Extension>of(),
ImmutableList.<Label>of());
Package result = resultBuilder.build();
Event.replayEventsOn(events.reporter(), result.getEvents());
Event.replayEventsOn(reporter, result.getEvents());
return Pair.of(result, globCache);
}

Expand Down

0 comments on commit 75eca13

Please sign in to comment.