[flutter_tools] remove automatic multiroot scheme (#50284)
This commit is contained in:
parent
6bfff984de
commit
181cdec079
@ -6,3 +6,4 @@ builders:
|
|||||||
- simpleBuilder
|
- simpleBuilder
|
||||||
build_extensions: {'.spec':['.dart']}
|
build_extensions: {'.spec':['.dart']}
|
||||||
auto_apply: all_packages
|
auto_apply: all_packages
|
||||||
|
build_to: source
|
||||||
|
@ -11,7 +11,6 @@ import '../../build_info.dart';
|
|||||||
import '../../compile.dart';
|
import '../../compile.dart';
|
||||||
import '../../dart/package_map.dart';
|
import '../../dart/package_map.dart';
|
||||||
import '../../globals.dart' as globals;
|
import '../../globals.dart' as globals;
|
||||||
import '../../project.dart';
|
|
||||||
import '../build_system.dart';
|
import '../build_system.dart';
|
||||||
import '../depfile.dart';
|
import '../depfile.dart';
|
||||||
import 'assets.dart';
|
import 'assets.dart';
|
||||||
@ -156,9 +155,7 @@ class Dart2JSTarget extends Target {
|
|||||||
final bool csp = environment.defines[kCspMode] == 'true';
|
final bool csp = environment.defines[kCspMode] == 'true';
|
||||||
final BuildMode buildMode = getBuildModeForName(environment.defines[kBuildMode]);
|
final BuildMode buildMode = getBuildModeForName(environment.defines[kBuildMode]);
|
||||||
final String specPath = globals.fs.path.join(globals.artifacts.getArtifactPath(Artifact.flutterWebSdk), 'libraries.json');
|
final String specPath = globals.fs.path.join(globals.artifacts.getArtifactPath(Artifact.flutterWebSdk), 'libraries.json');
|
||||||
final String packageFile = FlutterProject.fromDirectory(environment.projectDir).hasBuilders
|
final String packageFile = PackageMap.globalPackagesPath;
|
||||||
? PackageMap.globalGeneratedPackagesPath
|
|
||||||
: PackageMap.globalPackagesPath;
|
|
||||||
final File outputFile = environment.buildDir.childFile('main.dart.js');
|
final File outputFile = environment.buildDir.childFile('main.dart.js');
|
||||||
|
|
||||||
final ProcessResult result = await globals.processManager.run(<String>[
|
final ProcessResult result = await globals.processManager.run(<String>[
|
||||||
|
@ -4,19 +4,12 @@
|
|||||||
|
|
||||||
import 'package:meta/meta.dart';
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
import 'artifacts.dart';
|
|
||||||
import 'base/context.dart';
|
import 'base/context.dart';
|
||||||
import 'build_info.dart';
|
import 'build_info.dart';
|
||||||
import 'compile.dart';
|
import 'compile.dart';
|
||||||
import 'dart/package_map.dart';
|
|
||||||
import 'globals.dart' as globals;
|
import 'globals.dart' as globals;
|
||||||
import 'project.dart';
|
import 'project.dart';
|
||||||
|
|
||||||
// Arbitrarily chosen multi-root file scheme. This is used to configure the
|
|
||||||
// frontend_server to resolve a package uri to multiple filesystem directories.
|
|
||||||
// In this case, the source directory and a generated directory.
|
|
||||||
const String kMultiRootScheme = 'org-dartlang-app';
|
|
||||||
|
|
||||||
/// The [CodeGenerator] instance.
|
/// The [CodeGenerator] instance.
|
||||||
///
|
///
|
||||||
/// If [experimentalBuildEnabled] is false, this will contain an unsupported
|
/// If [experimentalBuildEnabled] is false, this will contain an unsupported
|
||||||
@ -25,9 +18,6 @@ CodeGenerator get codeGenerator => context.get<CodeGenerator>();
|
|||||||
|
|
||||||
/// A wrapper for a build_runner process which delegates to a generated
|
/// A wrapper for a build_runner process which delegates to a generated
|
||||||
/// build script.
|
/// build script.
|
||||||
///
|
|
||||||
/// This is only enabled if [experimentalBuildEnabled] is true, and only for
|
|
||||||
/// external flutter users.
|
|
||||||
abstract class CodeGenerator {
|
abstract class CodeGenerator {
|
||||||
const CodeGenerator();
|
const CodeGenerator();
|
||||||
|
|
||||||
@ -40,18 +30,6 @@ abstract class CodeGenerator {
|
|||||||
// Generates a synthetic package under .dart_tool/flutter_tool which is in turn
|
// Generates a synthetic package under .dart_tool/flutter_tool which is in turn
|
||||||
// used to generate a build script.
|
// used to generate a build script.
|
||||||
Future<void> generateBuildScript(FlutterProject flutterProject);
|
Future<void> generateBuildScript(FlutterProject flutterProject);
|
||||||
|
|
||||||
/// Create generated packages file which adds a multi-root scheme to the user's
|
|
||||||
/// project directory. Currently we only replace the root package with a multi-root
|
|
||||||
/// scheme. To support codegen on arbitrary packages we would need to do
|
|
||||||
/// this for each dependency.
|
|
||||||
void updatePackages(FlutterProject flutterProject) {
|
|
||||||
final String oldPackagesContents = globals.fs.file(PackageMap.globalPackagesPath).readAsStringSync();
|
|
||||||
final String appName = flutterProject.manifest.appName;
|
|
||||||
final String newPackagesContents = oldPackagesContents.replaceFirst('$appName:lib/', '$appName:$kMultiRootScheme:/');
|
|
||||||
final String generatedPackagesPath = globals.fs.path.setExtension(PackageMap.globalPackagesPath, '.generated');
|
|
||||||
globals.fs.file(generatedPackagesPath).writeAsStringSync(newPackagesContents);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class UnsupportedCodeGenerator extends CodeGenerator {
|
class UnsupportedCodeGenerator extends CodeGenerator {
|
||||||
@ -97,7 +75,6 @@ class CodeGeneratingKernelCompiler implements KernelCompiler {
|
|||||||
@required BuildMode buildMode,
|
@required BuildMode buildMode,
|
||||||
bool trackWidgetCreation,
|
bool trackWidgetCreation,
|
||||||
List<String> extraFrontEndOptions,
|
List<String> extraFrontEndOptions,
|
||||||
// These arguments are currently unused.
|
|
||||||
String sdkRoot,
|
String sdkRoot,
|
||||||
String packagesPath,
|
String packagesPath,
|
||||||
List<String> fileSystemRoots,
|
List<String> fileSystemRoots,
|
||||||
@ -108,13 +85,7 @@ class CodeGeneratingKernelCompiler implements KernelCompiler {
|
|||||||
String platformDill,
|
String platformDill,
|
||||||
List<String> dartDefines,
|
List<String> dartDefines,
|
||||||
}) async {
|
}) async {
|
||||||
if (fileSystemRoots != null || fileSystemScheme != null || depFilePath != null || targetModel != null || sdkRoot != null || packagesPath != null) {
|
|
||||||
globals.printTrace('fileSystemRoots, fileSystemScheme, depFilePath, targetModel, '
|
|
||||||
'sdkRoot, packagesPath are not supported when using the experimental '
|
|
||||||
'build* pipeline');
|
|
||||||
}
|
|
||||||
final FlutterProject flutterProject = FlutterProject.current();
|
final FlutterProject flutterProject = FlutterProject.current();
|
||||||
codeGenerator.updatePackages(flutterProject);
|
|
||||||
final CodegenDaemon codegenDaemon = await codeGenerator.daemon(flutterProject);
|
final CodegenDaemon codegenDaemon = await codeGenerator.daemon(flutterProject);
|
||||||
codegenDaemon.startBuild();
|
codegenDaemon.startBuild();
|
||||||
await for (final CodegenStatus codegenStatus in codegenDaemon.buildResults) {
|
await for (final CodegenStatus codegenStatus in codegenDaemon.buildResults) {
|
||||||
@ -135,12 +106,9 @@ class CodeGeneratingKernelCompiler implements KernelCompiler {
|
|||||||
trackWidgetCreation: trackWidgetCreation,
|
trackWidgetCreation: trackWidgetCreation,
|
||||||
extraFrontEndOptions: extraFrontEndOptions,
|
extraFrontEndOptions: extraFrontEndOptions,
|
||||||
sdkRoot: sdkRoot,
|
sdkRoot: sdkRoot,
|
||||||
packagesPath: PackageMap.globalGeneratedPackagesPath,
|
packagesPath: packagesPath,
|
||||||
fileSystemRoots: <String>[
|
fileSystemRoots: fileSystemRoots,
|
||||||
globals.fs.path.join(flutterProject.generated.path, 'lib${globals.platform.pathSeparator}'),
|
fileSystemScheme: fileSystemScheme,
|
||||||
globals.fs.path.join(flutterProject.directory.path, 'lib${globals.platform.pathSeparator}'),
|
|
||||||
],
|
|
||||||
fileSystemScheme: kMultiRootScheme,
|
|
||||||
depFilePath: depFilePath,
|
depFilePath: depFilePath,
|
||||||
targetModel: targetModel,
|
targetModel: targetModel,
|
||||||
initializeFromDill: initializeFromDill,
|
initializeFromDill: initializeFromDill,
|
||||||
@ -152,7 +120,7 @@ class CodeGeneratingKernelCompiler implements KernelCompiler {
|
|||||||
/// An implementation of a [ResidentCompiler] which runs a [BuildRunner] before
|
/// An implementation of a [ResidentCompiler] which runs a [BuildRunner] before
|
||||||
/// talking to the CFE.
|
/// talking to the CFE.
|
||||||
class CodeGeneratingResidentCompiler implements ResidentCompiler {
|
class CodeGeneratingResidentCompiler implements ResidentCompiler {
|
||||||
CodeGeneratingResidentCompiler._(this._residentCompiler, this._codegenDaemon, this._flutterProject);
|
CodeGeneratingResidentCompiler._(this._residentCompiler, this._codegenDaemon);
|
||||||
|
|
||||||
/// Creates a new [ResidentCompiler] and configures a [BuildDaemonClient] to
|
/// Creates a new [ResidentCompiler] and configures a [BuildDaemonClient] to
|
||||||
/// run builds.
|
/// run builds.
|
||||||
@ -161,37 +129,10 @@ class CodeGeneratingResidentCompiler implements ResidentCompiler {
|
|||||||
/// compiler will only be initialized with the correct configuration for
|
/// compiler will only be initialized with the correct configuration for
|
||||||
/// codegen mode.
|
/// codegen mode.
|
||||||
static Future<ResidentCompiler> create({
|
static Future<ResidentCompiler> create({
|
||||||
|
@required ResidentCompiler residentCompiler,
|
||||||
@required FlutterProject flutterProject,
|
@required FlutterProject flutterProject,
|
||||||
@required BuildMode buildMode,
|
|
||||||
bool trackWidgetCreation = false,
|
|
||||||
CompilerMessageConsumer compilerMessageConsumer = globals.printError,
|
|
||||||
bool unsafePackageSerialization = false,
|
|
||||||
String outputPath,
|
|
||||||
String initializeFromDill,
|
|
||||||
bool runCold = false,
|
bool runCold = false,
|
||||||
TargetPlatform targetPlatform,
|
|
||||||
@required List<String> dartDefines,
|
|
||||||
}) async {
|
}) async {
|
||||||
codeGenerator.updatePackages(flutterProject);
|
|
||||||
final ResidentCompiler residentCompiler = ResidentCompiler(
|
|
||||||
globals.artifacts.getArtifactPath(
|
|
||||||
Artifact.flutterPatchedSdkPath,
|
|
||||||
platform: targetPlatform,
|
|
||||||
mode: buildMode,
|
|
||||||
),
|
|
||||||
buildMode: buildMode,
|
|
||||||
trackWidgetCreation: trackWidgetCreation,
|
|
||||||
packagesPath: PackageMap.globalGeneratedPackagesPath,
|
|
||||||
fileSystemRoots: <String>[
|
|
||||||
globals.fs.path.join(flutterProject.generated.path, 'lib${globals.platform.pathSeparator}'),
|
|
||||||
globals.fs.path.join(flutterProject.directory.path, 'lib${globals.platform.pathSeparator}'),
|
|
||||||
],
|
|
||||||
fileSystemScheme: kMultiRootScheme,
|
|
||||||
targetModel: TargetModel.flutter,
|
|
||||||
unsafePackageSerialization: unsafePackageSerialization,
|
|
||||||
initializeFromDill: initializeFromDill,
|
|
||||||
dartDefines: dartDefines,
|
|
||||||
);
|
|
||||||
if (runCold) {
|
if (runCold) {
|
||||||
return residentCompiler;
|
return residentCompiler;
|
||||||
}
|
}
|
||||||
@ -203,12 +144,11 @@ class CodeGeneratingResidentCompiler implements ResidentCompiler {
|
|||||||
if (status == CodegenStatus.Failed) {
|
if (status == CodegenStatus.Failed) {
|
||||||
globals.printError('Code generation failed, build may have compile errors.');
|
globals.printError('Code generation failed, build may have compile errors.');
|
||||||
}
|
}
|
||||||
return CodeGeneratingResidentCompiler._(residentCompiler, codegenDaemon, flutterProject);
|
return CodeGeneratingResidentCompiler._(residentCompiler, codegenDaemon);
|
||||||
}
|
}
|
||||||
|
|
||||||
final ResidentCompiler _residentCompiler;
|
final ResidentCompiler _residentCompiler;
|
||||||
final CodegenDaemon _codegenDaemon;
|
final CodegenDaemon _codegenDaemon;
|
||||||
final FlutterProject _flutterProject;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void accept() {
|
void accept() {
|
||||||
@ -230,17 +170,11 @@ class CodeGeneratingResidentCompiler implements ResidentCompiler {
|
|||||||
if (_codegenDaemon.lastStatus == CodegenStatus.Failed) {
|
if (_codegenDaemon.lastStatus == CodegenStatus.Failed) {
|
||||||
globals.printError('Code generation failed, build may have compile errors.');
|
globals.printError('Code generation failed, build may have compile errors.');
|
||||||
}
|
}
|
||||||
// Update the generated packages file if the original packages file has changes.
|
|
||||||
if (globals.fs.statSync(PackageMap.globalPackagesPath).modified.millisecondsSinceEpoch >
|
|
||||||
globals.fs.statSync(PackageMap.globalGeneratedPackagesPath).modified.millisecondsSinceEpoch) {
|
|
||||||
codeGenerator.updatePackages(_flutterProject);
|
|
||||||
invalidatedFiles.add(globals.fs.file(PackageMap.globalGeneratedPackagesPath).uri);
|
|
||||||
}
|
|
||||||
return _residentCompiler.recompile(
|
return _residentCompiler.recompile(
|
||||||
mainPath,
|
mainPath,
|
||||||
invalidatedFiles,
|
invalidatedFiles,
|
||||||
outputPath: outputPath,
|
outputPath: outputPath,
|
||||||
packagesFilePath: PackageMap.globalGeneratedPackagesPath,
|
packagesFilePath: packagesFilePath,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,8 +19,6 @@ class PackageMap {
|
|||||||
|
|
||||||
static String get globalPackagesPath => _globalPackagesPath ?? kPackagesFileName;
|
static String get globalPackagesPath => _globalPackagesPath ?? kPackagesFileName;
|
||||||
|
|
||||||
static String get globalGeneratedPackagesPath => globals.fs.path.setExtension(globalPackagesPath, '.generated');
|
|
||||||
|
|
||||||
static set globalPackagesPath(String value) {
|
static set globalPackagesPath(String value) {
|
||||||
_globalPackagesPath = value;
|
_globalPackagesPath = value;
|
||||||
}
|
}
|
||||||
|
@ -94,13 +94,6 @@ class FlutterDevice {
|
|||||||
.absolute.uri.toString(),
|
.absolute.uri.toString(),
|
||||||
dartDefines: dartDefines,
|
dartDefines: dartDefines,
|
||||||
);
|
);
|
||||||
} else if (flutterProject.hasBuilders) {
|
|
||||||
generator = await CodeGeneratingResidentCompiler.create(
|
|
||||||
targetPlatform: targetPlatform,
|
|
||||||
buildMode: buildMode,
|
|
||||||
flutterProject: flutterProject,
|
|
||||||
dartDefines: dartDefines,
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
generator = ResidentCompiler(
|
generator = ResidentCompiler(
|
||||||
globals.artifacts.getArtifactPath(
|
globals.artifacts.getArtifactPath(
|
||||||
@ -116,6 +109,12 @@ class FlutterDevice {
|
|||||||
experimentalFlags: experimentalFlags,
|
experimentalFlags: experimentalFlags,
|
||||||
dartDefines: dartDefines,
|
dartDefines: dartDefines,
|
||||||
);
|
);
|
||||||
|
if (flutterProject.hasBuilders) {
|
||||||
|
generator = await CodeGeneratingResidentCompiler.create(
|
||||||
|
residentCompiler: generator,
|
||||||
|
flutterProject: flutterProject,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return FlutterDevice(
|
return FlutterDevice(
|
||||||
device,
|
device,
|
||||||
|
@ -93,20 +93,7 @@ class TestCompiler {
|
|||||||
/// Create the resident compiler used to compile the test.
|
/// Create the resident compiler used to compile the test.
|
||||||
@visibleForTesting
|
@visibleForTesting
|
||||||
Future<ResidentCompiler> createCompiler() async {
|
Future<ResidentCompiler> createCompiler() async {
|
||||||
if (flutterProject.hasBuilders) {
|
final ResidentCompiler residentCompiler = ResidentCompiler(
|
||||||
return CodeGeneratingResidentCompiler.create(
|
|
||||||
flutterProject: flutterProject,
|
|
||||||
buildMode: buildMode,
|
|
||||||
trackWidgetCreation: trackWidgetCreation,
|
|
||||||
compilerMessageConsumer: _reportCompilerMessage,
|
|
||||||
initializeFromDill: testFilePath,
|
|
||||||
// We already ran codegen once at the start, we only need to
|
|
||||||
// configure builders.
|
|
||||||
runCold: true,
|
|
||||||
dartDefines: const <String>[],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return ResidentCompiler(
|
|
||||||
globals.artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath),
|
globals.artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath),
|
||||||
packagesPath: PackageMap.globalPackagesPath,
|
packagesPath: PackageMap.globalPackagesPath,
|
||||||
buildMode: buildMode,
|
buildMode: buildMode,
|
||||||
@ -116,6 +103,13 @@ class TestCompiler {
|
|||||||
unsafePackageSerialization: false,
|
unsafePackageSerialization: false,
|
||||||
dartDefines: const <String>[],
|
dartDefines: const <String>[],
|
||||||
);
|
);
|
||||||
|
if (flutterProject.hasBuilders) {
|
||||||
|
return CodeGeneratingResidentCompiler.create(
|
||||||
|
residentCompiler: residentCompiler,
|
||||||
|
flutterProject: flutterProject,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return residentCompiler;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle a compilation request.
|
// Handle a compilation request.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user