[web] Start splitting the engine into smaller libs (flutter/engine#25569)
This commit is contained in:
@@ -519,6 +519,7 @@ FILE: ../../../flutter/lib/web_ui/lib/src/engine/key_map.dart
|
||||
FILE: ../../../flutter/lib/web_ui/lib/src/engine/keyboard.dart
|
||||
FILE: ../../../flutter/lib/web_ui/lib/src/engine/keyboard_binding.dart
|
||||
FILE: ../../../flutter/lib/web_ui/lib/src/engine/mouse_cursor.dart
|
||||
FILE: ../../../flutter/lib/web_ui/lib/src/engine/navigation.dart
|
||||
FILE: ../../../flutter/lib/web_ui/lib/src/engine/navigation/history.dart
|
||||
FILE: ../../../flutter/lib/web_ui/lib/src/engine/navigation/js_url_strategy.dart
|
||||
FILE: ../../../flutter/lib/web_ui/lib/src/engine/navigation/url_strategy.dart
|
||||
@@ -542,6 +543,7 @@ FILE: ../../../flutter/lib/web_ui/lib/src/engine/semantics/semantics.dart
|
||||
FILE: ../../../flutter/lib/web_ui/lib/src/engine/semantics/semantics_helper.dart
|
||||
FILE: ../../../flutter/lib/web_ui/lib/src/engine/semantics/tappable.dart
|
||||
FILE: ../../../flutter/lib/web_ui/lib/src/engine/semantics/text_field.dart
|
||||
FILE: ../../../flutter/lib/web_ui/lib/src/engine/services.dart
|
||||
FILE: ../../../flutter/lib/web_ui/lib/src/engine/services/buffers.dart
|
||||
FILE: ../../../flutter/lib/web_ui/lib/src/engine/services/message_codec.dart
|
||||
FILE: ../../../flutter/lib/web_ui/lib/src/engine/services/message_codecs.dart
|
||||
|
||||
@@ -5,8 +5,19 @@
|
||||
@JS()
|
||||
library engine;
|
||||
|
||||
// This file is transformed during the build process in order to make it a
|
||||
// single library. Some notable transformations:
|
||||
//
|
||||
// 1. Imports of engine/* files are stripped out.
|
||||
// 2. Exports of engine/* files are replaced with a part directive.
|
||||
//
|
||||
// The code that performs the transformations lives in:
|
||||
// - https://github.com/flutter/engine/blob/master/web_sdk/sdk_rewriter.dart
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:collection'
|
||||
// Some of these names are used in services/buffers.dart for example.
|
||||
// ignore: unused_shown_name
|
||||
show ListBase, IterableBase, DoubleLinkedQueue, DoubleLinkedQueueEntry;
|
||||
import 'dart:convert' hide Codec;
|
||||
import 'dart:developer' as developer;
|
||||
@@ -21,10 +32,68 @@ import 'package:meta/meta.dart';
|
||||
|
||||
import '../ui.dart' as ui;
|
||||
|
||||
part 'engine/alarm_clock.dart';
|
||||
import 'engine/alarm_clock.dart';
|
||||
export 'engine/alarm_clock.dart';
|
||||
|
||||
import 'engine/browser_detection.dart';
|
||||
export 'engine/browser_detection.dart';
|
||||
|
||||
import 'engine/mouse_cursor.dart';
|
||||
export 'engine/mouse_cursor.dart';
|
||||
|
||||
import 'engine/navigation/history.dart';
|
||||
export 'engine/navigation/history.dart';
|
||||
|
||||
import 'engine/navigation/js_url_strategy.dart';
|
||||
export 'engine/navigation/js_url_strategy.dart';
|
||||
|
||||
import 'engine/navigation/url_strategy.dart';
|
||||
export 'engine/navigation/url_strategy.dart';
|
||||
|
||||
import 'engine/plugins.dart';
|
||||
export 'engine/plugins.dart';
|
||||
|
||||
import 'engine/pointer_binding.dart';
|
||||
export 'engine/pointer_binding.dart';
|
||||
|
||||
// This import is intentionally commented out because the analyzer says it's unused.
|
||||
// import 'engine/pointer_converter.dart';
|
||||
export 'engine/pointer_converter.dart';
|
||||
|
||||
// This import is intentionally commented out because the analyzer says it's unused.
|
||||
// import 'engine/services/buffers.dart';
|
||||
export 'engine/services/buffers.dart';
|
||||
|
||||
import 'engine/services/message_codec.dart';
|
||||
export 'engine/services/message_codec.dart';
|
||||
|
||||
import 'engine/services/message_codecs.dart';
|
||||
export 'engine/services/message_codecs.dart';
|
||||
|
||||
// This import is intentionally commented out because the analyzer says it's unused.
|
||||
// import 'engine/services/serialization.dart';
|
||||
export 'engine/services/serialization.dart';
|
||||
|
||||
import 'engine/shadow.dart';
|
||||
export 'engine/shadow.dart';
|
||||
|
||||
import 'engine/test_embedding.dart';
|
||||
export 'engine/test_embedding.dart';
|
||||
|
||||
import 'engine/ulps.dart';
|
||||
export 'engine/ulps.dart';
|
||||
|
||||
import 'engine/validators.dart';
|
||||
export 'engine/validators.dart';
|
||||
|
||||
import 'engine/vector_math.dart';
|
||||
export 'engine/vector_math.dart';
|
||||
|
||||
import 'engine/web_experiments.dart';
|
||||
export 'engine/web_experiments.dart';
|
||||
|
||||
part 'engine/assets.dart';
|
||||
part 'engine/bitmap_canvas.dart';
|
||||
part 'engine/browser_detection.dart';
|
||||
part 'engine/canvaskit/canvas.dart';
|
||||
part 'engine/canvaskit/canvaskit_canvas.dart';
|
||||
part 'engine/canvaskit/canvaskit_api.dart';
|
||||
@@ -63,9 +132,6 @@ part 'engine/dom_canvas.dart';
|
||||
part 'engine/dom_renderer.dart';
|
||||
part 'engine/engine_canvas.dart';
|
||||
part 'engine/frame_reference.dart';
|
||||
part 'engine/navigation/history.dart';
|
||||
part 'engine/navigation/js_url_strategy.dart';
|
||||
part 'engine/navigation/url_strategy.dart';
|
||||
part 'engine/html/backdrop_filter.dart';
|
||||
part 'engine/html/canvas.dart';
|
||||
part 'engine/html/clip.dart';
|
||||
@@ -101,14 +167,10 @@ part 'engine/html_image_codec.dart';
|
||||
part 'engine/keyboard_binding.dart';
|
||||
part 'engine/keyboard.dart';
|
||||
part 'engine/key_map.dart';
|
||||
part 'engine/mouse_cursor.dart';
|
||||
part 'engine/onscreen_logging.dart';
|
||||
part 'engine/picture.dart';
|
||||
part 'engine/platform_dispatcher.dart';
|
||||
part 'engine/platform_views.dart';
|
||||
part 'engine/plugins.dart';
|
||||
part 'engine/pointer_binding.dart';
|
||||
part 'engine/pointer_converter.dart';
|
||||
part 'engine/profiler.dart';
|
||||
part 'engine/rrect_renderer.dart';
|
||||
part 'engine/semantics/accessibility.dart';
|
||||
@@ -122,12 +184,6 @@ part 'engine/semantics/semantics.dart';
|
||||
part 'engine/semantics/semantics_helper.dart';
|
||||
part 'engine/semantics/tappable.dart';
|
||||
part 'engine/semantics/text_field.dart';
|
||||
part 'engine/services/buffers.dart';
|
||||
part 'engine/services/message_codec.dart';
|
||||
part 'engine/services/message_codecs.dart';
|
||||
part 'engine/services/serialization.dart';
|
||||
part 'engine/shadow.dart';
|
||||
part 'engine/test_embedding.dart';
|
||||
part 'engine/text/font_collection.dart';
|
||||
part 'engine/text/layout_service.dart';
|
||||
part 'engine/text/line_break_properties.dart';
|
||||
@@ -144,11 +200,7 @@ part 'engine/text_editing/autofill_hint.dart';
|
||||
part 'engine/text_editing/input_type.dart';
|
||||
part 'engine/text_editing/text_capitalization.dart';
|
||||
part 'engine/text_editing/text_editing.dart';
|
||||
part 'engine/ulps.dart';
|
||||
part 'engine/util.dart';
|
||||
part 'engine/validators.dart';
|
||||
part 'engine/vector_math.dart';
|
||||
part 'engine/web_experiments.dart';
|
||||
part 'engine/window.dart';
|
||||
|
||||
// The mode the app is running in.
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
part of engine;
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:ui/ui.dart' as ui;
|
||||
|
||||
/// A function that returns current system time.
|
||||
typedef TimestampFunction = DateTime Function();
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
part of engine;
|
||||
import 'dart:html' as html;
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
/// The HTML engine used by the current browser.
|
||||
enum BrowserEngine {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
part of engine;
|
||||
import 'package:ui/src/engine.dart' show domRenderer, DomRenderer;
|
||||
|
||||
/// Provides mouse cursor bindings, such as the `flutter/mousecursor` channel.
|
||||
class MouseCursor {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.12
|
||||
export 'navigation/history.dart';
|
||||
export 'navigation/js_url_strategy.dart';
|
||||
export 'navigation/url_strategy.dart';
|
||||
@@ -2,7 +2,14 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
part of engine;
|
||||
import 'dart:html' as html;
|
||||
|
||||
import 'package:ui/src/engine.dart' show EnginePlatformDispatcher;
|
||||
import 'package:ui/ui.dart' as ui;
|
||||
|
||||
import '../services/message_codec.dart';
|
||||
import '../services/message_codecs.dart';
|
||||
import 'url_strategy.dart';
|
||||
|
||||
/// An abstract class that provides the API for [EngineWindow] to delegate its
|
||||
/// navigating events.
|
||||
|
||||
@@ -2,7 +2,13 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
part of engine;
|
||||
@JS()
|
||||
library js_url_strategy;
|
||||
|
||||
import 'dart:html' as html;
|
||||
|
||||
import 'package:js/js.dart';
|
||||
import 'package:ui/ui.dart' as ui;
|
||||
|
||||
typedef _PathGetter = String Function();
|
||||
|
||||
|
||||
@@ -2,7 +2,12 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
part of engine;
|
||||
import 'dart:async';
|
||||
import 'dart:html' as html;
|
||||
|
||||
import 'package:ui/ui.dart' as ui;
|
||||
|
||||
import 'js_url_strategy.dart';
|
||||
|
||||
/// Represents and reads route state from the browser's URL.
|
||||
///
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
part of engine;
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:ui/ui.dart' as ui;
|
||||
|
||||
Future<void> Function(String, ByteData?, ui.PlatformMessageResponseCallback?)? pluginMessageCallHandler;
|
||||
|
||||
@@ -2,7 +2,16 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
part of engine;
|
||||
import 'dart:html' as html;
|
||||
import 'dart:js' as js;
|
||||
import 'dart:js_util' as js_util;
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:ui/src/engine.dart';
|
||||
import 'package:ui/ui.dart' as ui;
|
||||
|
||||
import 'pointer_converter.dart';
|
||||
|
||||
/// Set this flag to true to see all the fired events in the console.
|
||||
const bool _debugLogPointerEvents = false;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
part of engine;
|
||||
import 'package:ui/ui.dart' as ui;
|
||||
|
||||
const bool _debugLogPointerConverter = false;
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.12
|
||||
export 'services/buffers.dart';
|
||||
export 'services/message_codec.dart';
|
||||
export 'services/message_codecs.dart';
|
||||
export 'services/serialization.dart';
|
||||
@@ -2,7 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
part of engine;
|
||||
import 'dart:collection';
|
||||
import 'dart:typed_data';
|
||||
|
||||
abstract class _TypedDataBuffer<E> extends ListBase<E> {
|
||||
static const int _initialLength = 8;
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
part of engine;
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
/// A message encoding/decoding mechanism.
|
||||
///
|
||||
|
||||
@@ -2,7 +2,11 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
part of engine;
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'message_codec.dart';
|
||||
import 'serialization.dart';
|
||||
|
||||
/// [MessageCodec] with unencoded binary messages represented using [ByteData].
|
||||
///
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
part of engine;
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'buffers.dart';
|
||||
|
||||
/// Write-only buffer for incrementally building a [ByteData] instance.
|
||||
///
|
||||
|
||||
@@ -2,7 +2,11 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
part of engine;
|
||||
import 'dart:html' as html;
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:ui/ui.dart' as ui;
|
||||
|
||||
/// How far is the light source from the surface of the UI.
|
||||
///
|
||||
|
||||
@@ -2,7 +2,12 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
part of engine;
|
||||
import 'dart:async';
|
||||
import 'dart:html' as html;
|
||||
|
||||
import 'package:ui/ui.dart' as ui;
|
||||
|
||||
import 'navigation/url_strategy.dart';
|
||||
|
||||
const bool _debugLogHistoryActions = false;
|
||||
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
part of engine;
|
||||
import 'dart:math' as math;
|
||||
import 'dart:typed_data';
|
||||
|
||||
// This is a small library to handle stability for floating point operations.
|
||||
//
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
part of engine;
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:ui/ui.dart' as ui;
|
||||
|
||||
bool rectIsValid(ui.Rect rect) {
|
||||
assert(rect != null, 'Rect argument was null.'); // ignore: unnecessary_null_comparison
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
part of engine;
|
||||
import 'dart:math' as math;
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:ui/src/engine.dart' show assertionsEnabled;
|
||||
|
||||
class Matrix4 {
|
||||
final Float32List _m4storage;
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
part of engine;
|
||||
import 'dart:js' as js;
|
||||
|
||||
import 'package:ui/src/engine.dart' show registerHotRestartListener;
|
||||
|
||||
/// A bag of all experiment flags in the web engine.
|
||||
///
|
||||
|
||||
@@ -8,7 +8,7 @@ import 'package:test/test.dart';
|
||||
import 'package:quiver/testing/async.dart';
|
||||
import 'package:quiver/time.dart';
|
||||
|
||||
import 'package:ui/src/engine.dart';
|
||||
import 'package:ui/src/engine/alarm_clock.dart';
|
||||
|
||||
void main() {
|
||||
internalBootstrapBrowserTest(() => testMain);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import 'package:test/bootstrap/browser.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:ui/src/engine.dart';
|
||||
import 'package:ui/src/engine/browser_detection.dart';
|
||||
|
||||
void main() {
|
||||
internalBootstrapBrowserTest(() => testMain);
|
||||
|
||||
@@ -10,7 +10,11 @@ import 'dart:html' as html;
|
||||
|
||||
import 'package:test/bootstrap/browser.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:ui/src/engine.dart';
|
||||
import 'package:ui/src/engine.dart' show window;
|
||||
import 'package:ui/src/engine/browser_detection.dart';
|
||||
import 'package:ui/src/engine/navigation.dart';
|
||||
import 'package:ui/src/engine/services.dart';
|
||||
import 'package:ui/src/engine/test_embedding.dart';
|
||||
|
||||
import '../spy.dart';
|
||||
|
||||
|
||||
@@ -9,7 +9,9 @@ import 'dart:js_util' as js_util;
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:test/bootstrap/browser.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:ui/src/engine.dart';
|
||||
import 'package:ui/src/engine.dart' show domRenderer, window;
|
||||
import 'package:ui/src/engine/browser_detection.dart';
|
||||
import 'package:ui/src/engine/pointer_binding.dart';
|
||||
import 'package:ui/ui.dart' as ui;
|
||||
|
||||
const int _kNoButtonChange = -1;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import 'dart:typed_data';
|
||||
import 'package:test/bootstrap/browser.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:ui/src/engine.dart';
|
||||
import 'package:ui/src/engine/ulps.dart';
|
||||
|
||||
void main() {
|
||||
internalBootstrapBrowserTest(() => testMain);
|
||||
|
||||
@@ -8,7 +8,7 @@ import 'dart:js_util' as js_util;
|
||||
|
||||
import 'package:test/bootstrap/browser.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:ui/src/engine.dart';
|
||||
import 'package:ui/src/engine/web_experiments.dart';
|
||||
|
||||
const bool _defaultUseCanvasText = true;
|
||||
const bool _defaultUseCanvasRichText = true;
|
||||
|
||||
@@ -17,78 +17,150 @@ final ArgParser argParser = ArgParser()
|
||||
..addMultiOption('input')
|
||||
..addOption('stamp');
|
||||
|
||||
const List<List<String>> uiPatterns = <List<String>>[
|
||||
<String>['library ui;', 'library dart.ui;'],
|
||||
<String>['part of ui;', 'part of dart.ui;'],
|
||||
<String>[
|
||||
r'''
|
||||
final List<Replacer> uiPatterns = <Replacer>[
|
||||
AllReplacer('library ui;', 'library dart.ui;'),
|
||||
AllReplacer('part of ui;', 'part of dart.ui;'),
|
||||
AllReplacer(r'''
|
||||
import 'src/engine.dart' as engine;
|
||||
''',
|
||||
r'''
|
||||
''', r'''
|
||||
import 'dart:_engine' as engine;
|
||||
'''
|
||||
],
|
||||
<String>[
|
||||
'''),
|
||||
AllReplacer(
|
||||
r'''
|
||||
export 'src/engine.dart'
|
||||
''',
|
||||
r'''
|
||||
export 'dart:_engine'
|
||||
''',
|
||||
],
|
||||
),
|
||||
];
|
||||
|
||||
const List<List<String>> enginePatterns = <List<String>>[
|
||||
<String>['library engine;', 'library dart._engine;'],
|
||||
<String>['part of engine;', 'part of dart._engine;'],
|
||||
<String>[
|
||||
r'''
|
||||
final List<Replacer> engineLibraryPatterns = <Replacer>[
|
||||
AllReplacer('library engine;', 'library dart._engine;'),
|
||||
AllReplacer(r'''
|
||||
import '../ui.dart' as ui;
|
||||
''',
|
||||
r'''
|
||||
''', r'''
|
||||
import 'dart:ui' as ui;
|
||||
'''
|
||||
],
|
||||
<String>[
|
||||
'''),
|
||||
AllReplacer(r'''
|
||||
import 'package:ui/ui.dart' as ui;
|
||||
''', r'''
|
||||
import 'dart:ui' as ui;
|
||||
'''),
|
||||
// Remove imports of engine part files.
|
||||
AllReplacer(RegExp(r"import 'engine/.*';"), ''),
|
||||
// Replace exports of engine files with "part" directives.
|
||||
MappedReplacer(RegExp(r'''
|
||||
export 'engine/(.*)';
|
||||
'''), (Match match) => '''
|
||||
part 'engine/${match.group(1)}';
|
||||
'''),
|
||||
AllReplacer(
|
||||
'import \'package:js/js.dart\'',
|
||||
'import \'dart:_js_annotations\'',
|
||||
],
|
||||
),
|
||||
];
|
||||
|
||||
const List<List<String>> sharedPatterns = <List<String>>[
|
||||
<String>["import 'package:meta/meta.dart';", ''],
|
||||
<String>['@required', ''],
|
||||
<String>['@protected', ''],
|
||||
<String>['@mustCallSuper', ''],
|
||||
<String>['@immutable', ''],
|
||||
<String>['@visibleForTesting', '']
|
||||
final List<Replacer> enginePartsPatterns = <Replacer>[
|
||||
AllReplacer('part of engine;', 'part of dart._engine;'),
|
||||
// Remove library-level JS annotations.
|
||||
AllReplacer(RegExp(r'\n@JS(.*)\nlibrary .+;'), ''),
|
||||
// Remove library directives.
|
||||
AllReplacer(RegExp(r'\nlibrary .+;'), ''),
|
||||
// Remove imports/exports from all engine parts.
|
||||
AllReplacer(RegExp(r'import .*'), ''),
|
||||
AllReplacer(RegExp(r'export .*'), ''),
|
||||
];
|
||||
|
||||
final List<Replacer> sharedPatterns = <Replacer>[
|
||||
AllReplacer("import 'package:meta/meta.dart';", ''),
|
||||
AllReplacer('@required', ''),
|
||||
AllReplacer('@protected', ''),
|
||||
AllReplacer('@mustCallSuper', ''),
|
||||
AllReplacer('@immutable', ''),
|
||||
AllReplacer('@visibleForTesting', ''),
|
||||
];
|
||||
|
||||
// Rewrites the "package"-style web ui library into a dart:ui implementation.
|
||||
// So far this only requires a replace of the library declarations.
|
||||
void main(List<String> arguments) {
|
||||
final ArgResults results = argParser.parse(arguments);
|
||||
final Directory directory = Directory(results['output-dir']);
|
||||
final String inputDirectoryPath = results['input-dir'];
|
||||
for (String inputFilePath in results['input']) {
|
||||
final Directory directory = Directory(results['output-dir'] as String);
|
||||
final String inputDirectoryPath = results['input-dir'] as String;
|
||||
for (final String inputFilePath in results['input'] as Iterable<String>) {
|
||||
final File inputFile = File(inputFilePath);
|
||||
final File outputFile = File(path.join(
|
||||
directory.path, inputFile.path.substring(inputDirectoryPath.length)))
|
||||
..createSync(recursive: true);
|
||||
String source = inputFile.readAsStringSync();
|
||||
final List<List<String>> replacementPatterns = <List<String>>[];
|
||||
final List<Replacer> replacementPatterns = <Replacer>[];
|
||||
replacementPatterns.addAll(sharedPatterns);
|
||||
if (results['ui']) {
|
||||
if (results['ui'] as bool) {
|
||||
replacementPatterns.addAll(uiPatterns);
|
||||
} else if (results['engine']) {
|
||||
replacementPatterns.addAll(enginePatterns);
|
||||
} else if (results['engine'] as bool) {
|
||||
if (inputFilePath.endsWith('lib/src/engine.dart')) {
|
||||
replacementPatterns.addAll(engineLibraryPatterns);
|
||||
} else {
|
||||
source = _preprocessEnginePartFile(source);
|
||||
replacementPatterns.addAll(enginePartsPatterns);
|
||||
}
|
||||
}
|
||||
for (List<String> patterns in replacementPatterns) {
|
||||
source = source.replaceAll(patterns.first, patterns.last);
|
||||
for (final Replacer replacer in replacementPatterns) {
|
||||
source = replacer.perform(source);
|
||||
}
|
||||
outputFile.writeAsStringSync(source);
|
||||
if (results['stamp'] != null) {
|
||||
File(results['stamp']).writeAsStringSync("stamp");
|
||||
File(results['stamp'] as String).writeAsStringSync('stamp');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String _preprocessEnginePartFile(String source) {
|
||||
if (source.contains('\npart of engine;')) {
|
||||
// The file hasn't been migrated yet.
|
||||
// Do nothing.
|
||||
} else {
|
||||
// Insert the part directive at the beginning of the file.
|
||||
source = 'part of engine;\n' + source;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
/// Responsible for performing string replacements.
|
||||
abstract class Replacer {
|
||||
/// Performs the replacement in the provided [text].
|
||||
String perform(String text);
|
||||
}
|
||||
|
||||
/// Replaces all occurrences of a pattern with a fixed string.
|
||||
class AllReplacer implements Replacer {
|
||||
/// Creates a new tuple with the given [pattern] and [replacement] string.
|
||||
AllReplacer(this._pattern, this._replacement);
|
||||
|
||||
/// The pattern to be replaced.
|
||||
final Pattern _pattern;
|
||||
|
||||
/// The replacement string.
|
||||
final String _replacement;
|
||||
|
||||
@override
|
||||
String perform(String text) {
|
||||
return text.replaceAll(_pattern, _replacement);
|
||||
}
|
||||
}
|
||||
|
||||
/// Uses a callback to replace each occurrence of a pattern.
|
||||
class MappedReplacer implements Replacer {
|
||||
MappedReplacer(this._pattern, this._replace);
|
||||
|
||||
/// The pattern to be replaced.
|
||||
final RegExp _pattern;
|
||||
|
||||
/// A callback to replace each occurrence of [_pattern].
|
||||
final String Function(Match match) _replace;
|
||||
|
||||
@override
|
||||
String perform(String text) {
|
||||
return text.replaceAllMapped(_pattern, _replace);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user