15
15
use std:: { fmt, path:: PathBuf } ;
16
16
17
17
use miette:: { ensure, miette, Context , IntoDiagnostic } ;
18
- use protoc_bin_vendored:: protoc_bin_path;
19
18
use serde:: { Deserialize , Serialize } ;
20
19
use tracing:: { debug, info} ;
21
20
@@ -57,18 +56,12 @@ impl Generator {
57
56
58
57
/// Run the generator for a dependency and output files at the provided path
59
58
pub async fn run ( & self ) -> miette:: Result < ( ) > {
60
- let protoc = protoc_bin_path ( )
61
- . into_diagnostic ( )
62
- . wrap_err ( miette ! ( "unable to locate vendored protoc" ) ) ?;
63
-
64
- std:: env:: set_var ( "PROTOC" , protoc. clone ( ) ) ;
65
-
66
59
let store = PackageStore :: current ( ) . await ?;
67
60
let manifest = Manifest :: read ( ) . await ?;
68
61
69
62
store. populate ( & manifest) . await ?;
70
63
71
- let protos = store. populated_files ( & manifest) . await ;
64
+ let proto_files = store. populated_files ( & manifest) . await ;
72
65
let includes = & [ store. proto_vendor_path ( ) ] ;
73
66
74
67
match self {
@@ -78,15 +71,15 @@ impl Generator {
78
71
. build_server ( true )
79
72
. build_transport ( true )
80
73
. include_file ( Self :: TONIC_INCLUDE_FILE )
81
- . compile ( & protos , includes)
74
+ . compile ( & proto_files , includes)
82
75
. into_diagnostic ( ) ?;
83
76
}
84
77
Generator :: Protoc { language, out_dir } => {
85
- let mut protoc_cmd = tokio :: process :: Command :: new ( protoc ) ;
78
+ let mut protoc = protoc :: ProtocLangOut :: new ( ) ;
86
79
87
80
match language {
88
81
Language :: Python => {
89
- protoc_cmd . arg ( "--python_out ") . arg ( out_dir) ;
82
+ protoc . lang ( "python ") . out_dir ( out_dir) ;
90
83
}
91
84
}
92
85
@@ -95,25 +88,14 @@ impl Generator {
95
88
// e.g. if input proto path is proto/vendor/units/units.proto and the proto path is 'proto'
96
89
// and the --python_out is 'proto/build/gen' then the file will be output to
97
90
// proto/build/gen/vendor/units/units.py
91
+ // We need both of these if we want "vendor" to be removed, and it has to come first
92
+ protoc. includes ( [ "proto/vendor" , "proto" ] ) ;
98
93
99
- protoc_cmd. arg ( "--proto_path" ) . arg ( "proto/vendor" ) ; // We need both of these if we want "vendor" to be removed, and it has to come first
100
- protoc_cmd. arg ( "--proto_path" ) . arg ( "proto" ) ;
101
-
102
- protoc_cmd. args ( & protos) ;
103
-
104
- debug ! ( ":: running {protoc_cmd:?}" ) ;
105
-
106
- let output = protoc_cmd. output ( ) . await . into_diagnostic ( ) ?;
94
+ protoc. inputs ( & proto_files) ;
107
95
108
- let exit = output. status . code ( ) . ok_or ( miette ! (
109
- "a signal interrupted the protoc subprocess before it could complete"
110
- ) ) ?;
96
+ debug ! ( ":: running protoc" ) ;
111
97
112
- ensure ! (
113
- exit == 0 ,
114
- "the protoc subprocess terminated with an error: {exit}. stderr: {}" ,
115
- String :: from_utf8_lossy( & output. stderr)
116
- ) ;
98
+ protoc. run ( ) . into_diagnostic ( ) ?;
117
99
118
100
info ! ( ":: {language} code generated successfully" ) ;
119
101
}
0 commit comments