diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index 8da8cd4606..dbbe1f77f6 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -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 diff --git a/packages/pigeon/lib/pigeon_cl.dart b/packages/pigeon/lib/pigeon_cl.dart index 3d6164fd8d..3f4218f7fc 100644 --- a/packages/pigeon/lib/pigeon_cl.dart +++ b/packages/pigeon/lib/pigeon_cl.dart @@ -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 runCommandLine(List args, {Uri? packageConfig}) async { +/// [sdkPath] for specifying an optional Dart SDK path. +Future runCommandLine(List args, + {Uri? packageConfig, String? sdkPath}) async { return Pigeon.run(args); } diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 9026226d2b..5b4110f245 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -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 includedPaths = [ path.absolute(path.normalize(inputPath)) ]; - final AnalysisContextCollection collection = - AnalysisContextCollection(includedPaths: includedPaths); + final AnalysisContextCollection collection = AnalysisContextCollection( + includedPaths: includedPaths, + sdkPath: sdkPath, + ); final List compilationErrors = []; 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 run(List args, - {List? generators}) async { + {List? generators, String? sdkPath}) async { final Pigeon pigeon = Pigeon.setup(); PigeonOptions options = Pigeon.parseArgs(args); final List 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!));