1
- use anyhow:: Result ;
1
+ #![ warn( clippy:: pedantic) ]
2
+
2
3
use clap:: Parser ;
3
4
use digest:: Digest ;
4
5
use duct:: cmd;
@@ -207,7 +208,7 @@ fn build_rpms(version: &str) {
207
208
PathBuf :: from ( format ! ( "modelfox-{version}/modelfox" , version = version) ) ;
208
209
let sources_path = rpm_path. join ( "SOURCES" ) ;
209
210
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) ;
211
212
// Write the spec file.
212
213
let spec = formatdoc ! (
213
214
r#"
@@ -321,6 +322,9 @@ fn build_containers(version: &str) {
321
322
}
322
323
}
323
324
325
+ /// # Panics
326
+ ///
327
+ /// This function will panic if shelling out to `gpg --decrypt` fails.
324
328
pub fn build_pkgs ( version : & str , pkgs_url : & str ) {
325
329
let root_path = std:: env:: current_dir ( ) . unwrap ( ) ;
326
330
let pkgs_path = root_path. join ( "dist" ) . join ( "pkgs" ) ;
@@ -364,30 +368,27 @@ pub fn build_pkgs(version: &str, pkgs_url: &str) {
364
368
version,
365
369
& alpine_public_key_path,
366
370
& alpine_private_key_path,
367
- )
368
- . unwrap ( ) ;
371
+ ) ;
369
372
deb (
370
373
pkgs_url,
371
374
version,
372
375
& deb_public_key_path,
373
376
& deb_private_key_path,
374
- )
375
- . unwrap ( ) ;
377
+ ) ;
376
378
rpm (
377
379
pkgs_url,
378
380
version,
379
381
& rpm_public_key_path,
380
382
& rpm_private_key_path,
381
- )
382
- . unwrap ( ) ;
383
+ ) ;
383
384
}
384
385
385
386
fn alpine (
386
387
_pkgs_url : & str ,
387
388
version : & str ,
388
389
alpine_public_key_path : & Path ,
389
390
alpine_private_key_path : & Path ,
390
- ) -> Result < ( ) > {
391
+ ) {
391
392
let root_path = std:: env:: current_dir ( ) . unwrap ( ) ;
392
393
let compile_path = root_path. join ( "dist" ) . join ( "compile" ) ;
393
394
let pkgs_path = root_path. join ( "dist" ) . join ( "pkgs" ) ;
@@ -447,18 +448,10 @@ fn alpine(
447
448
. run ( )
448
449
. unwrap ( ) ;
449
450
}
450
- Ok ( ( ) )
451
451
}
452
452
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 ) {
462
455
struct Deb < ' a > {
463
456
arch : DebArch ,
464
457
version : & ' a str ,
@@ -477,10 +470,13 @@ fn deb(
477
470
}
478
471
}
479
472
}
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" ) ;
480
476
let archs = [ DebArch :: Amd64 , DebArch :: Arm64 ] ;
481
477
let debs: Vec < Deb > = archs
482
478
. iter ( )
483
- . cloned ( )
479
+ . copied ( )
484
480
. map ( |arch| {
485
481
let path = debs_path. join ( format ! (
486
482
"modelfox_{version}_{arch}.deb" ,
@@ -532,7 +528,7 @@ fn deb(
532
528
let pool_path = repo_path. join ( "pool" ) ;
533
529
std:: fs:: create_dir_all ( & pool_path) . unwrap ( ) ;
534
530
// Copy all the .debs into the pool.
535
- for deb in debs. iter ( ) {
531
+ for deb in & debs {
536
532
std:: fs:: copy ( & deb. path , pool_path. join ( & deb. path . file_name ( ) . unwrap ( ) ) ) . unwrap ( ) ;
537
533
}
538
534
let dists_path = repo_path. join ( "dists" ) ;
@@ -656,19 +652,9 @@ fn deb(
656
652
) ;
657
653
}
658
654
}
659
- Ok ( ( ) )
660
655
}
661
656
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 ) {
672
658
struct Rpm {
673
659
target : RpmTarget ,
674
660
path : PathBuf ,
@@ -686,10 +672,14 @@ fn rpm(
686
672
}
687
673
}
688
674
}
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.
689
679
let targets = [ RpmTarget :: X8664 , RpmTarget :: AArch64 ] ;
690
680
let rpms: Vec < Rpm > = targets
691
681
. iter ( )
692
- . cloned ( )
682
+ . copied ( )
693
683
. map ( |target| {
694
684
let path = rpms_path. join ( format ! (
695
685
"modelfox_{version}_{target}.rpm" ,
@@ -713,9 +703,8 @@ fn rpm(
713
703
std:: fs:: create_dir_all ( & repo_path) . unwrap ( ) ;
714
704
// Create the .repo file.
715
705
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) ) ;
719
708
let repo_file = formatdoc ! (
720
709
r#"
721
710
[modelfox]
@@ -740,7 +729,7 @@ fn rpm(
740
729
let repo_target_path = repo_path. join ( target. to_string ( ) ) ;
741
730
std:: fs:: create_dir_all ( & repo_target_path) . unwrap ( ) ;
742
731
// Copy the .rpm.
743
- for rpm in rpms. iter ( ) {
732
+ for rpm in & rpms {
744
733
if rpm. target == target {
745
734
std:: fs:: copy (
746
735
& rpm. path ,
@@ -760,7 +749,6 @@ fn rpm(
760
749
) ;
761
750
}
762
751
}
763
- Ok ( ( ) )
764
752
}
765
753
766
754
fn build_release ( version : & str ) {
@@ -784,7 +772,7 @@ fn build_release(version: &str) {
784
772
modelfox_cli_path. clone( ) ,
785
773
PathBuf :: from( modelfox_cli_file_name) ,
786
774
) ] ;
787
- tar ( inputs, & output_path) ;
775
+ tar ( & inputs, & output_path) ;
788
776
}
789
777
// libmodelfox
790
778
for target in TARGETS {
@@ -810,7 +798,7 @@ fn build_release(version: &str) {
810
798
PathBuf :: from( target_file_names. libmodelfox_static_file_name) ,
811
799
) ,
812
800
] ;
813
- tar ( inputs, & output_path) ;
801
+ tar ( & inputs, & output_path) ;
814
802
}
815
803
}
816
804
@@ -830,7 +818,7 @@ pub enum Arch {
830
818
X8664 ,
831
819
}
832
820
833
- #[ derive( Clone , Copy , Debug , PartialEq ) ]
821
+ #[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
834
822
pub enum Target {
835
823
AArch64LinuxGnu ,
836
824
AArch64LinuxMusl ,
@@ -843,6 +831,7 @@ pub enum Target {
843
831
}
844
832
845
833
impl Target {
834
+ #[ must_use]
846
835
pub fn arch ( & self ) -> Arch {
847
836
match self {
848
837
Target :: AArch64LinuxGnu | Target :: AArch64LinuxMusl | Target :: AArch64MacOs => {
@@ -856,6 +845,7 @@ impl Target {
856
845
}
857
846
}
858
847
848
+ #[ must_use]
859
849
pub fn target_name ( & self ) -> & ' static str {
860
850
match self {
861
851
Target :: AArch64LinuxGnu => "aarch64-linux-gnu" ,
@@ -869,6 +859,7 @@ impl Target {
869
859
}
870
860
}
871
861
862
+ #[ must_use]
872
863
pub fn rust_target_name ( & self ) -> & ' static str {
873
864
match self {
874
865
Target :: AArch64LinuxGnu => "aarch64-unknown-linux-gnu" ,
@@ -882,6 +873,7 @@ impl Target {
882
873
}
883
874
}
884
875
876
+ #[ must_use]
885
877
pub fn rust_target ( & self ) -> & ' static str {
886
878
match self {
887
879
Target :: AArch64LinuxGnu => "aarch64-unknown-linux-gnu" ,
@@ -907,6 +899,7 @@ pub struct TargetFileNames {
907
899
}
908
900
909
901
impl TargetFileNames {
902
+ #[ must_use]
910
903
pub fn for_target ( target : Target ) -> TargetFileNames {
911
904
match target {
912
905
Target :: X8664LinuxGnu
@@ -959,16 +952,17 @@ fn clean_and_create(path: &Path) {
959
952
std:: fs:: create_dir_all ( path) . unwrap ( ) ;
960
953
}
961
954
962
- fn tar ( input_paths : Vec < ( PathBuf , PathBuf ) > , output_path : & Path ) {
955
+ fn tar ( input_paths : & [ ( PathBuf , PathBuf ) ] , output_path : & Path ) {
963
956
let output_file = std:: fs:: File :: create ( output_path) . unwrap ( ) ;
964
957
let gz = flate2:: write:: GzEncoder :: new ( output_file, flate2:: Compression :: default ( ) ) ;
965
958
let mut tar = tar:: Builder :: new ( gz) ;
966
- for ( path, name) in input_paths. iter ( ) {
959
+ for ( path, name) in input_paths {
967
960
tar. append_path_with_name ( path, name) . unwrap ( ) ;
968
961
}
969
962
tar. finish ( ) . unwrap ( ) ;
970
963
}
971
964
965
+ #[ derive( Clone , Copy ) ]
972
966
enum SignatureType {
973
967
Cleartext ,
974
968
Detached ,
0 commit comments