Skip to content

Commit c67d352

Browse files
authored
Allow pub get execution on Windows platforms (#240)
1 parent e9b8af3 commit c67d352

File tree

2 files changed

+47
-7
lines changed

2 files changed

+47
-7
lines changed

packages/custom_lint/lib/src/workspace.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ String _buildDependencyConstraint(
114114
case HostedDependency():
115115
return ' ${sharedConstraint.getDisplayString()}';
116116
case PathDependency():
117-
return '\n path: "${sharedConstraint.path}"';
117+
// Use appropriate path separators across platforms
118+
final path = posix.prettyUri(sharedConstraint.path);
119+
return '\n path: "$path"';
118120
case SdkDependency():
119121
return '\n sdk: ${sharedConstraint.sdk}';
120122
case GitDependency():
@@ -391,6 +393,10 @@ typedef RunProcess = Future<ProcessResult> Function(
391393
@visibleForTesting
392394
RunProcess runProcess = Process.run;
393395

396+
/// Allow mocking of the platform for tests.
397+
@visibleForTesting
398+
bool platformIsWindows = Platform.isWindows;
399+
394400
/// An error thrown when [CustomLintPlugin._visitSelfAndTransitiveDependencies] tries to iterate over
395401
/// the dependencies of a package, but the package cannot be found in
396402
/// the `package_config.json`.
@@ -836,6 +842,7 @@ publish_to: 'none'
836842
stdoutEncoding: utf8,
837843
stderrEncoding: utf8,
838844
workingDirectory: tempDir.path,
845+
runInShell: platformIsWindows,
839846
);
840847
if (result.exitCode != 0) {
841848
throw Exception(

packages/custom_lint/test/src/workspace_test.dart

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ void mockProcess(RunProcess mock) {
9393
runProcess = mock;
9494
}
9595

96-
Queue<({String executable, List<String> args})> spyProcess() {
97-
final result = Queue<({String executable, List<String> args})>();
96+
Queue<({String executable, List<String> args, bool runInShell})> spyProcess() {
97+
final result =
98+
Queue<({String executable, List<String> args, bool runInShell})>();
9899

99100
final previousRunProcess = runProcess;
100101
addTearDown(() => runProcess = previousRunProcess);
@@ -108,7 +109,8 @@ Queue<({String executable, List<String> args})> spyProcess() {
108109
stdoutEncoding,
109110
workingDirectory,
110111
}) {
111-
result.add((executable: executable, args: arguments));
112+
result
113+
.add((executable: executable, args: arguments, runInShell: runInShell));
112114

113115
return previousRunProcess(
114116
executable,
@@ -813,12 +815,12 @@ environment:
813815
814816
dev_dependencies:
815817
plugin1:
816-
path: "${workingDir.dir('plugin1').path}"
818+
path: "${p.posix.prettyUri(workingDir.dir('plugin1').path)}"
817819
''');
818820
expect(tempDir.pubspecOverrides.readAsStringSync(), '''
819821
dependency_overrides:
820822
plugin1:
821-
path: "${workingDir.dir('plugin1').path}"
823+
path: "${p.posix.prettyUri(workingDir.dir('plugin1').path)}"
822824
''');
823825
});
824826

@@ -1110,6 +1112,37 @@ dependency_overrides:
11101112
);
11111113
expect(processes, isEmpty);
11121114
});
1115+
1116+
test('only spawns a shell when running in Windows', () async {
1117+
final workingDir = await createSimpleWorkspace([
1118+
'custom_lint_builder',
1119+
Pubspec(
1120+
'plugin1',
1121+
environment: {'sdk': VersionConstraint.parse('^3.0.0')},
1122+
dependencies: {'custom_lint_builder': HostedDependency()},
1123+
),
1124+
Pubspec(
1125+
'a',
1126+
environment: {'sdk': VersionConstraint.parse('^3.0.0')},
1127+
devDependencies: {'plugin1': PathDependency('../plugin1')},
1128+
),
1129+
]);
1130+
1131+
final workspace = await fromContextRootsFromPaths(
1132+
['a'],
1133+
workingDirectory: workingDir,
1134+
);
1135+
1136+
final processes = spyProcess();
1137+
1138+
platformIsWindows = true;
1139+
await workspace.runPubGet(workingDir.dir('a'));
1140+
expect(processes.last.runInShell, true);
1141+
1142+
platformIsWindows = false;
1143+
await workspace.runPubGet(workingDir.dir('a'));
1144+
expect(processes.last.runInShell, false);
1145+
});
11131146
});
11141147

11151148
group('isUsingFlutter', () {
@@ -1718,7 +1751,7 @@ publish_to: 'none'
17181751
17191752
dev_dependencies:
17201753
plugin1:
1721-
path: "${workingDir.dir('plugin1').path}"
1754+
path: "${p.posix.prettyUri(workingDir.dir('plugin1').path)}"
17221755
''');
17231756
});
17241757

0 commit comments

Comments
 (0)