[Pigeon] Add the optional sdkPath parameter for specifying Dart SDK path (#434)

This commit is contained in:
zhenqiu1101
2021-08-13 13:01:44 -07:00
committed by GitHub
parent 5820fda0c7
commit c0b0bdd0e5
3 changed files with 16 additions and 7 deletions

View File

@ -9,6 +9,7 @@
* Fixed NPE in java generated code for nested types.
* Started supporting generics' type arguments for fields in classes.
* Generics (class fields and primitives)
* Added the optional sdkPath parameter for specifying Dart SDK path.
## 0.3.0

View File

@ -8,6 +8,8 @@ import 'package:pigeon/pigeon_lib.dart';
/// This is the main entrypoint for the command-line tool. [args] are the
/// commmand line arguments and there is an optional [packageConfig] to
/// accomodate users that want to integrate pigeon with other build systems.
Future<int> runCommandLine(List<String> args, {Uri? packageConfig}) async {
/// [sdkPath] for specifying an optional Dart SDK path.
Future<int> runCommandLine(List<String> args,
{Uri? packageConfig, String? sdkPath}) async {
return Pigeon.run(args);
}

View File

@ -808,12 +808,16 @@ class Pigeon {
/// Reads the file located at [path] and generates [ParseResults] by parsing
/// it. [types] optionally filters out what datatypes are actually parsed.
ParseResults parseFile(String inputPath) {
/// [sdkPath] for specifying the Dart SDK path for
/// [AnalysisContextCollection].
ParseResults parseFile(String inputPath, {String? sdkPath}) {
final List<String> includedPaths = <String>[
path.absolute(path.normalize(inputPath))
];
final AnalysisContextCollection collection =
AnalysisContextCollection(includedPaths: includedPaths);
final AnalysisContextCollection collection = AnalysisContextCollection(
includedPaths: includedPaths,
sdkPath: sdkPath,
);
final List<Error> compilationErrors = <Error>[];
final _RootBuilder rootBuilder =
@ -941,9 +945,10 @@ options:
/// The 'main' entrypoint used by the command-line tool. [args] are the
/// command-line arguments. The optional parameter [generators] allows you to
/// customize the generators that pigeon will use.
/// customize the generators that pigeon will use. The optional parameter
/// [sdkPath] allows you to specify the Dart SDK path.
static Future<int> run(List<String> args,
{List<Generator>? generators}) async {
{List<Generator>? generators, String? sdkPath}) async {
final Pigeon pigeon = Pigeon.setup();
PigeonOptions options = Pigeon.parseArgs(args);
final List<Generator> safeGenerators = generators ??
@ -969,7 +974,8 @@ options:
ObjcOptions(header: path.basename(options.objcHeaderOut!)))));
}
final ParseResults parseResults = pigeon.parseFile(options.input!);
final ParseResults parseResults =
pigeon.parseFile(options.input!, sdkPath: sdkPath);
if (parseResults.pigeonOptions != null) {
options = PigeonOptions.fromMap(
mergeMaps(options.toMap(), parseResults.pigeonOptions!));