Skip to content

Commit

Permalink
Use .bat for executables on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
evanweible-wf committed Aug 26, 2022
1 parent 24b981d commit 720be36
Show file tree
Hide file tree
Showing 17 changed files with 75 additions and 51 deletions.
4 changes: 2 additions & 2 deletions lib/src/executable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'utils/cached_pubspec.dart';
import 'utils/dart_dev_paths.dart';
import 'utils/dart_tool_cache.dart';
import 'utils/ensure_process_exit.dart';
import 'utils/executables.dart' as exe;
import 'utils/format_tool_builder.dart';
import 'utils/get_dart_version_comment.dart';
import 'utils/logging.dart';
Expand Down Expand Up @@ -51,8 +52,7 @@ Future<void> run(List<String> args) async {
}

generateRunScript();
final process = await Process.start(
Platform.executable, [paths.runScript, ...args],
final process = await Process.start(exe.dart, [paths.runScript, ...args],
mode: ProcessStartMode.inheritStdio);
ensureProcessExit(process);
exitCode = await process.exitCode;
Expand Down
3 changes: 2 additions & 1 deletion lib/src/tools/analyze_tool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:logging/logging.dart';
import '../dart_dev_tool.dart';
import '../utils/arg_results_utils.dart';
import '../utils/assert_no_positional_args_nor_args_after_separator.dart';
import '../utils/executables.dart' as exe;
import '../utils/logging.dart';
import '../utils/process_declaration.dart';
import '../utils/run_process_and_ensure_exit.dart';
Expand Down Expand Up @@ -176,7 +177,7 @@ ProcessDeclaration buildProcess(
'Arguments can be passed to the "${analyzerUsed}" process via '
'the --analyzer-args option.');
}
final executable = useDartAnalyze ? 'dart' : 'dartanalyzer';
var executable = useDartAnalyze ? exe.dart : exe.dartanalyzer;
final args = buildArgs(
argResults: context.argResults,
configuredAnalyzerArgs: configuredAnalyzerArgs,
Expand Down
7 changes: 4 additions & 3 deletions lib/src/tools/format_tool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import '../../utils.dart';
import '../dart_dev_tool.dart';
import '../utils/arg_results_utils.dart';
import '../utils/assert_no_positional_args_nor_args_after_separator.dart';
import '../utils/executables.dart' as exe;
import '../utils/logging.dart';
import '../utils/organize_directives/organize_directives_in_paths.dart';
import '../utils/package_is_immediate_dependency.dart';
Expand Down Expand Up @@ -586,12 +587,12 @@ FormatExecution buildExecution(
ProcessDeclaration buildFormatProcess([Formatter formatter]) {
switch (formatter) {
case Formatter.dartStyle:
return ProcessDeclaration('dart', ['run', 'dart_style:format']);
return ProcessDeclaration(exe.dart, ['run', 'dart_style:format']);
case Formatter.dartFormat:
return ProcessDeclaration('dart', ['format']);
return ProcessDeclaration(exe.dart, ['format']);
case Formatter.dartfmt:
default:
return ProcessDeclaration('dartfmt', []);
return ProcessDeclaration(exe.dartfmt, []);
}
}

Expand Down
5 changes: 3 additions & 2 deletions lib/src/tools/over_react_format_tool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import 'dart:io';
import 'package:dart_dev/dart_dev.dart';
import 'package:dart_dev/utils.dart';

import '../tools/format_tool.dart';
import '../utils/executables.dart' as exe;
import 'format_tool.dart';

class OverReactFormatTool extends DevTool {
/// Wrap lines longer than this.
Expand All @@ -31,7 +32,7 @@ class OverReactFormatTool extends DevTool {
'over_react_format',
if (lineLength != null) '--line-length=$lineLength'
];
final process = ProcessDeclaration('dart', [...args, ...paths],
final process = ProcessDeclaration(exe.dart, [...args, ...paths],
mode: ProcessStartMode.inheritStdio);
logCommand('dart', paths, args, verbose: context?.verbose);
return runProcessAndEnsureExit(process);
Expand Down
3 changes: 2 additions & 1 deletion lib/src/tools/test_tool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:logging/logging.dart';

import '../dart_dev_tool.dart';
import '../utils/arg_results_utils.dart';
import '../utils/executables.dart' as exe;
import '../utils/logging.dart';
import '../utils/package_is_immediate_dependency.dart';
import '../utils/process_declaration.dart';
Expand Down Expand Up @@ -315,7 +316,7 @@ TestExecution buildExecution(
verbose: context.verbose);
logSubprocessHeader(_log, 'dart ${args.join(' ')}'.trim());
return TestExecution.process(
ProcessDeclaration('dart', args, mode: ProcessStartMode.inheritStdio));
ProcessDeclaration(exe.dart, args, mode: ProcessStartMode.inheritStdio));
}

// NOTE: This currently depends on https://github.com/dart-lang/build/pull/2445
Expand Down
3 changes: 2 additions & 1 deletion lib/src/tools/tuneup_check_tool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:logging/logging.dart';
import '../dart_dev_tool.dart';
import '../utils/arg_results_utils.dart';
import '../utils/assert_no_positional_args_nor_args_after_separator.dart';
import '../utils/executables.dart' as exe;
import '../utils/logging.dart';
import '../utils/package_is_immediate_dependency.dart';
import '../utils/process_declaration.dart';
Expand Down Expand Up @@ -152,5 +153,5 @@ TuneupExecution buildExecution(
verbose: context.verbose);
logSubprocessHeader(_log, 'dart ${args.join(' ')}');
return TuneupExecution.process(
ProcessDeclaration('dart', args, mode: ProcessStartMode.inheritStdio));
ProcessDeclaration(exe.dart, args, mode: ProcessStartMode.inheritStdio));
}
3 changes: 2 additions & 1 deletion lib/src/tools/webdev_serve_tool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:pub_semver/pub_semver.dart';
import '../dart_dev_tool.dart';
import '../utils/arg_results_utils.dart';
import '../utils/assert_no_positional_args_nor_args_after_separator.dart';
import '../utils/executables.dart' as exe;
import '../utils/global_package_is_active_and_compatible.dart';
import '../utils/logging.dart';
import '../utils/process_declaration.dart';
Expand Down Expand Up @@ -227,5 +228,5 @@ WebdevServeExecution buildExecution(
verbose: context.verbose);
logSubprocessHeader(_log, 'dart ${args.join(' ')}'.trim());
return WebdevServeExecution.process(
ProcessDeclaration('dart', args, mode: ProcessStartMode.inheritStdio));
ProcessDeclaration(exe.dart, args, mode: ProcessStartMode.inheritStdio));
}
7 changes: 7 additions & 0 deletions lib/src/utils/executables.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import 'dart:io';

