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

Side by Side Diff: pkg/front_end/lib/src/codegen/tools.dart

Issue 3002713002: Fix logic for locating dartfmt (Closed)
Patch Set: Created 3 years, 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 import 'dart:io'; 5 import 'dart:io';
6 6
7 import 'package:path/path.dart'; 7 import 'package:path/path.dart';
8 8
9 /** 9 /**
10 * Type of functions used to compute the contents of a set of generated files. 10 * Type of functions used to compute the contents of a set of generated files.
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 File output(String pkgPath) => 231 File output(String pkgPath) =>
232 new File(join(pkgPath, joinAll(posix.split(outputPath)))); 232 new File(join(pkgPath, joinAll(posix.split(outputPath))));
233 } 233 }
234 234
235 /** 235 /**
236 * A utility class for invoking dartfmt. 236 * A utility class for invoking dartfmt.
237 */ 237 */
238 class DartFormat { 238 class DartFormat {
239 static String get _dartfmtPath { 239 static String get _dartfmtPath {
240 String binName = Platform.isWindows ? 'dartfmt.bat' : 'dartfmt'; 240 String binName = Platform.isWindows ? 'dartfmt.bat' : 'dartfmt';
241 return join(dirname(Platform.resolvedExecutable), binName); 241 for (var loc in [binName, join('dart-sdk', 'bin', binName)]) {
242 var candidatePath = join(dirname(Platform.resolvedExecutable), loc);
243 if (new File(candidatePath).existsSync()) {
244 return candidatePath;
245 }
246 }
247 throw new StateError('Could not find dartfmt executable');
242 } 248 }
243 249
244 static void formatFile(File file) { 250 static void formatFile(File file) {
245 ProcessResult result = Process.runSync(_dartfmtPath, ['-w', file.path]); 251 ProcessResult result = Process.runSync(_dartfmtPath, ['-w', file.path]);
246 if (result.exitCode != 0) throw result.stderr; 252 if (result.exitCode != 0) throw result.stderr;
247 } 253 }
248 254
249 static String formatText(String text) { 255 static String formatText(String text) {
250 File file = new File(join(Directory.systemTemp.path, 'gen.dart')); 256 File file = new File(join(Directory.systemTemp.path, 'gen.dart'));
251 file.writeAsStringSync(text); 257 file.writeAsStringSync(text);
252 ProcessResult result = Process.runSync(_dartfmtPath, ['-w', file.path]); 258 ProcessResult result = Process.runSync(_dartfmtPath, ['-w', file.path]);
253 if (result.exitCode != 0) throw result.stderr; 259 if (result.exitCode != 0) throw result.stderr;
254 return file.readAsStringSync(); 260 return file.readAsStringSync();
255 } 261 }
256 } 262 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698