Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions packages/pigeon/bin/pigeon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 `input` to `from`, the output being a

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

from from to input no?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

good call

/// 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';
Expand Down