final dart = 'dart';

final dartanalyzer = Platform.isWindows ? 'dartanalyzer.bat' : 'dartanalyzer';

final dartfmt = Platform.isWindows ? 'dartfmt.bat' : 'dartfmt';
7 changes: 4 additions & 3 deletions lib/src/utils/global_package_is_active_and_compatible.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'dart:io';

import 'package:pub_semver/pub_semver.dart';

import 'executables.dart' as exe;

/// Returns `true` if [packageName] is globally activated at a version
/// allowed by [constraint]. Returns `false` otherwise.
///
Expand All @@ -16,13 +18,12 @@ import 'package:pub_semver/pub_semver.dart';
bool globalPackageIsActiveAndCompatible(
String packageName, VersionConstraint constraint,
{Map<String, String> environment}) {
final executable = 'dart';
final args = ['pub', 'global', 'list'];
final result = Process.runSync(executable, args,
final result = Process.runSync(exe.dart, args,
environment: environment, stderrEncoding: utf8, stdoutEncoding: utf8);
if (result.exitCode != 0) {
throw ProcessException(
executable,
exe.dart,
args,
'Could not list global pub packages:\n${result.stderr}',
result.exitCode);
Expand Down
5 changes: 3 additions & 2 deletions test/functional.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';
import 'dart:io';

import 'package:dart_dev/src/utils/executables.dart' as exe;
import 'package:path/path.dart' as p;
import 'package:test_descriptor/test_descriptor.dart' as d;
import 'package:test_process/test_process.dart';
Expand Down Expand Up @@ -44,7 +45,7 @@ Future<TestProcess> runDevToolFunctionalTest(
});
pubspec.writeAsStringSync(updated);

final result = Process.runSync('dart', ['pub', 'get'],
final result = Process.runSync(exe.dart, ['pub', 'get'],
workingDirectory: pubspec.parent.path);
if (result.exitCode != 0) {
final origPath = p.join(p.relative(templateDir.absolute.path),
Expand All @@ -56,5 +57,5 @@ Future<TestProcess> runDevToolFunctionalTest(
}

final allArgs = <String>['run', 'dart_dev', command, ...?args];
return TestProcess.start('dart', allArgs, workingDirectory: d.sandbox);
return TestProcess.start(exe.dart, allArgs, workingDirectory: d.sandbox);
}
5 changes: 3 additions & 2 deletions test/functional/documentation_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ library test.functional.documentation_test;

import 'dart:io';

import 'package:dart_dev/src/utils/executables.dart' as exe;
import 'package:glob/glob.dart';
import 'package:glob/list_local_fs.dart';
import 'package:path/path.dart' as p;
Expand All @@ -28,13 +29,13 @@ void main() {
d.file('pubspec.yaml', pubspecSource),
]).create();

final pubGet = await TestProcess.start('dart', ['pub', 'get'],
final pubGet = await TestProcess.start(exe.dart, ['pub', 'get'],
workingDirectory: '${d.sandbox}/project');
printOnFailure('PUBSPEC:\n$pubspecSource\n');
await pubGet.shouldExit(0);

final analysis = await TestProcess.start(
'dart', ['analyze', '--fatal-infos'],
exe.dart, ['analyze', '--fatal-infos'],
workingDirectory: '${d.sandbox}/project');
printOnFailure('SOURCE:\n${dartBlock.source}\n');
await analysis.shouldExit(0);
Expand Down
13 changes: 8 additions & 5 deletions test/tools/analyze_tool_test.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
@TestOn('vm')
import 'dart:io';

import 'package:args/args.dart';
import 'package:args/command_runner.dart';
import 'package:dart_dev/src/dart_dev_tool.dart';
import 'package:dart_dev/src/tools/analyze_tool.dart';
import 'package:dart_dev/src/utils/executables.dart' as exe;
import 'package:glob/glob.dart';
import 'package:logging/logging.dart';
import 'package:test/test.dart';
Expand Down Expand Up @@ -120,14 +123,14 @@ void main() {
test('returns a ProcessDeclaration (default)', () {
final context = DevToolExecutionContext();
final process = buildProcess(context);
expect(process.executable, 'dartanalyzer');
expect(process.executable, exe.dartanalyzer);
expect(process.args, orderedEquals(['.']));
});

test('returns a ProcessDeclaration with useDartAnalyze (default)', () {
final context = DevToolExecutionContext();
final process = buildProcess(context, useDartAnalyze: true);
expect(process.executable, 'dart');
expect(process.executable, exe.dart);
expect(process.args, orderedEquals(['analyze', '.']));
});

Expand All @@ -140,7 +143,7 @@ void main() {
configuredAnalyzerArgs: ['--fatal-infos', '--fatal-warnings'],
include: [Glob('*.dart'), Glob('*.txt')],
path: globRoot);
expect(process.executable, 'dartanalyzer');
expect(process.executable, exe.dartanalyzer);
expect(
process.args,
orderedEquals([
Expand All @@ -163,7 +166,7 @@ void main() {
include: [Glob('*.dart')],
path: globRoot,
useDartAnalyze: true);
expect(process.executable, 'dart');
expect(process.executable, exe.dart);
expect(
process.args,
orderedEquals([
Expand All @@ -186,7 +189,7 @@ void main() {
configuredAnalyzerArgs: ['--fatal-infos', '--fatal-warnings'],
include: [Glob('*.dart'), Glob('*.txt')],
path: globRoot);
expect(process.executable, 'dartanalyzer');
expect(process.executable, exe.dartanalyzer);
expect(
process.args,
orderedEquals([
Expand Down
25 changes: 13 additions & 12 deletions test/tools/format_tool_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:args/args.dart';
import 'package:args/command_runner.dart';
import 'package:dart_dev/src/dart_dev_tool.dart';
import 'package:dart_dev/src/tools/format_tool.dart';
import 'package:dart_dev/src/utils/executables.dart' as exe;
import 'package:glob/glob.dart';
import 'package:io/io.dart';
import 'package:logging/logging.dart';
Expand Down Expand Up @@ -230,7 +231,7 @@ void main() {
argResults: argResults, commandName: 'hackFastFormat');
final execution = buildExecution(context);
expect(execution.exitCode, isNull);
expect(execution.formatProcess.executable, 'dartfmt');
expect(execution.formatProcess.executable, exe.dartfmt);
expect(execution.formatProcess.args, orderedEquals(['a/random/path']));
expect(execution.formatProcess.mode, ProcessStartMode.inheritStdio);
expect(execution.directiveOrganization, isNull);
Expand Down Expand Up @@ -333,7 +334,7 @@ void main() {
final context = DevToolExecutionContext();
final execution = buildExecution(context);
expect(execution.exitCode, isNull);
expect(execution.formatProcess.executable, 'dartfmt');
expect(execution.formatProcess.executable, exe.dartfmt);
expect(execution.formatProcess.args, orderedEquals(['.']));
expect(execution.formatProcess.mode, ProcessStartMode.inheritStdio);
expect(execution.directiveOrganization, isNull);
Expand All @@ -344,7 +345,7 @@ void main() {
final execution =
buildExecution(context, defaultMode: FormatMode.dryRun);
expect(execution.exitCode, isNull);
expect(execution.formatProcess.executable, 'dartfmt');
expect(execution.formatProcess.executable, exe.dartfmt);
expect(execution.formatProcess.args, orderedEquals(['-n', '.']));
expect(execution.formatProcess.mode, ProcessStartMode.inheritStdio);
expect(execution.directiveOrganization, isNull);
Expand All @@ -354,7 +355,7 @@ void main() {
final context = DevToolExecutionContext();
final execution = buildExecution(context, formatter: Formatter.dartfmt);
expect(execution.exitCode, isNull);
expect(execution.formatProcess.executable, 'dartfmt');
expect(execution.formatProcess.executable, exe.dartfmt);
expect(execution.formatProcess.args, orderedEquals(['.']));
expect(execution.formatProcess.mode, ProcessStartMode.inheritStdio);
expect(execution.directiveOrganization, isNull);
Expand All @@ -365,7 +366,7 @@ void main() {
final execution =
buildExecution(context, formatter: Formatter.dartFormat);
expect(execution.exitCode, isNull);
expect(execution.formatProcess.executable, 'dart');
expect(execution.formatProcess.executable, exe.dart);
expect(execution.formatProcess.args, orderedEquals(['format', '.']));
expect(execution.formatProcess.mode, ProcessStartMode.inheritStdio);
});
Expand All @@ -376,7 +377,7 @@ void main() {
formatter: Formatter.dartStyle,
path: 'test/tools/fixtures/format/has_dart_style');
expect(execution.exitCode, isNull);
expect(execution.formatProcess.executable, 'dart');
expect(execution.formatProcess.executable, exe.dart);
expect(execution.formatProcess.args,
orderedEquals(['run', 'dart_style:format', '.']));
expect(execution.formatProcess.mode, ProcessStartMode.inheritStdio);
Expand All @@ -392,7 +393,7 @@ void main() {
configuredFormatterArgs: ['--fix', '--follow-links'],
formatter: Formatter.dartfmt);
expect(execution.exitCode, isNull);
expect(execution.formatProcess.executable, 'dartfmt');
expect(execution.formatProcess.executable, exe.dartfmt);
expect(
execution.formatProcess.args,
orderedEquals(
Expand All @@ -409,7 +410,7 @@ void main() {
configuredFormatterArgs: ['--fix', '--follow-links'],
formatter: Formatter.dartFormat);
expect(execution.exitCode, isNull);
expect(execution.formatProcess.executable, 'dart');
expect(execution.formatProcess.executable, exe.dart);
expect(
execution.formatProcess.args,
orderedEquals(
Expand Down Expand Up @@ -461,25 +462,25 @@ void main() {
group('buildFormatProcess', () {
test('dartfmt', () {
final process = buildFormatProcess(Formatter.dartfmt);
expect(process.executable, 'dartfmt');
expect(process.executable, exe.dartfmt);
expect(process.args, isEmpty);
});

test('dart format', () {
final process = buildFormatProcess(Formatter.dartFormat);
expect(process.executable, 'dart');
expect(process.executable, exe.dart);
expect(process.args, orderedEquals(['format']));
});

test('dart_style', () {
final process = buildFormatProcess(Formatter.dartStyle);
expect(process.executable, 'dart');
expect(process.executable, exe.dart);
expect(process.args, orderedEquals(['run', 'dart_style:format']));
});

test('default', () {
final process = buildFormatProcess(Formatter.dartfmt);
expect(process.executable, 'dartfmt');
expect(process.executable, exe.dartfmt);
expect(process.args, isEmpty);
});
});
Expand Down
Loading

0 comments on commit 720be36

Please sign in to comment.