1- use anyhow:: Result ;
1+ #![ warn( clippy:: pedantic) ]
2+
23use clap:: Parser ;
34use digest:: Digest ;
45use duct:: cmd;
@@ -207,7 +208,7 @@ fn build_rpms(version: &str) {
207208 PathBuf :: from ( format ! ( "modelfox-{version}/modelfox" , version = version) ) ;
208209 let sources_path = rpm_path. join ( "SOURCES" ) ;
209210 let tar_path = sources_path. join ( "modelfox.tar.gz" ) ;
210- tar ( vec ! [ ( modelfox_cli_path, modelfox_path_in_tar) ] , & tar_path) ;
211+ tar ( & [ ( modelfox_cli_path, modelfox_path_in_tar) ] , & tar_path) ;
211212 // Write the spec file.
212213 let spec = formatdoc ! (
213214 r#"
@@ -321,6 +322,9 @@ fn build_containers(version: &str) {
321322 }
322323}
323324
325+ /// # Panics
326+ ///
327+ /// This function will panic if shelling out to `gpg --decrypt` fails.
324328pub fn build_pkgs ( version : & str , pkgs_url : & str ) {
325329 let root_path = std:: env:: current_dir ( ) . unwrap ( ) ;
326330 let pkgs_path = root_path. join ( "dist" ) . join ( "pkgs" ) ;
@@ -364,30 +368,27 @@ pub fn build_pkgs(version: &str, pkgs_url: &str) {
364368 version,
365369 & alpine_public_key_path,
366370 & alpine_private_key_path,
367- )
368- . unwrap ( ) ;
371+ ) ;
369372 deb (
370373 pkgs_url,
371374 version,
372375 & deb_public_key_path,
373376 & deb_private_key_path,
374- )
375- . unwrap ( ) ;
377+ ) ;
376378 rpm (
377379 pkgs_url,
378380 version,
379381 & rpm_public_key_path,
380382 & rpm_private_key_path,
381- )
382- . unwrap ( ) ;
383+ ) ;
383384}
384385
385386fn alpine (
386387 _pkgs_url : & str ,
387388 version : & str ,
388389 alpine_public_key_path : & Path ,
389390 alpine_private_key_path : & Path ,
390- ) -> Result < ( ) > {
391+ ) {
391392 let root_path = std:: env:: current_dir ( ) . unwrap ( ) ;
392393 let compile_path = root_path. join ( "dist" ) . join ( "compile" ) ;
393394 let pkgs_path = root_path. join ( "dist" ) . join ( "pkgs" ) ;
@@ -447,18 +448,10 @@ fn alpine(
447448 . run ( )
448449 . unwrap ( ) ;
449450 }
450- Ok ( ( ) )
451451}
452452
453- fn deb (
454- pkgs_url : & str ,
455- version : & str ,
456- deb_public_key_path : & Path ,
457- deb_private_key_path : & Path ,
458- ) -> Result < ( ) > {
459- let root_path = std:: env:: current_dir ( ) . unwrap ( ) ;
460- let pkgs_path = root_path. join ( "dist" ) . join ( "pkgs" ) ;
461- let debs_path = root_path. join ( "dist" ) . join ( "debs" ) ;
453+ #[ allow( clippy:: too_many_lines) ]
454+ fn deb ( pkgs_url : & str , version : & str , deb_public_key_path : & Path , deb_private_key_path : & Path ) {
462455 struct Deb < ' a > {
463456 arch : DebArch ,
464457 version : & ' a str ,
@@ -477,10 +470,13 @@ fn deb(
477470 }
478471 }
479472 }
473+ let root_path = std:: env:: current_dir ( ) . unwrap ( ) ;
474+ let pkgs_path = root_path. join ( "dist" ) . join ( "pkgs" ) ;
475+ let debs_path = root_path. join ( "dist" ) . join ( "debs" ) ;
480476 let archs = [ DebArch :: Amd64 , DebArch :: Arm64 ] ;
481477 let debs: Vec < Deb > = archs
482478 . iter ( )
483- . cloned ( )
479+ . copied ( )
484480 . map ( |arch| {
485481 let path = debs_path. join ( format ! (
486482 "modelfox_{version}_{arch}.deb" ,
@@ -532,7 +528,7 @@ fn deb(
532528 let pool_path = repo_path. join ( "pool" ) ;
533529 std:: fs:: create_dir_all ( & pool_path) . unwrap ( ) ;
534530 // Copy all the .debs into the pool.
535- for deb in debs. iter ( ) {
531+ for deb in & debs {
536532 std:: fs:: copy ( & deb. path , pool_path. join ( & deb. path . file_name ( ) . unwrap ( ) ) ) . unwrap ( ) ;
537533 }
538534 let dists_path = repo_path. join ( "dists" ) ;
@@ -656,19 +652,9 @@ fn deb(
656652 ) ;
657653 }
658654 }
659- Ok ( ( ) )
660655}
661656
662- fn rpm (
663- pkgs_url : & str ,
664- version : & str ,
665- rpm_public_key_path : & Path ,
666- rpm_private_key_path : & Path ,
667- ) -> Result < ( ) > {
668- let root_path = std:: env:: current_dir ( ) . unwrap ( ) ;
669- let pkgs_path = root_path. join ( "dist" ) . join ( "pkgs" ) ;
670- let rpms_path = root_path. join ( "dist" ) . join ( "rpms" ) ;
671- // Find all the .rpms in args.rpms.
657+ fn rpm ( pkgs_url : & str , version : & str , rpm_public_key_path : & Path , rpm_private_key_path : & Path ) {
672658 struct Rpm {
673659 target : RpmTarget ,
674660 path : PathBuf ,
@@ -686,10 +672,14 @@ fn rpm(
686672 }
687673 }
688674 }
675+ let root_path = std:: env:: current_dir ( ) . unwrap ( ) ;
676+ let pkgs_path = root_path. join ( "dist" ) . join ( "pkgs" ) ;
677+ let rpms_path = root_path. join ( "dist" ) . join ( "rpms" ) ;
678+ // Find all the .rpms in args.rpms.
689679 let targets = [ RpmTarget :: X8664 , RpmTarget :: AArch64 ] ;
690680 let rpms: Vec < Rpm > = targets
691681 . iter ( )
692- . cloned ( )
682+ . copied ( )
693683 . map ( |target| {
694684 let path = rpms_path. join ( format ! (
695685 "modelfox_{version}_{target}.rpm" ,
@@ -713,9 +703,8 @@ fn rpm(
713703 std:: fs:: create_dir_all ( & repo_path) . unwrap ( ) ;
714704 // Create the .repo file.
715705 let repo_file_path = repo_path. join ( "modelfox.repo" ) ;
716- let distribution_version_with_leading_slash = distribution_version
717- . map ( |v| format ! ( "/{v}" , v = v) )
718- . unwrap_or_else ( || "" . to_owned ( ) ) ;
706+ let distribution_version_with_leading_slash =
707+ distribution_version. map_or_else ( || "" . to_owned ( ) , |v| format ! ( "/{v}" , v = v) ) ;
719708 let repo_file = formatdoc ! (
720709 r#"
721710 [modelfox]
@@ -740,7 +729,7 @@ fn rpm(
740729 let repo_target_path = repo_path. join ( target. to_string ( ) ) ;
741730 std:: fs:: create_dir_all ( & repo_target_path) . unwrap ( ) ;
742731 // Copy the .rpm.
743- for rpm in rpms. iter ( ) {
732+ for rpm in & rpms {
744733 if rpm. target == target {
745734 std:: fs:: copy (
746735 & rpm. path ,
@@ -760,7 +749,6 @@ fn rpm(
760749 ) ;
761750 }
762751 }
763- Ok ( ( ) )
764752}
765753
766754fn build_release ( version : & str ) {
@@ -784,7 +772,7 @@ fn build_release(version: &str) {
784772 modelfox_cli_path. clone( ) ,
785773 PathBuf :: from( modelfox_cli_file_name) ,
786774 ) ] ;
787- tar ( inputs, & output_path) ;
775+ tar ( & inputs, & output_path) ;
788776 }
789777 // libmodelfox
790778 for target in TARGETS {
@@ -810,7 +798,7 @@ fn build_release(version: &str) {
810798 PathBuf :: from( target_file_names. libmodelfox_static_file_name) ,
811799 ) ,
812800 ] ;
813- tar ( inputs, & output_path) ;
801+ tar ( & inputs, & output_path) ;
814802 }
815803}
816804
@@ -830,7 +818,7 @@ pub enum Arch {
830818 X8664 ,
831819}
832820
833- #[ derive( Clone , Copy , Debug , PartialEq ) ]
821+ #[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
834822pub enum Target {
835823 AArch64LinuxGnu ,
836824 AArch64LinuxMusl ,
@@ -843,6 +831,7 @@ pub enum Target {
843831}
844832
845833impl Target {
834+ #[ must_use]
846835 pub fn arch ( & self ) -> Arch {
847836 match self {
848837 Target :: AArch64LinuxGnu | Target :: AArch64LinuxMusl | Target :: AArch64MacOs => {
@@ -856,6 +845,7 @@ impl Target {
856845 }
857846 }
858847
848+ #[ must_use]
859849 pub fn target_name ( & self ) -> & ' static str {
860850 match self {
861851 Target :: AArch64LinuxGnu => "aarch64-linux-gnu" ,
@@ -869,6 +859,7 @@ impl Target {
869859 }
870860 }
871861
862+ #[ must_use]
872863 pub fn rust_target_name ( & self ) -> & ' static str {
873864 match self {
874865 Target :: AArch64LinuxGnu => "aarch64-unknown-linux-gnu" ,
@@ -882,6 +873,7 @@ impl Target {
882873 }
883874 }
884875
876+ #[ must_use]
885877 pub fn rust_target ( & self ) -> & ' static str {
886878 match self {
887879 Target :: AArch64LinuxGnu => "aarch64-unknown-linux-gnu" ,
@@ -907,6 +899,7 @@ pub struct TargetFileNames {
907899}
908900
909901impl TargetFileNames {
902+ #[ must_use]
910903 pub fn for_target ( target : Target ) -> TargetFileNames {
911904 match target {
912905 Target :: X8664LinuxGnu
@@ -959,16 +952,17 @@ fn clean_and_create(path: &Path) {
959952 std:: fs:: create_dir_all ( path) . unwrap ( ) ;
960953}
961954
962- fn tar ( input_paths : Vec < ( PathBuf , PathBuf ) > , output_path : & Path ) {
955+ fn tar ( input_paths : & [ ( PathBuf , PathBuf ) ] , output_path : & Path ) {
963956 let output_file = std:: fs:: File :: create ( output_path) . unwrap ( ) ;
964957 let gz = flate2:: write:: GzEncoder :: new ( output_file, flate2:: Compression :: default ( ) ) ;
965958 let mut tar = tar:: Builder :: new ( gz) ;
966- for ( path, name) in input_paths. iter ( ) {
959+ for ( path, name) in input_paths {
967960 tar. append_path_with_name ( path, name) . unwrap ( ) ;
968961 }
969962 tar. finish ( ) . unwrap ( ) ;
970963}
971964
965+ #[ derive( Clone , Copy ) ]
972966enum SignatureType {
973967 Cleartext ,
974968 Detached ,
0 commit comments