-
Notifications
You must be signed in to change notification settings - Fork 186
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
Add dart_package option #298
Open
sigurdm
wants to merge
3
commits into
google:master
Choose a base branch
from
sigurdm:dart_package_option
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+294
−9
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/// | ||
// Generated code. Do not modify. | ||
// source: no_package.proto | ||
// | ||
// @dart = 2.3 | ||
// ignore_for_file: camel_case_types,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type | ||
|
||
import 'dart:core' as $core; | ||
|
||
import 'package:protobuf/protobuf.dart' as $pb; | ||
|
||
import 'package:abc/a.pb.dart' as $3; | ||
|
||
class D extends $pb.GeneratedMessage { | ||
static final $pb.BuilderInfo _i = $pb.BuilderInfo('D', createEmptyInstance: create) | ||
..aOM<$3.A>(1, 'a', subBuilder: $3.A.create) | ||
..hasRequiredFields = false | ||
; | ||
|
||
D._() : super(); | ||
factory D() => create(); | ||
factory D.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); | ||
factory D.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); | ||
D clone() => D()..mergeFromMessage(this); | ||
D copyWith(void Function(D) updates) => super.copyWith((message) => updates(message as D)); | ||
$pb.BuilderInfo get info_ => _i; | ||
@$core.pragma('dart2js:noInline') | ||
static D create() => D._(); | ||
D createEmptyInstance() => create(); | ||
static $pb.PbList<D> createRepeated() => $pb.PbList<D>(); | ||
@$core.pragma('dart2js:noInline') | ||
static D getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<D>(create); | ||
static D _defaultInstance; | ||
|
||
@$pb.TagNumber(1) | ||
$3.A get a => $_getN(0); | ||
@$pb.TagNumber(1) | ||
set a($3.A v) { setField(1, v); } | ||
@$pb.TagNumber(1) | ||
$core.bool hasA() => $_has(0); | ||
@$pb.TagNumber(1) | ||
void clearA() => clearField(1); | ||
@$pb.TagNumber(1) | ||
$3.A ensureA() => $_ensure(0); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/// | ||
// Generated code. Do not modify. | ||
// source: other_package.proto | ||
// | ||
// @dart = 2.3 | ||
// ignore_for_file: camel_case_types,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type | ||
|
||
import 'dart:core' as $core; | ||
|
||
import 'package:protobuf/protobuf.dart' as $pb; | ||
|
||
import 'package:abc/a.pb.dart' as $3; | ||
|
||
class C extends $pb.GeneratedMessage { | ||
static final $pb.BuilderInfo _i = $pb.BuilderInfo('C', createEmptyInstance: create) | ||
..aOM<$3.A>(1, 'a', subBuilder: $3.A.create) | ||
..hasRequiredFields = false | ||
; | ||
|
||
C._() : super(); | ||
factory C() => create(); | ||
factory C.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); | ||
factory C.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); | ||
C clone() => C()..mergeFromMessage(this); | ||
C copyWith(void Function(C) updates) => super.copyWith((message) => updates(message as C)); | ||
$pb.BuilderInfo get info_ => _i; | ||
@$core.pragma('dart2js:noInline') | ||
static C create() => C._(); | ||
C createEmptyInstance() => create(); | ||
static $pb.PbList<C> createRepeated() => $pb.PbList<C>(); | ||
@$core.pragma('dart2js:noInline') | ||
static C getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<C>(create); | ||
static C _defaultInstance; | ||
|
||
@$pb.TagNumber(1) | ||
$3.A get a => $_getN(0); | ||
@$pb.TagNumber(1) | ||
set a($3.A v) { setField(1, v); } | ||
@$pb.TagNumber(1) | ||
$core.bool hasA() => $_has(0); | ||
@$pb.TagNumber(1) | ||
void clearA() => clearField(1); | ||
@$pb.TagNumber(1) | ||
$3.A ensureA() => $_ensure(0); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/// | ||
// Generated code. Do not modify. | ||
// source: same_package.proto | ||
// | ||
// @dart = 2.3 | ||
// ignore_for_file: camel_case_types,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type | ||
|
||
import 'dart:core' as $core; | ||
|
||
import 'package:protobuf/protobuf.dart' as $pb; | ||
|
||
import 'a.pb.dart' as $3; | ||
|
||
class B extends $pb.GeneratedMessage { | ||
static final $pb.BuilderInfo _i = $pb.BuilderInfo('B', createEmptyInstance: create) | ||
..aOM<$3.A>(1, 'a', subBuilder: $3.A.create) | ||
..hasRequiredFields = false | ||
; | ||
|
||
B._() : super(); | ||
factory B() => create(); | ||
factory B.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); | ||
factory B.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); | ||
B clone() => B()..mergeFromMessage(this); | ||
B copyWith(void Function(B) updates) => super.copyWith((message) => updates(message as B)); | ||
$pb.BuilderInfo get info_ => _i; | ||
@$core.pragma('dart2js:noInline') | ||
static B create() => B._(); | ||
B createEmptyInstance() => create(); | ||
static $pb.PbList<B> createRepeated() => $pb.PbList<B>(); | ||
@$core.pragma('dart2js:noInline') | ||
static B getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<B>(create); | ||
static B _defaultInstance; | ||
|
||
@$pb.TagNumber(1) | ||
$3.A get a => $_getN(0); | ||
@$pb.TagNumber(1) | ||
set a($3.A v) { setField(1, v); } | ||
@$pb.TagNumber(1) | ||
$core.bool hasA() => $_has(0); | ||
@$pb.TagNumber(1) | ||
void clearA() => clearField(1); | ||
@$pb.TagNumber(1) | ||
$3.A ensureA() => $_ensure(0); | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @sigurdm I've been having a look at this, and I think this should be:
descriptor.name
returns the full path of the proto file.In my project the proto root is not the same as the package directory, so I get something like:
dartPackage: "foo/bar"
descriptor.name: "bar/baz.proto"
Combining them together gives "foo/bar/bar/baz.proto" when it should be "foo/bar/baz.proto".
I believe it would be better to ignore the path from the descriptor because the dart package name should always point directly to the directory that contains the dart source file. Right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the dart package should not have slashes. It should just be a single name (the name of the package where the proto belongs)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ooh interesting... That would be tricky in my project... I have one directory structure with several dart packages, and they all share a common proto root.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it seems like an unnecessary restriction that your proto file structure should be the same as your dart package structure. Let me explain my project structure:
It's convenient to have the proto files all in the same directory structure, but the file structure of the Dart packages doesn't match this. I'm trying to ensure my proto files stay platform independent, so I don't really want to rearrange my proto files to match my Dart directory structure. Nor do I really want to have a separate proto root for each package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense to have one proto-root per package, if the protos truly belongs in that package. (At least the generated files have to be moved into
lib/
of that package.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK I'll have a go at rearranging my project / protoc commands. I'll let you know how I get on!