Skip to content
This repository has been archived by the owner on Jan 26, 2021. It is now read-only.

Commit

Permalink
Sync changes from internal repo. (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobr-google authored May 17, 2018
1 parent a957cb2 commit a5936dd
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 41 deletions.
31 changes: 7 additions & 24 deletions lib/file_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class FileGenerator extends ProtobufContainer {
/// Writes the header and imports for the .pb.dart file.
void writeMainHeader(IndentingWriter out,
[OutputConfiguration config = const DefaultOutputConfiguration()]) {
_writeLibraryHeading(out);
_writeHeading(out);

// We only add the dart:async import if there are generic client API
// generators for services in the FileDescriptorProto.
Expand Down Expand Up @@ -357,7 +357,7 @@ class FileGenerator extends ProtobufContainer {
if (!_linked) throw new StateError("not linked");

var out = new IndentingWriter();
_writeLibraryHeading(out, "pbenum");
_writeHeading(out);

if (enumCount > 0) {
// Make sure any other symbols in dart:core don't cause name conflicts
Expand Down Expand Up @@ -393,7 +393,7 @@ class FileGenerator extends ProtobufContainer {
[OutputConfiguration config = const DefaultOutputConfiguration()]) {
if (!_linked) throw new StateError("not linked");
var out = new IndentingWriter();
_writeLibraryHeading(out, "pbserver");
_writeHeading(out);

if (serviceGenerators.isNotEmpty) {
out.println('''
Expand Down Expand Up @@ -435,7 +435,7 @@ import 'package:protobuf/protobuf.dart';
[OutputConfiguration config = const DefaultOutputConfiguration()]) {
if (!_linked) throw new StateError("not linked");
var out = new IndentingWriter();
_writeLibraryHeading(out, "pbgrpc");
_writeHeading(out);

out.println('''
import 'dart:async';
Expand Down Expand Up @@ -469,7 +469,7 @@ import 'package:grpc/grpc.dart';
[OutputConfiguration config = const DefaultOutputConfiguration()]) {
if (!_linked) throw new StateError("not linked");
var out = new IndentingWriter();
_writeLibraryHeading(out, "pbjson");
_writeHeading(out);

// Import the .pbjson.dart files we depend on.
var imports = _findJsonProtosToImport();
Expand Down Expand Up @@ -508,30 +508,13 @@ import 'package:grpc/grpc.dart';
return imports;
}

/// Writes the library name at the top of the dart file.
///
/// (This should be unique to avoid warnings about duplicate Dart libraries.)
void _writeLibraryHeading(IndentingWriter out, [String extension]) {
Uri filePath = new Uri.file(descriptor.name);
if (filePath.isAbsolute) {
// protoc should never generate a file descriptor with an absolute path.
throw "FAILURE: File with an absolute path is not supported";
}

var libraryName = _fileNameWithoutExtension(filePath).replaceAll('-', '_');
if (extension != null) libraryName += "_$extension";
if (descriptor.package != '') {
// Two .protos can be in the same proto package.
// It isn't unique enough to use as a Dart library name.
// But we can prepend it.
libraryName = descriptor.package + "_" + libraryName;
}
/// Writes the header at the top of the dart file.
void _writeHeading(IndentingWriter out) {
out.println('''
///
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
library $libraryName;
''');
}

Expand Down
1 change: 0 additions & 1 deletion lib/src/dart_options.pb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
library dart_options_dart_options;

// ignore: UNUSED_SHOWN_NAME
import 'dart:core' show int, bool, double, String, List, override;
Expand Down
1 change: 0 additions & 1 deletion lib/src/descriptor.pb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
library google.protobuf_descriptor;

// ignore: UNUSED_SHOWN_NAME
import 'dart:core' show int, bool, double, String, List, override;
Expand Down
1 change: 0 additions & 1 deletion lib/src/descriptor.pbenum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
library google.protobuf_descriptor_pbenum;

// ignore_for_file: UNDEFINED_SHOWN_NAME,UNUSED_SHOWN_NAME
import 'dart:core' show int, dynamic, String, List, Map;
Expand Down
1 change: 0 additions & 1 deletion lib/src/plugin.pb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
library google.protobuf.compiler_plugin;

// ignore: UNUSED_SHOWN_NAME
import 'dart:core' show int, bool, double, String, List, override;
Expand Down
13 changes: 0 additions & 13 deletions test/file_generator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ void main() {
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
library test;
// ignore: UNUSED_SHOWN_NAME
import 'dart:core' show int, bool, double, String, List, override;
Expand Down Expand Up @@ -141,7 +140,6 @@ class _ReadonlyPhoneNumber extends PhoneNumber with ReadonlyMessageMixin {}
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
library test_pbjson;
const PhoneNumber$json = const {
'1': 'PhoneNumber',
Expand Down Expand Up @@ -169,7 +167,6 @@ const PhoneNumber$json = const {
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
library test;
// ignore: UNUSED_SHOWN_NAME
import 'dart:core' show int, bool, double, String, List, override;
Expand All @@ -183,7 +180,6 @@ export 'test.pbenum.dart';
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
library test_pbenum;
// ignore_for_file: UNDEFINED_SHOWN_NAME,UNUSED_SHOWN_NAME
import 'dart:core' show int, dynamic, String, List, Map;
Expand Down Expand Up @@ -230,7 +226,6 @@ class PhoneType extends ProtobufEnum {
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
library test_pbjson;
const PhoneType$json = const {
'1': 'PhoneType',
Expand Down Expand Up @@ -260,7 +255,6 @@ const PhoneType$json = const {
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
library pb_library_test;
// ignore: UNUSED_SHOWN_NAME
import 'dart:core' show int, bool, double, String, List, override;
Expand All @@ -287,7 +281,6 @@ import 'package:protobuf/protobuf.dart';
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
library test;
// ignore: UNUSED_SHOWN_NAME
import 'dart:core' show int, bool, double, String, List, override;
Expand Down Expand Up @@ -324,7 +317,6 @@ import 'package:protobuf/protobuf.dart';
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
library test;
import 'dart:async';
// ignore: UNUSED_SHOWN_NAME
Expand Down Expand Up @@ -373,7 +365,6 @@ class TestApi {
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
library test_pbserver;
import 'dart:async';
Expand Down Expand Up @@ -440,7 +431,6 @@ abstract class TestServiceBase extends GeneratedService {
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
library test;
// ignore: UNUSED_SHOWN_NAME
import 'dart:core' show int, bool, double, String, List, override;
Expand Down Expand Up @@ -503,7 +493,6 @@ class _ReadonlyEmpty extends Empty with ReadonlyMessageMixin {}
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
library test_pbgrpc;
import 'dart:async';
Expand Down Expand Up @@ -662,7 +651,6 @@ abstract class TestServiceBase extends Service {
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
library test;
// ignore: UNUSED_SHOWN_NAME
import 'dart:core' show int, bool, double, String, List, override;
Expand Down Expand Up @@ -721,7 +709,6 @@ class _ReadonlyM extends M with ReadonlyMessageMixin {}
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
library test_pbjson;
const M$json = const {
'1': 'M',
Expand Down

0 comments on commit a5936dd

Please sign in to comment.