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

Commit a5936dd

Browse files
Sync changes from internal repo. (#107)
1 parent a957cb2 commit a5936dd

File tree

6 files changed

+7
-41
lines changed

6 files changed

+7
-41
lines changed

lib/file_generator.dart

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ class FileGenerator extends ProtobufContainer {
239239
/// Writes the header and imports for the .pb.dart file.
240240
void writeMainHeader(IndentingWriter out,
241241
[OutputConfiguration config = const DefaultOutputConfiguration()]) {
242-
_writeLibraryHeading(out);
242+
_writeHeading(out);
243243

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

359359
var out = new IndentingWriter();
360-
_writeLibraryHeading(out, "pbenum");
360+
_writeHeading(out);
361361

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

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

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

474474
// Import the .pbjson.dart files we depend on.
475475
var imports = _findJsonProtosToImport();
@@ -508,30 +508,13 @@ import 'package:grpc/grpc.dart';
508508
return imports;
509509
}
510510

511-
/// Writes the library name at the top of the dart file.
512-
///
513-
/// (This should be unique to avoid warnings about duplicate Dart libraries.)
514-
void _writeLibraryHeading(IndentingWriter out, [String extension]) {
515-
Uri filePath = new Uri.file(descriptor.name);
516-
if (filePath.isAbsolute) {
517-
// protoc should never generate a file descriptor with an absolute path.
518-
throw "FAILURE: File with an absolute path is not supported";
519-
}
520-
521-
var libraryName = _fileNameWithoutExtension(filePath).replaceAll('-', '_');
522-
if (extension != null) libraryName += "_$extension";
523-
if (descriptor.package != '') {
524-
// Two .protos can be in the same proto package.
525-
// It isn't unique enough to use as a Dart library name.
526-
// But we can prepend it.
527-
libraryName = descriptor.package + "_" + libraryName;
528-
}
511+
/// Writes the header at the top of the dart file.
512+
void _writeHeading(IndentingWriter out) {
529513
out.println('''
530514
///
531515
// Generated code. Do not modify.
532516
///
533517
// ignore_for_file: non_constant_identifier_names,library_prefixes
534-
library $libraryName;
535518
''');
536519
}
537520

lib/src/dart_options.pb.dart

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/descriptor.pb.dart

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/descriptor.pbenum.dart

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/plugin.pb.dart

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/file_generator_test.dart

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ void main() {
7777
// Generated code. Do not modify.
7878
///
7979
// ignore_for_file: non_constant_identifier_names,library_prefixes
80-
library test;
8180
8281
// ignore: UNUSED_SHOWN_NAME
8382
import 'dart:core' show int, bool, double, String, List, override;
@@ -141,7 +140,6 @@ class _ReadonlyPhoneNumber extends PhoneNumber with ReadonlyMessageMixin {}
141140
// Generated code. Do not modify.
142141
///
143142
// ignore_for_file: non_constant_identifier_names,library_prefixes
144-
library test_pbjson;
145143
146144
const PhoneNumber$json = const {
147145
'1': 'PhoneNumber',
@@ -169,7 +167,6 @@ const PhoneNumber$json = const {
169167
// Generated code. Do not modify.
170168
///
171169
// ignore_for_file: non_constant_identifier_names,library_prefixes
172-
library test;
173170
174171
// ignore: UNUSED_SHOWN_NAME
175172
import 'dart:core' show int, bool, double, String, List, override;
@@ -183,7 +180,6 @@ export 'test.pbenum.dart';
183180
// Generated code. Do not modify.
184181
///
185182
// ignore_for_file: non_constant_identifier_names,library_prefixes
186-
library test_pbenum;
187183
188184
// ignore_for_file: UNDEFINED_SHOWN_NAME,UNUSED_SHOWN_NAME
189185
import 'dart:core' show int, dynamic, String, List, Map;
@@ -230,7 +226,6 @@ class PhoneType extends ProtobufEnum {
230226
// Generated code. Do not modify.
231227
///
232228
// ignore_for_file: non_constant_identifier_names,library_prefixes
233-
library test_pbjson;
234229
235230
const PhoneType$json = const {
236231
'1': 'PhoneType',
@@ -260,7 +255,6 @@ const PhoneType$json = const {
260255
// Generated code. Do not modify.
261256
///
262257
// ignore_for_file: non_constant_identifier_names,library_prefixes
263-
library pb_library_test;
264258
265259
// ignore: UNUSED_SHOWN_NAME
266260
import 'dart:core' show int, bool, double, String, List, override;
@@ -287,7 +281,6 @@ import 'package:protobuf/protobuf.dart';
287281
// Generated code. Do not modify.
288282
///
289283
// ignore_for_file: non_constant_identifier_names,library_prefixes
290-
library test;
291284
292285
// ignore: UNUSED_SHOWN_NAME
293286
import 'dart:core' show int, bool, double, String, List, override;
@@ -324,7 +317,6 @@ import 'package:protobuf/protobuf.dart';
324317
// Generated code. Do not modify.
325318
///
326319
// ignore_for_file: non_constant_identifier_names,library_prefixes
327-
library test;
328320
329321
import 'dart:async';
330322
// ignore: UNUSED_SHOWN_NAME
@@ -373,7 +365,6 @@ class TestApi {
373365
// Generated code. Do not modify.
374366
///
375367
// ignore_for_file: non_constant_identifier_names,library_prefixes
376-
library test_pbserver;
377368
378369
import 'dart:async';
379370
@@ -440,7 +431,6 @@ abstract class TestServiceBase extends GeneratedService {
440431
// Generated code. Do not modify.
441432
///
442433
// ignore_for_file: non_constant_identifier_names,library_prefixes
443-
library test;
444434
445435
// ignore: UNUSED_SHOWN_NAME
446436
import 'dart:core' show int, bool, double, String, List, override;
@@ -503,7 +493,6 @@ class _ReadonlyEmpty extends Empty with ReadonlyMessageMixin {}
503493
// Generated code. Do not modify.
504494
///
505495
// ignore_for_file: non_constant_identifier_names,library_prefixes
506-
library test_pbgrpc;
507496
508497
import 'dart:async';
509498
@@ -662,7 +651,6 @@ abstract class TestServiceBase extends Service {
662651
// Generated code. Do not modify.
663652
///
664653
// ignore_for_file: non_constant_identifier_names,library_prefixes
665-
library test;
666654
667655
// ignore: UNUSED_SHOWN_NAME
668656
import 'dart:core' show int, bool, double, String, List, override;
@@ -721,7 +709,6 @@ class _ReadonlyM extends M with ReadonlyMessageMixin {}
721709
// Generated code. Do not modify.
722710
///
723711
// ignore_for_file: non_constant_identifier_names,library_prefixes
724-
library test_pbjson;
725712
726713
const M$json = const {
727714
'1': 'M',

0 commit comments

Comments
 (0)