[pigeon] fixed windows across multiple drives (#233)

This commit is contained in:
gaaclarke
2020-10-23 13:37:43 -07:00
committed by GitHub
parent 4e89dd0b12
commit 85135ddad0
4 changed files with 23 additions and 10 deletions

View File

@ -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

View File

@ -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<void> main(List<String> 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<String> 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';

View File

@ -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() {

View File

@ -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: