Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include the proto package name as a constant #824

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions protoc_plugin/lib/src/file_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ class FileGenerator extends ProtobufContainer {

writeMainHeader(out, config);

if (package.isNotEmpty) {
out.println("const \$core.String kPackageName = '$package';\n");
}

// Generate code.
for (final m in messageGenerators) {
m.generate(out);
Expand Down
4 changes: 3 additions & 1 deletion protoc_plugin/test/file_generator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import 'golden_file.dart';

FileDescriptorProto buildFileDescriptor(
{bool phoneNumber = true, bool topLevelEnum = false}) {
final fd = FileDescriptorProto()..name = 'test';
final fd = FileDescriptorProto()
..name = 'test'
..package = 'testPackage';

if (topLevelEnum) {
fd.enumType.add(EnumDescriptorProto()
Expand Down
4 changes: 3 additions & 1 deletion protoc_plugin/test/goldens/oneMessage.pb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ import 'dart:core' as $core;

import 'package:protobuf/protobuf.dart' as $pb;

const $core.String kPackageName = 'testPackage';

class PhoneNumber extends $pb.GeneratedMessage {
factory PhoneNumber() => create();
PhoneNumber._() : super();
factory PhoneNumber.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
factory PhoneNumber.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r);

static final $pb.BuilderInfo _i = $pb.BuilderInfo(_omitMessageNames ? '' : 'PhoneNumber', createEmptyInstance: create)
static final $pb.BuilderInfo _i = $pb.BuilderInfo(_omitMessageNames ? '' : 'PhoneNumber', package: const $pb.PackageName(_omitMessageNames ? '' : 'testPackage'), createEmptyInstance: create)
..aQS(1, _omitFieldNames ? '' : 'number')
..a<$core.int>(2, _omitFieldNames ? '' : 'type', $pb.PbFieldType.O3)
..a<$core.String>(3, _omitFieldNames ? '' : 'name', $pb.PbFieldType.OS, defaultOrMaker: '\$')
Expand Down
56 changes: 28 additions & 28 deletions protoc_plugin/test/goldens/oneMessage.pb.meta
Original file line number Diff line number Diff line change
Expand Up @@ -2,121 +2,121 @@ annotation: {
path: 4
path: 0
sourceFile: test
begin: 434
end: 445
begin: 484
end: 495
}
annotation: {
path: 4
path: 0
sourceFile: test
begin: 516
end: 527
begin: 566
end: 577
}
annotation: {
path: 4
path: 0
path: 2
path: 0
sourceFile: test
begin: 2236
end: 2242
begin: 2358
end: 2364
}
annotation: {
path: 4
path: 0
path: 2
path: 0
sourceFile: test
begin: 2284
end: 2290
begin: 2406
end: 2412
}
annotation: {
path: 4
path: 0
path: 2
path: 0
sourceFile: test
begin: 2363
end: 2372
begin: 2485
end: 2494
}
annotation: {
path: 4
path: 0
path: 2
path: 0
sourceFile: test
begin: 2415
end: 2426
begin: 2537
end: 2548
}
annotation: {
path: 4
path: 0
path: 2
path: 1
sourceFile: test
begin: 2484
end: 2488
begin: 2606
end: 2610
}
annotation: {
path: 4
path: 0
path: 2
path: 1
sourceFile: test
begin: 2530
end: 2534
begin: 2652
end: 2656
}
annotation: {
path: 4
path: 0
path: 2
path: 1
sourceFile: test
begin: 2609
end: 2616
begin: 2731
end: 2738
}
annotation: {
path: 4
path: 0
path: 2
path: 1
sourceFile: test
begin: 2659
end: 2668
begin: 2781
end: 2790
}
annotation: {
path: 4
path: 0
path: 2
path: 2
sourceFile: test
begin: 2729
end: 2733
begin: 2851
end: 2855
}
annotation: {
path: 4
path: 0
path: 2
path: 2
sourceFile: test
begin: 2780
end: 2784
begin: 2902
end: 2906
}
annotation: {
path: 4
path: 0
path: 2
path: 2
sourceFile: test
begin: 2857
end: 2864
begin: 2979
end: 2986
}
annotation: {
path: 4
path: 0
path: 2
path: 2
sourceFile: test
begin: 2907
end: 2916
begin: 3029
end: 3038
}
2 changes: 2 additions & 0 deletions protoc_plugin/test/goldens/topLevelEnum.pb
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ import 'dart:core' as $core;

export 'test.pbenum.dart';

const $core.String kPackageName = 'testPackage';