Skip to content

Commit

Permalink
Prevent warnings for "import public" on an empty .proto file. (#330)
Browse files Browse the repository at this point in the history
* Prevent warnings for "import proto" on an empty .proto file.

Previously, if we reexported an empty module, we ran into `-Wdodgy-imports`.
In practice, this came up because of a proto file that only defined an
extension, which proto-lens doesn't support yet, so it generated an
empty module.

I think proto-lens-protoc's architecture makes it nontrivial to detect whether a module
has no exports.  So I just suppressed the `-Wdodgy-imports` warning.  I also
converted the other warnings from `-fno-warn-*` to `-Wno-*` for consistency,
since GHC has supported that form for a while.

* Add missing  empty.proto file
  • Loading branch information
judah authored and blackgnezdo committed Aug 29, 2019
1 parent 3e9cd10 commit 6e8b73d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
10 changes: 6 additions & 4 deletions proto-lens-protoc/src/Data/ProtoLens/Compiler/Generate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,12 @@ generateModule modName imports publicImports modifyImport definitions importedEn
"DataKinds", "BangPatterns", "TypeApplications"]
-- Allow unused imports in case we don't import anything from
-- Data.Text, Data.Int, etc.
, optionsGhcPragma "-fno-warn-unused-imports"
-- haskell-src-exts doesn't support exporting `Foo(..., A, B)`
-- in a single entry, so we use two: `Foo(..)` and `Foo(A, B)`.
, optionsGhcPragma "-fno-warn-duplicate-exports"
, optionsGhcPragma "-Wno-unused-imports"
-- haskell-src-exts doesn't support exporting `Foo(..., A, B)`
-- in a single entry, so we use two: `Foo(..)` and `Foo(A, B)`.
, optionsGhcPragma "-Wno-duplicate-exports"
-- Don't warn if empty "import public" modules are reexported.
, optionsGhcPragma "-Wno-dodgy-exports"
]
mainImports = map (modifyImport . importSimple)
[ "Control.DeepSeq", "Data.ProtoLens.Prism" ]
Expand Down
1 change: 1 addition & 0 deletions proto-lens-tests/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ tests:
dependencies:
- proto-lens-tests
other-modules:
- Proto.Empty
- Proto.Enum
- Proto.Imports
- Proto.ImportsDep
Expand Down
4 changes: 4 additions & 0 deletions proto-lens-tests/tests/empty.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// An empty proto file.
syntax = "proto3";

package empty;
2 changes: 2 additions & 0 deletions proto-lens-tests/tests/imports_dep.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ syntax = "proto2";
package dep.pkg;

import public "imports_transitive.proto";
// Test that we supress warnings about reexporting empty modules.
import public "empty.proto";

message DepPkg {
optional int32 x = 1;
Expand Down

0 comments on commit 6e8b73d

Please sign in to comment.