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

Side by Side Diff: pkg/analyzer/lib/src/command_line/arguments.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 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.src.command_line.arguments; 5 library analyzer.src.command_line.arguments;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/file_system/file_system.dart'; 9 import 'package:analyzer/file_system/file_system.dart';
10 import 'package:analyzer/src/context/builder.dart'; 10 import 'package:analyzer/src/context/builder.dart';
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 ArgResults parse( 220 ArgResults parse(
221 ResourceProvider provider, ArgParser parser, List<String> args) { 221 ResourceProvider provider, ArgParser parser, List<String> args) {
222 args = preprocessArgs(provider, args); 222 args = preprocessArgs(provider, args);
223 if (args.contains('--$ignoreUnrecognizedFlagsFlag')) { 223 if (args.contains('--$ignoreUnrecognizedFlagsFlag')) {
224 args = filterUnknownArguments(args, parser); 224 args = filterUnknownArguments(args, parser);
225 } 225 }
226 return parser.parse(args); 226 return parser.parse(args);
227 } 227 }
228 228
229 /** 229 /**
230 * Preprocess the given list of command line [args] by checking whether the real 230 * Preprocess the given list of command line [args].
231 * arguments are in a file (Bazel worker mode). 231 * If the final arg is `@file_path` (Bazel worker mode),
232 * then read in all the lines of that file and add those as args.
233 * Always returns a new modifiable list.
232 */ 234 */
233 List<String> preprocessArgs(ResourceProvider provider, List<String> args) { 235 List<String> preprocessArgs(ResourceProvider provider, List<String> args) {
236 args = new List.from(args);
Brian Wilkerson 2016/12/13 18:48:20 Is there a reason for creating a copy of the args
danrubel 2016/12/13 18:50:08 Yes. DDC expects that.
Brian Wilkerson 2016/12/13 19:02:16 I was looking for an answer to the question of "wh
danrubel 2016/12/13 19:09:13 Yes, they modify it :-) I can revert this code ch
vsm 2016/12/13 19:14:33 Either is fine by me.
Brian Wilkerson 2016/12/13 19:18:33 Modifying the list seems strange, but given that,
234 if (args.isEmpty) { 237 if (args.isEmpty) {
235 return args; 238 return args;
236 } 239 }
237 String lastArg = args.last; 240 String lastArg = args.last;
238 if (lastArg.startsWith('@')) { 241 if (lastArg.startsWith('@')) {
239 File argsFile = provider.getFile(lastArg.substring(1)); 242 File argsFile = provider.getFile(lastArg.substring(1));
240 try { 243 try {
241 List<String> newArgs = args.sublist(0, args.length - 1).toList(); 244 args.removeLast();
242 newArgs.addAll(argsFile 245 args.addAll(argsFile
243 .readAsStringSync() 246 .readAsStringSync()
244 .replaceAll('\r\n', '\n') 247 .replaceAll('\r\n', '\n')
245 .replaceAll('\r', '\n') 248 .replaceAll('\r', '\n')
246 .split('\n') 249 .split('\n')
247 .where((String line) => line.isNotEmpty)); 250 .where((String line) => line.isNotEmpty));
248 return newArgs; 251 } on FileSystemException catch (e) {
249 } on FileSystemException { 252 throw new Exception('Failed to read file specified by $lastArg : $e');
Brian Wilkerson 2016/12/13 19:02:16 Also, it isn't clear to me that it helps to wrap t
danrubel 2016/12/13 19:09:13 I wanted it to be clear that the @filePath was the
Brian Wilkerson 2016/12/13 19:18:33 Ah. Makes sense.
250 // Don't modify args if the file does not exist or cannot be read.
251 } 253 }
252 } 254 }
253 return args; 255 return args;
254 } 256 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/command_line/arguments_test.dart » ('j') | pkg/analyzer_cli/lib/src/options.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698