Support steps that only run on the main module

I'll work on a follow up CL to add unit tests for it.

Change-Id: Ifa142731eb60ba14fb3187b5f3e9333cef12f751
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/102124
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
This commit is contained in:
Sigmund Cherem 2019-05-10 19:43:58 +00:00 committed by commit-bot@chromium.org
parent 8aa2c13c9f
commit 0edab8264a
6 changed files with 19 additions and 4 deletions

View file

@ -60,7 +60,7 @@ Future<ModularTest> loadTest(Uri uri) async {
var relativeUri = Uri.parse(fileName);
var isMain = moduleName == 'main';
var module = Module(moduleName, [], testUri, [relativeUri],
mainSource: isMain ? relativeUri : null);
mainSource: isMain ? relativeUri : null, isMain: isMain);
if (isMain) mainModule = module;
modules[moduleName] = module;
} else if (fileName == '.packages') {

View file

@ -39,11 +39,15 @@ class ModularStep {
/// Data that this step produces.
final DataId resultId;
/// Whether this step is only executed on the main module.
final bool onlyOnMain;
ModularStep(
{this.needsSources: true,
this.dependencyDataNeeded: const [],
this.moduleDataNeeded: const [],
this.resultId});
this.resultId,
this.onlyOnMain: false});
}
/// An object to uniquely identify modular data produced by a modular step.
@ -124,6 +128,7 @@ abstract class Pipeline<S extends ModularStep> {
}
parentDependencies.addAll(transitiveDependencies);
if (step.onlyOnMain && !module.isMain) return;
// Include only requested data from transitive dependencies.
Map<Module, Set<DataId>> visibleData = {};

View file

@ -41,8 +41,11 @@ class Module {
/// package name matches the module name.
bool isPackage;
/// Whether this is the main entry module of a test.
bool isMain;
Module(this.name, this.dependencies, this.rootUri, this.sources,
{this.mainSource, this.isPackage: false}) {
{this.mainSource, this.isPackage: false, this.isMain: false}) {
if (!_validModuleName.hasMatch(name)) {
throw ArgumentError("invalid module name: $name");
}

View file

@ -86,6 +86,7 @@ class SourceOnlyStep implements IOModularStep {
final bool needsSources;
List<DataId> get dependencyDataNeeded => const [];
List<DataId> get moduleDataNeeded => const [];
bool get onlyOnMain => false;
SourceOnlyStep(this.action, this.resultId, this.needsSources);
@ -111,6 +112,7 @@ class ModuleDataStep implements IOModularStep {
final List<DataId> moduleDataNeeded;
final DataId resultId;
final DataId inputId;
bool get onlyOnMain => false;
ModuleDataStep(this.action, this.inputId, this.resultId, bool requestInput)
: moduleDataNeeded = requestInput ? [inputId] : [];
@ -134,6 +136,7 @@ class LinkStep implements IOModularStep {
final DataId inputId;
final DataId depId;
final DataId resultId;
bool get onlyOnMain => false;
LinkStep(this.action, this.inputId, this.depId, this.resultId,
bool requestDependencies)

View file

@ -75,7 +75,8 @@ String _dumpAsText(ModularTest test) {
buffer.write('\n');
}
buffer.write(module.name);
if (test.mainModule == module) {
if (module.isMain) {
Expect.equals(test.mainModule, module);
buffer.write('\n **main module**');
}
buffer.write('\n is package? ${module.isPackage ? 'yes' : 'no'}');

View file

@ -64,6 +64,7 @@ class SourceOnlyStep implements MemoryModularStep {
final bool needsSources;
List<DataId> get dependencyDataNeeded => const [];
List<DataId> get moduleDataNeeded => const [];
bool get onlyOnMain => false;
SourceOnlyStep(this.action, this.resultId, this.needsSources);
@ -84,6 +85,7 @@ class ModuleDataStep implements MemoryModularStep {
final List<DataId> moduleDataNeeded;
final DataId resultId;
final DataId inputId;
bool get onlyOnMain => false;
ModuleDataStep(this.action, this.inputId, this.resultId, bool requestInput)
: moduleDataNeeded = requestInput ? [inputId] : [];
@ -104,6 +106,7 @@ class LinkStep implements MemoryModularStep {
final DataId inputId;
final DataId depId;
final DataId resultId;
bool get onlyOnMain => false;
LinkStep(this.action, this.inputId, this.depId, this.resultId,
bool requestDependencies)