Skip to content
This repository has been archived by the owner on Dec 9, 2023. It is now read-only.

Make LocalProcessManager portable #3

Merged
merged 1 commit into from
Feb 11, 2017
Merged

Conversation

goderbauer
Copy link
Member

LocalProcessManager now uses the same algorithm on Windows and Posix systems to find the executable for a command.

Previously, manager.run(['pub']) would work on Linux, but not on Windows because pub.bat could not be located.

@@ -15,6 +16,7 @@ import 'utils.dart';

void main() {
FileSystem fs = new LocalFileSystem();
String newline = Platform.isWindows ? '\r\n' : '\n';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, I just created dart-lang/platform#1 -- maybe add a comment referencing it here so that when it's implemented, we can switch to use it here.

///
/// Return `null` if the executable cannot be found.
@visibleForTesting
String getExecutablePath(String commandName, String workingDirectory,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put in a separate common.dart that's not exported by the library -- so the test can still import it under lib/src, but package users don't get it by accident.

/// Return `null` if the executable cannot be found.
@visibleForTesting
String getExecutablePath(String commandName, String workingDirectory,
{bool isWindows, List<String> path, List<String> pathExt}) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than bool isWindows, make it Platform platform from package:platform (rather than dart:io's native Platform)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a beautiful abstraction. So much nicer!

{bool isWindows, List<String> path, List<String> pathExt}) {
workingDirectory ??= Directory.current.path;
isWindows ??= Platform.isWindows;
String pathSeparator = isWindows ? ';' : ':';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another TODO to refactor once the API is available: dart-lang/platform#2

Iterable<String> _getCandidatePaths(
String commandName, List<String> searchPaths, List<String> extensions) {
List<String> withExtensions = extensions.isNotEmpty
? extensions.map((String ext) => '$commandName$ext').toList()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you ever want to include the version without the extension as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That wouldn't work in Windows. In flutter, we do have bin/flutter and bin/flutter.bat, but only the later is executable on Windows. As far as I can tell, windows doesn't have a concept of executables without extensions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

@@ -48,7 +50,13 @@ class Manifest {
List<Map<String, dynamic>> decoded = new JsonDecoder().convert(json);
Manifest manifest = new Manifest();
decoded.forEach((Map<String, dynamic> entry) {
manifest._entries.add(new ManifestEntry.fromJson(entry));
if (entry['type'] == 'run') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch (entry['type']) { ... }

@goderbauer goderbauer force-pushed the addCanRun branch 2 times, most recently from 04f5f5d to bb1cbc8 Compare February 10, 2017 23:06
@@ -0,0 +1,56 @@
import 'dart:io';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs license header

@tvolkert
Copy link
Contributor

Update CHANGELOG.md to start a 1.0.2 section please. Other than that and making sure that the license header is on the new files, LGTM.

@goderbauer goderbauer force-pushed the addCanRun branch 2 times, most recently from 9bb2f57 to 84641b6 Compare February 11, 2017 00:23
LocalProcessManager now uses the same algorithm on Windows and Posix systems to find the executable for a command.

Previously, manager.run(['pub']) would work on Linux, but not on Windows because 'pub.bat' could not be located.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants