Skip to content

Commit e202db9

Browse files
committed
relative paths and appDir comments
1 parent dd5e68c commit e202db9

8 files changed

Lines changed: 34 additions & 15 deletions

File tree

packages/pigeon/lib/src/kotlin/jnigen_config_generator.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class JnigenConfigGenerator extends Generator<InternalJnigenConfigOptions> {
5959
summarizerOptions: SummarizerOptions(backend: SummarizerBackend.asm),
6060
outputConfig: OutputConfig(
6161
dartConfig: DartCodeOutputConfig(
62+
// Path is relative to appDirectory.
6263
path: Uri.file('${path.relative(path.withoutExtension(generatorOptions.dartOptions.dartOut ?? './lib/pigeons/'), from: generatorOptions.appDirectory ?? './')}.jni.dart'),
6364
structure: OutputStructure.singleFile,
6465
),

packages/pigeon/lib/src/kotlin/kotlin_generator.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ class KotlinOptions {
6262
/// Whether to use Jni when possible.
6363
final bool useJni;
6464

65-
/// The directory that the app exists in, this is required for Jni APIs.
65+
/// The directory that the app exists in.
66+
///
67+
/// Defaults to './' if not specified.
6668
final String? appDirectory;
6769

6870
/// The name of the error class used for passing custom error parameters.

packages/pigeon/lib/src/pigeon_lib_internal.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ class FfigenConfigGeneratorAdapter implements GeneratorAdapter {
573573
swiftOptions,
574574
options.basePath,
575575
dartOptions.dartOut,
576-
swiftOptions.swiftOut,
576+
options.appDirectory,
577577
);
578578

579579
generator.generate(
@@ -586,11 +586,11 @@ class FfigenConfigGeneratorAdapter implements GeneratorAdapter {
586586

587587
@override
588588
IOSink? shouldGenerate(InternalPigeonOptions options, FileType _) =>
589-
options.swiftOptions?.appDirectory != null &&
590-
(options.swiftOptions?.useFfi ?? false)
589+
(options.swiftOptions?.useFfi ?? false)
591590
? _openSink(
592591
'ffigen_config.dart',
593-
basePath: options.swiftOptions?.appDirectory ?? '',
592+
basePath:
593+
options.swiftOptions?.appDirectory ?? options.appDirectory ?? '',
594594
)
595595
: null;
596596

@@ -809,7 +809,11 @@ class JnigenConfigGeneratorAdapter implements GeneratorAdapter {
809809
IOSink? shouldGenerate(InternalPigeonOptions options, FileType _) =>
810810
options.kotlinOptions?.kotlinOut != null &&
811811
(options.kotlinOptions?.useJni ?? false)
812-
? _openSink('jnigen_config.dart', basePath: options.appDirectory ?? '')
812+
? _openSink(
813+
'jnigen_config.dart',
814+
basePath:
815+
options.kotlinOptions?.appDirectory ?? options.appDirectory ?? '',
816+
)
813817
: null;
814818

815819
@override

packages/pigeon/lib/src/swift/ffigen_config_generator.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,16 @@ import 'package:swiftgen/swiftgen.dart';
156156
),
157157
),
158158
inputs: <SwiftGenInput>[ObjCCompatibleSwiftFileInput(files: <Uri>[
159-
Uri.file('${generatorOptions.swiftOptions.swiftOut}')
159+
Uri.file('${path.relative(generatorOptions.swiftOptions.swiftOut, from: generatorOptions.exampleAppDirectory ?? './')}')
160160
])
161161
],
162162
include: (Declaration d) =>
163163
classes.contains(d.name) || enums.contains(d.name),
164164
output: Output(
165165
module: '${generatorOptions.swiftOptions.ffiModuleName ?? ''}',
166-
dartFile: Uri.file('${path.posix.join(generatorOptions.basePath ?? '', path.withoutExtension(generatorOptions.dartOut ?? ''))}.ffi.dart'),
167-
objectiveCFile: Uri.file('${path.posix.join(objcDir, '${path.posix.basenameWithoutExtension(generatorOptions.swiftOptions.swiftOut)}.m')}'),
166+
// Path is relative to appDirectory.
167+
dartFile: Uri.file('${path.relative(path.withoutExtension(generatorOptions.dartOut ?? ''), from: generatorOptions.exampleAppDirectory ?? './')}.ffi.dart'),
168+
objectiveCFile: Uri.file('${path.relative(path.posix.join(objcDir, '${path.posix.basenameWithoutExtension(generatorOptions.swiftOptions.swiftOut)}.m'), from: generatorOptions.exampleAppDirectory ?? './')}'),
168169
preamble: \'''
169170
// ${generatorOptions.swiftOptions.copyrightHeader?.join('\n// ') ?? ''}
170171

packages/pigeon/lib/src/swift/swift_generator.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ class SwiftOptions {
5757
/// The module name that the FFi classes will use. Required if useFfi is true.
5858
final String? ffiModuleName;
5959

60-
/// The directory that the app exists in, this is required for FFI APIs.
60+
/// The directory that the app exists in.
61+
///
62+
/// Defaults to './' if not specified.
6163
final String? appDirectory;
6264

6365
/// The path to the Apple SDK to use for FFI generation.

packages/pigeon/pigeons/ni_tests.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@ import 'package:pigeon/pigeon.dart';
99
@ConfigurePigeon(
1010
PigeonOptions(
1111
dartOptions: DartOptions(),
12-
kotlinOptions: KotlinOptions(useJni: true),
13-
swiftOptions: SwiftOptions(useFfi: true, ffiModuleName: 'test_plugin'),
12+
kotlinOptions: KotlinOptions(
13+
useJni: true,
14+
appDirectory: 'platform_tests/test_plugin/example/',
15+
),
16+
swiftOptions: SwiftOptions(
17+
useFfi: true,
18+
ffiModuleName: 'test_plugin',
19+
appDirectory: 'platform_tests/test_plugin/example/',
20+
),
1421
),
1522
)
1623
enum NIAnEnum { one, two, three, fortyTwo, fourHundredTwentyTwo }

packages/pigeon/platform_tests/test_plugin/example/ffigen_config.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Future<void> main(List<String> args) async {
7070
ObjCCompatibleSwiftFileInput(
7171
files: <Uri>[
7272
Uri.file(
73-
'/Users/tarrinneal/work/packages/packages/pigeon/platform_tests/test_plugin/darwin/test_plugin/Sources/test_plugin/NiTests.gen.swift',
73+
'../darwin/test_plugin/Sources/test_plugin/NiTests.gen.swift',
7474
),
7575
],
7676
),
@@ -79,11 +79,12 @@ Future<void> main(List<String> args) async {
7979
classes.contains(d.name) || enums.contains(d.name),
8080
output: Output(
8181
module: 'test_plugin',
82+
// Path is relative to appDirectory.
8283
dartFile: Uri.file(
83-
'/Users/tarrinneal/work/packages/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/ni_tests.gen.ffi.dart',
84+
'../../shared_test_plugin_code/lib/src/generated/ni_tests.gen.ffi.dart',
8485
),
8586
objectiveCFile: Uri.file(
86-
'/Users/tarrinneal/work/packages/packages/pigeon/platform_tests/test_plugin/darwin/test_plugin/Sources/test_plugin_objc/NiTests.gen.m',
87+
'../darwin/test_plugin/Sources/test_plugin_objc/NiTests.gen.m',
8788
),
8889
preamble: '''
8990
// Copyright 2013 The Flutter Authors

packages/pigeon/platform_tests/test_plugin/example/jnigen_config.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ void main() async {
1212
summarizerOptions: SummarizerOptions(backend: SummarizerBackend.asm),
1313
outputConfig: OutputConfig(
1414
dartConfig: DartCodeOutputConfig(
15+
// Path is relative to appDirectory.
1516
path: Uri.file(
1617
'../../shared_test_plugin_code/lib/src/generated/ni_tests.gen.jni.dart',
1718
),

0 commit comments

Comments
 (0)