@@ -22,6 +22,7 @@ const TASKS: &[(&str, fn(&Shell) -> Result<()>)] = &[
22
22
( "man2markdown" , man2markdown) ,
23
23
( "package" , package) ,
24
24
( "package-srpm" , package_srpm) ,
25
+ ( "spec" , spec) ,
25
26
( "custom-lints" , custom_lints) ,
26
27
( "test-tmt" , test_tmt) ,
27
28
] ;
@@ -244,6 +245,41 @@ fn package(sh: &Shell) -> Result<()> {
244
245
Ok ( ( ) )
245
246
}
246
247
248
+ fn update_spec ( sh : & Shell ) -> Result < Utf8PathBuf > {
249
+ let p = Utf8Path :: new ( "target" ) ;
250
+ let pkg = impl_package ( sh) ?;
251
+ let srcpath = pkg. srcpath . file_name ( ) . unwrap ( ) ;
252
+ let v = pkg. version ;
253
+ let src_vendorpath = pkg. vendorpath . file_name ( ) . unwrap ( ) ;
254
+ {
255
+ let specin = File :: open ( format ! ( "contrib/packaging/{NAME}.spec" ) )
256
+ . map ( BufReader :: new)
257
+ . context ( "Opening spec" ) ?;
258
+ let mut o = File :: create ( p. join ( format ! ( "{NAME}.spec" ) ) ) . map ( BufWriter :: new) ?;
259
+ for line in specin. lines ( ) {
260
+ let line = line?;
261
+ if line. starts_with ( "Version:" ) {
262
+ writeln ! ( o, "# Replaced by cargo xtask spec" ) ?;
263
+ writeln ! ( o, "Version: {v}" ) ?;
264
+ } else if line. starts_with ( "Source0" ) {
265
+ writeln ! ( o, "Source0: {srcpath}" ) ?;
266
+ } else if line. starts_with ( "Source1" ) {
267
+ writeln ! ( o, "Source1: {src_vendorpath}" ) ?;
268
+ } else {
269
+ writeln ! ( o, "{}" , line) ?;
270
+ }
271
+ }
272
+ }
273
+ let spec_path = p. join ( format ! ( "{NAME}.spec" ) ) ;
274
+ Ok ( spec_path)
275
+ }
276
+
277
+ fn spec ( sh : & Shell ) -> Result < ( ) > {
278
+ let s = update_spec ( sh) ?;
279
+ println ! ( "Generated: {s}" ) ;
280
+ Ok ( ( ) )
281
+ }
282
+
247
283
fn impl_srpm ( sh : & Shell ) -> Result < Utf8PathBuf > {
248
284
{
249
285
let _g = sh. push_dir ( "target" ) ;
0 commit comments