Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Unified Diff: tools/patch_sdk.dart

Issue 2931773003: Add flutter mode to patched_sdk (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/patch_sdk.dart
diff --git a/tools/patch_sdk.dart b/tools/patch_sdk.dart
index 64038458e20e667185fccd0c72cc514f3e8ffb32..e73cc19da1ca22b2a2a70bd768a2ab7ae72e7cf6 100644
--- a/tools/patch_sdk.dart
+++ b/tools/patch_sdk.dart
@@ -74,14 +74,18 @@ void usage(String mode) {
exit(1);
}
+const validModes = const ['vm', 'dart2js', 'flutter'];
+String mode;
+bool get forVm => mode == 'vm';
+bool get forFlutter => mode == 'flutter';
+bool get forDart2js => mode == 'dart2js';
+
Future _main(List<String> argv) async {
- if (argv.isEmpty) usage('[vm|dart2js]');
- var mode = argv.first;
- if (mode != 'vm' && mode != 'dart2js') usage('[vm|dart2js]');
+ if (argv.isEmpty) usage('[${validModes.join('|')}]');
+ mode = argv.first;
+ if (!validModes.contains(mode)) usage('[${validModes.join('|')}]');
if (argv.length != 5) usage(mode);
- bool forVm = mode == 'vm';
- bool forDart2js = mode == 'dart2js';
var input = argv[1];
var sdkLibIn = path.join(input, 'lib');
var patchIn = argv[2];
@@ -93,19 +97,19 @@ Future _main(List<String> argv) async {
// Parse libraries.dart
var libContents = readInputFile(path.join(
sdkLibIn, '_internal', 'sdk_library_metadata', 'lib', 'libraries.dart'));
- if (forVm) libContents = _updateLibraryMetadata(sdkOut, libContents);
- var sdkLibraries = _getSdkLibraries(libContents, forDart2js);
+ libContents = _updateLibraryMetadata(sdkOut, libContents);
+ var sdkLibraries = _getSdkLibraries(libContents);
Map<String, String> locations = <String, String>{};
// Enumerate core libraries and apply patches
for (SdkLibrary library in sdkLibraries) {
if (forDart2js && library.isVmLibrary) continue;
- if (forVm && library.isDart2JsLibrary) continue;
+ if ((forVm || forFlutter) && library.isDart2JsLibrary) continue;
ahe 2017/06/09 09:23:35 !forDart2js
Siggi Cherem (dart-lang) 2017/06/14 17:55:37 Done.
_applyPatch(library, sdkLibIn, patchIn, sdkOut, locations);
}
- if (forVm) _copyExtraVmLibraries(sdkOut, locations);
+ _copyExtraLibraries(sdkOut, locations);
Uri platform = outDirUri.resolve('platform.dill.tmp');
Uri outline = outDirUri.resolve('outline.dill');
@@ -115,9 +119,11 @@ Future _main(List<String> argv) async {
await _writeSync(
librariesJson.toFilePath(), JSON.encode({"libraries": locations}));
- if (forVm) {
+ if (forVm || forFlutter) {
await fasta.compilePlatform(outDirUri, platform,
- packages: packages, outlineOutput: outline);
+ packages: packages,
+ outlineOutput: outline,
+ backendTarget: forVm ? 'vm_fasta' : 'flutter_fasta');
ahe 2017/06/09 09:23:35 I think you'll get a simple conflict here as Dima
Siggi Cherem (dart-lang) 2017/06/14 17:55:37 Thanks for the heads up. Tuns out this API is stil
} else {
await dart2js.compilePlatform(outDirUri, platform,
packages: packages, outlineOutput: outline);
@@ -133,16 +139,22 @@ Future _main(List<String> argv) async {
// here.
// - the internal platform libraries that may affect how this script
// runs in the VM are discovered by providing the `platform` argument
- // below. Regardless of patched_sdk or patched_dart2js_sdk we provide below
- // the .dill file of patched_sdk (since the script runs in the VM and not
- // in dart2js). At the BUILD.gn level we have a dependency from
- // patched_dart2js_sdk to patched_sdk to ensure that file already exists.
+ // below. For this, we provide below the `platform.dill` of the VM (since
+ // the script runs in the VM, not in dart2js or flutter). At the BUILD.gn
+ // level we need a dependency from patched_dart2js_sdk to patched_sdk (and
+ // from flutter_patched_sdk to patched_sdk) to ensure that file already
+ // exists.
ahe 2017/06/09 09:23:35 I don't understand this.
Siggi Cherem (dart-lang) 2017/06/14 17:55:37 Just clarified, hope this helps.
+ var platformForDeps = platform;
+ var sdkDir = outDirUri;
+ if (forDart2js || forFlutter) {
+ platformForDeps = outDirUri.resolve('../patched_sdk/platform.dill');
+ sdkDir = outDirUri.resolve('../patched_sdk/');
+ }
await fasta.writeDepsFile(Platform.script,
Uri.base.resolveUri(new Uri.file("$outDir.d")), platformFinalLocation,
- sdk: outDirUri,
+ sdk: sdkDir,
packages: packages,
- platform:
- forVm ? platform : outDirUri.resolve('../patched_sdk/platform.dill'),
+ platform: platformForDeps,
extraDependencies: deps);
await new File.fromUri(platform).rename(platformFinalLocation.toFilePath());
@@ -152,11 +164,9 @@ Future _main(List<String> argv) async {
/// sdk/lib/_internal/sdk_library_metadata/lib/libraries.dart to include
/// declarations for vm internal libraries.
String _updateLibraryMetadata(String sdkOut, String libContents) {
- // Copy and patch libraries.dart and version
- libContents = libContents.replaceAll(
- ' libraries = const {',
- ''' libraries = const {
-
+ if (!forVm && !forFlutter) return libContents;
+ var extraLibraries = new StringBuffer();
+ extraLibraries.write('''
"_builtin": const LibraryInfo(
"_builtin/_builtin.dart",
categories: "Client,Server",
@@ -174,14 +184,35 @@ String _updateLibraryMetadata(String sdkOut, String libContents) {
implementation: true,
documented: false,
platforms: VM_PLATFORM),
+ ''');
- "vmservice_io": const LibraryInfo(
- "vmservice_io/vmservice_io.dart",
- implementation: true,
- documented: false,
- platforms: VM_PLATFORM),
+ if (forVm) {
+ extraLibraries.write('''
+ "vmservice_io": const LibraryInfo(
Siggi Cherem (dart-lang) 2017/06/08 22:18:53 Just discovered from talking with Siva that vmserv
+ "vmservice_io/vmservice_io.dart",
+ implementation: true,
+ documented: false,
+ platforms: VM_PLATFORM),
+ ''');
+ } else {
+ extraLibraries.write('''
+ "vmservice_sky": const LibraryInfo(
+ "vmservice_io/vmservice_io.dart",
+ implementation: true,
+ documented: false,
+ platforms: VM_PLATFORM),
+
+ "ui": const LibraryInfo(
+ "ui/ui.dart",
+ categories: "Client,Server",
+ implementation: true,
+ documented: false,
+ platforms: VM_PLATFORM),
+ ''');
+ }
-''');
+ libContents = libContents.replaceAll(
+ ' libraries = const {', ' libraries = const { $extraLibraries');
_writeSync(
path.join(
sdkOut, '_internal', 'sdk_library_metadata', 'lib', 'libraries.dart'),
@@ -189,31 +220,42 @@ String _updateLibraryMetadata(String sdkOut, String libContents) {
return libContents;
}
-/// Copy internal libraries that are developed under 'runtime/bin/' to the
-/// patched_sdk folder.
-_copyExtraVmLibraries(String sdkOut, Map<String, String> locations) {
+/// Copy internal libraries that are developed outside the sdk folder into the
+/// patched_sdk folder. For the VM< this includes files under 'runtime/bin/',
+/// for flutter, this is includes also the ui library.
+_copyExtraLibraries(String sdkOut, Map<String, String> locations) {
+ if (forDart2js) return;
var base = path.fromUri(Platform.script);
var dartDir = path.dirname(path.dirname(path.absolute(base)));
- for (var tuple in [
- ['_builtin', 'builtin.dart']
- ]) {
- var vmLibrary = tuple[0];
- var dartFile = tuple[1];
-
- // The "dart:_builtin" library is only available for the DartVM.
- var builtinLibraryIn = path.join(dartDir, 'runtime', 'bin', dartFile);
- var builtinLibraryOut = path.join(sdkOut, vmLibrary, '${vmLibrary}.dart');
- _writeSync(builtinLibraryOut, readInputFile(builtinLibraryIn));
- locations[vmLibrary] = path.join(vmLibrary, '${vmLibrary}.dart');
- }
+ var builtinLibraryIn = path.join(dartDir, 'runtime', 'bin', 'builtin.dart');
+ var builtinLibraryOut = path.join(sdkOut, '_builtin', '_builtin.dart');
+ _writeSync(builtinLibraryOut, readInputFile(builtinLibraryIn));
+ locations['_builtin'] = path.join('_builtin', '_builtin.dart');
for (var file in ['loader.dart', 'server.dart', 'vmservice_io.dart']) {
var libraryIn = path.join(dartDir, 'runtime', 'bin', 'vmservice', file);
var libraryOut = path.join(sdkOut, 'vmservice_io', file);
_writeSync(libraryOut, readInputFile(libraryIn));
}
- locations["vmservice_io"] = "vmservice_io/vmservice_io.dart";
+ locations[forVm ? "vmservice_io" : "vmservice_sky"] =
+ path.join('vmservice_io', 'vmservice_io.dart');
+
+ if (forFlutter) {
+ // Flutter repo has this layout:
+ // engine/src/
+ // dart/
+ // flutter/
+ var srcDir = path.dirname(path.dirname(path.dirname(path.absolute(base))));
+ var uiLibraryInDir = path.join(srcDir, 'flutter', 'lib', 'ui');
+ for (var file in new Directory(uiLibraryInDir).listSync()) {
+ if (!file.path.endsWith('.dart')) continue;
+ var name = path.basename(file.path);
+ var uiLibraryOut = path.join(sdkOut, 'ui', name);
+ _writeSync(uiLibraryOut, readInputFile(file.path));
+ }
+ locations['ui'] = 'ui/ui.dart';
+ }
}
_applyPatch(SdkLibrary library, String sdkLibIn, String patchIn, String sdkOut,
@@ -624,8 +666,8 @@ class _StringEdit implements Comparable<_StringEdit> {
}
}
-List<SdkLibrary> _getSdkLibraries(String contents, bool useDart2js) {
- var libraryBuilder = new SdkLibrariesReader_LibraryBuilder(useDart2js);
+List<SdkLibrary> _getSdkLibraries(String contents) {
+ var libraryBuilder = new SdkLibrariesReader_LibraryBuilder(forDart2js);
parseCompilationUnit(contents).accept(libraryBuilder);
return libraryBuilder.librariesMap.sdkLibraries;
}
« pkg/kernel/lib/target/flutter_fasta.dart ('K') | « pkg/kernel/lib/target/targets.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698