Generate exports for proto libraries that are publicly imported. (#275)
diff --git a/protobuf/CHANGELOG.md b/protobuf/CHANGELOG.md
index aee700b..5e086ea 100644
--- a/protobuf/CHANGELOG.md
+++ b/protobuf/CHANGELOG.md
@@ -1,3 +1,12 @@
+## 0.14.1
+
+* Support for `import public`.
+
+ The generated code for a protofile `a.proto` that `import public "b.proto"` will export the
+ generated code for `b.proto`.
+
+ See https://developers.google.com/protocol-buffers/docs/proto#importing-definitions.
+
## 0.14.0
* Support for proto3 json (json with field names as keys)
diff --git a/protobuf/pubspec.yaml b/protobuf/pubspec.yaml
index 0f5437b..69c2241 100644
--- a/protobuf/pubspec.yaml
+++ b/protobuf/pubspec.yaml
@@ -1,5 +1,5 @@
name: protobuf
-version: 0.14.0
+version: 0.14.1
author: Dart Team <misc@dartlang.org>
description: >
Runtime library for protocol buffers support.
diff --git a/protoc_plugin/Makefile b/protoc_plugin/Makefile
index 5338686..797cbfa 100644
--- a/protoc_plugin/Makefile
+++ b/protoc_plugin/Makefile
@@ -32,6 +32,7 @@
ExtensionNameConflict \
foo \
import_clash \
+ import_public \
json_name \
map_api \
map_api2 \
diff --git a/protoc_plugin/lib/file_generator.dart b/protoc_plugin/lib/file_generator.dart
index c1b355c..d120d57 100644
--- a/protoc_plugin/lib/file_generator.dart
+++ b/protoc_plugin/lib/file_generator.dart
@@ -319,6 +319,11 @@
}
if (enumImports.isNotEmpty) out.println();
+ for (int publicDependency in descriptor.publicDependency) {
+ _writeExport(out, config,
+ Uri.file(descriptor.dependency[publicDependency]), '.pb.dart');
+ }
+
// Export enums in main file for backward compatibility.
if (enumCount > 0) {
Uri resolvedImport =
@@ -559,4 +564,12 @@
}
out.println(';');
}
+
+ /// Writes an export of a pb.dart file corresponding to a .proto file.
+ /// (Possibly the same .proto file.)
+ void _writeExport(IndentingWriter out, OutputConfiguration config, Uri target,
+ String extension) {
+ Uri resolvedImport = config.resolveImport(target, protoFileUri, extension);
+ out.println("export '$resolvedImport';");
+ }
}
diff --git a/protoc_plugin/test/import_public_test.dart b/protoc_plugin/test/import_public_test.dart
new file mode 100644
index 0000000..2a4dd94
--- /dev/null
+++ b/protoc_plugin/test/import_public_test.dart
@@ -0,0 +1,14 @@
+#!/usr/bin/env dart
+// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+import 'package:test/test.dart';
+
+import '../out/protos/import_public.pb.dart';
+
+main() {
+ test('can reference a message type imported publicly', () {
+ expect(Foo(), TypeMatcher<Foo>());
+ expect(A(), TypeMatcher<A>());
+ });
+}
diff --git a/protoc_plugin/test/protos/import_public.proto b/protoc_plugin/test/protos/import_public.proto
new file mode 100644
index 0000000..effed9f
--- /dev/null
+++ b/protoc_plugin/test/protos/import_public.proto
@@ -0,0 +1,11 @@
+syntax = "proto2";
+
+// A public import can be used in the file importing this file. Similar to a
+// Dart export.
+//
+// See https://developers.google.com/protocol-buffers/docs/proto#importing-definitions
+import public "foo.proto";
+
+message A {
+ optional foo.Foo a = 1;
+}