From 85135ddad047d82aa5025496410a41b031c4c5df Mon Sep 17 00:00:00 2001 From: gaaclarke <30870216+gaaclarke@users.noreply.github.com> Date: Fri, 23 Oct 2020 13:37:43 -0700 Subject: [PATCH] [pigeon] fixed windows across multiple drives (#233) --- packages/pigeon/CHANGELOG.md | 4 ++++ packages/pigeon/bin/pigeon.dart | 25 ++++++++++++++++-------- packages/pigeon/lib/generator_tools.dart | 2 +- packages/pigeon/pubspec.yaml | 2 +- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index a930b26209..be7e72ccaf 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.14 + +* [Windows] Fixed executing from drives other than C:. + ## 0.1.13 * Fixed execution on Windows with certain setups where Dart didn't allow diff --git a/packages/pigeon/bin/pigeon.dart b/packages/pigeon/bin/pigeon.dart index 8c1742dedf..9dfb67f69f 100644 --- a/packages/pigeon/bin/pigeon.dart +++ b/packages/pigeon/bin/pigeon.dart @@ -9,20 +9,29 @@ import 'dart:isolate'; import 'package:path/path.dart' as path; import 'package:pigeon/pigeon_lib.dart'; +/// This creates a relative path from `from` to `input`, the output being a +/// posix path on all platforms. +String _posixRelative(String input, {String from}) { + final path.Context context = path.Context(style: path.Style.posix); + final String rawInputPath = input; + final String absInputPath = File(rawInputPath).absolute.path; + // By going through URI's we can make sure paths can go between drives in + // Windows. + final Uri inputUri = path.toUri(absInputPath); + final String posixAbsInputPath = context.fromUri(inputUri); + final Uri tempUri = path.toUri(from); + final String posixTempPath = context.fromUri(tempUri); + return context.relative(posixAbsInputPath, from: posixTempPath); +} + Future main(List args) async { final PigeonOptions opts = Pigeon.parseArgs(args); final Directory tempDir = Directory.systemTemp.createTempSync(); String importLine = ''; if (opts.input != null) { - final String rawInputPath = opts.input; - final String absInputPath = File(rawInputPath).absolute.path; - final String relInputPath = path.relative(absInputPath, from: tempDir.path); - - final List relInputComponents = path.split(relInputPath); - final path.Context context = path.Context(style: path.Style.posix); - final String posixRelInputPath = context.joinAll(relInputComponents); - importLine = 'import \'$posixRelInputPath\';\n'; + final String relInputPath = _posixRelative(opts.input, from: tempDir.path); + importLine = 'import \'$relInputPath\';\n'; } final String code = """$importLine import 'dart:io'; diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index f7d2b5b14d..4f099c93b1 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -8,7 +8,7 @@ import 'dart:mirrors'; import 'ast.dart'; /// The current version of pigeon. -const String pigeonVersion = '0.1.13'; +const String pigeonVersion = '0.1.14'; /// Read all the content from [stdin] to a String. String readStdin() { diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index bab62fc86d..af89b16f4a 100644 --- a/packages/pigeon/pubspec.yaml +++ b/packages/pigeon/pubspec.yaml @@ -1,5 +1,5 @@ name: pigeon -version: 0.1.13 +version: 0.1.14 description: Code generator tool to make communication between Flutter and the host platform type-safe and easier. homepage: https://github.com/flutter/packages/tree/master/packages/pigeon dependencies: