Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
gen_debug_wrapper_main.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2#
3# Copyright 2013 The Flutter Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6import argparse
7import os
8import re
9import sys
10
11
12def main():
13 parser = argparse.ArgumentParser(
14 sys.argv[0], description="Generate main file for Fuchsia dart test"
15 )
16 parser.add_argument("--out", help="Path to .dart file to generate", required=True)
17 parser.add_argument("--main-dart", help="Path to main.dart file to import", required=True)
18 args = parser.parse_args()
19 out_dir = os.path.dirname(args.out)
20 assert os.path.isfile(os.path.join(os.path.dirname(args.out), args.main_dart))
21 outfile = open(args.out, 'w')
22
23 # Ignores relative lib imports due to a few modules that complain about
24 # this. It is also possible that a future may be unawaited given that main
25 # may not always be synchronous across all functions.
26 outfile.write('''// Generated by ''')
27 outfile.write(os.path.basename(__file__))
28 outfile.write(
29 '''
30
31
32// ignore_for_file: avoid_relative_lib_imports
33import 'dart:async';
34
35import 'package:flutter_driver/driver_extension.dart';
36'''
37 )
38 outfile.write("import '%s' as flutter_app_main;\n" % args.main_dart)
39 outfile.write(
40 '''
41void main() async {
42 assert(await (() async {
43 // TODO(awdavies): Use the logger instead.
44 print('Overriding app main method because flutter_driver_extendable '
45 'is enabled in the build file');
46
47 try {
48 // Enables Flutter Driver VM service extension
49 //
50 // This extension is required for tests that use package:flutter_driver
51 // to drive applications from a separate process.
52 enableFlutterDriverExtension();
53
54 // TODO(awdavies): Use the logger instead.
55 print('flutter driver extensions enabled.');
56 //ignore: avoid_catches_without_on_clauses
57 } catch (e) {
58 // TODO(awdavies): Use the logger instead.
59 // Noop.
60 print('flutter driver extensions not enabled. $e');
61 }
62 // Always return true so that the assert succeeds.
63 return true;
64 }()));
65 // Execute the main method of the app under test
66 var res = (flutter_app_main.main as dynamic)();
67 if (res != null && res is Future) {
68 await res;
69 }
70}
71'''
72 )
73 outfile.close()
74
75
76if __name__ == '__main__':
77 main()
Definition main.py:1