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

Side by Side Diff: pkg/dev_compiler/bin/dartdevc.dart

Issue 2572813002: update DDC and analyzer cli preprocessArgs (Closed)
Patch Set: remove unused import Created 4 years 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 unified diff | Download patch
OLDNEW
1 #!/usr/bin/env dart 1 #!/usr/bin/env dart
2 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 2 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
3 // for details. All rights reserved. Use of this source code is governed by a 3 // for details. All rights reserved. Use of this source code is governed by a
4 // BSD-style license that can be found in the LICENSE file. 4 // BSD-style license that can be found in the LICENSE file.
5 5
6 /// Command line entry point for Dart Development Compiler (dartdevc). 6 /// Command line entry point for Dart Development Compiler (dartdevc).
7 /// 7 ///
8 /// Supported commands are 8 /// Supported commands are
9 /// * compile: builds a collection of dart libraries into a single JS module 9 /// * compile: builds a collection of dart libraries into a single JS module
10 /// 10 ///
(...skipping 19 matching lines...) Expand all
30 /// file server, 30 /// file server,
31 /// * We didn't have a file watcher API at first, 31 /// * We didn't have a file watcher API at first,
32 /// * We had no conventions about where compiled output should go (or even 32 /// * We had no conventions about where compiled output should go (or even
33 /// that we would be compiling at all, vs running on an in-browser Dart VM), 33 /// that we would be compiling at all, vs running on an in-browser Dart VM),
34 /// * We wanted a good first impression with our simple examples, so we used 34 /// * We wanted a good first impression with our simple examples, so we used
35 /// local file servers, and users have an expectation of it now, even though 35 /// local file servers, and users have an expectation of it now, even though
36 /// it doesn't scale to typical apps that need their own real servers. 36 /// it doesn't scale to typical apps that need their own real servers.
37 37
38 import 'dart:async'; 38 import 'dart:async';
39 import 'dart:io'; 39 import 'dart:io';
40 import 'package:analyzer/file_system/physical_file_system.dart';
41 import 'package:analyzer/src/command_line/arguments.dart';
40 import 'package:analyzer/src/generated/engine.dart' show AnalysisEngine; 42 import 'package:analyzer/src/generated/engine.dart' show AnalysisEngine;
41 import 'package:bazel_worker/bazel_worker.dart'; 43 import 'package:bazel_worker/bazel_worker.dart';
42 import 'package:dev_compiler/src/compiler/command.dart'; 44 import 'package:dev_compiler/src/compiler/command.dart';
43 45
44 Future main(List<String> args) async { 46 Future main(List<String> args) async {
45 // Always returns a new modifiable list. 47 // Always returns a new modifiable list.
46 args = _preprocessArgs(args); 48 args = preprocessArgs(PhysicalResourceProvider.INSTANCE, args);
47 49
48 if (args.contains('--persistent_worker')) { 50 if (args.contains('--persistent_worker')) {
49 new _CompilerWorker(args..remove('--persistent_worker')).run(); 51 new _CompilerWorker(args..remove('--persistent_worker')).run();
50 } else { 52 } else {
51 exitCode = compile(args); 53 exitCode = compile(args);
52 } 54 }
53 } 55 }
54 56
55 /// Runs the compiler worker loop. 57 /// Runs the compiler worker loop.
56 class _CompilerWorker extends AsyncWorkerLoop { 58 class _CompilerWorker extends AsyncWorkerLoop {
57 /// The original args supplied to the executable. 59 /// The original args supplied to the executable.
58 final List<String> _startupArgs; 60 final List<String> _startupArgs;
59 61
60 _CompilerWorker(this._startupArgs) : super(); 62 _CompilerWorker(this._startupArgs) : super();
61 63
62 /// Performs each individual work request. 64 /// Performs each individual work request.
63 Future<WorkResponse> performRequest(WorkRequest request) async { 65 Future<WorkResponse> performRequest(WorkRequest request) async {
64 var args = _startupArgs.toList()..addAll(request.arguments); 66 var args = _startupArgs.toList()..addAll(request.arguments);
65 67
66 var output = new StringBuffer(); 68 var output = new StringBuffer();
67 var exitCode = compile(args, printFn: output.writeln); 69 var exitCode = compile(args, printFn: output.writeln);
68 AnalysisEngine.instance.clearCaches(); 70 AnalysisEngine.instance.clearCaches();
69 return new WorkResponse() 71 return new WorkResponse()
70 ..exitCode = exitCode 72 ..exitCode = exitCode
71 ..output = output.toString(); 73 ..output = output.toString();
72 } 74 }
73 } 75 }
74
75 /// Always returns a new modifiable list.
76 ///
77 /// If the final arg is `@file_path` then read in all the lines of that file
78 /// and add those as args.
79 ///
80 /// Bazel actions that support workers must provide all their per-WorkRequest
81 /// arguments in a file like this instead of as normal args.
82 List<String> _preprocessArgs(List<String> args) {
83 args = new List.from(args);
84 if (args.isNotEmpty && args.last.startsWith('@')) {
85 var fileArg = args.removeLast();
86 args.addAll(new File(fileArg.substring(1)).readAsLinesSync());
87 }
88 return args;
89 }
OLDNEW
« pkg/analyzer_cli/lib/src/options.dart ('K') | « pkg/analyzer_cli/lib/src/options.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698