@@ -24,6 +24,8 @@ pub use self::{
2424 Settings , SettingsBuilder , UpdaterSettings ,
2525 } ,
2626} ;
27+ #[ cfg( target_os = "macos" ) ]
28+ use anyhow:: Context ;
2729use log:: { info, warn} ;
2830pub use settings:: { NsisSettings , WindowsSettings , WixLanguage , WixLanguageConfig , WixSettings } ;
2931
@@ -41,7 +43,7 @@ pub struct Bundle {
4143/// Bundles the project.
4244/// Returns the list of paths where the bundles can be found.
4345pub fn bundle_project ( settings : Settings ) -> crate :: Result < Vec < Bundle > > {
44- let mut bundles = Vec :: new ( ) ;
46+ let mut bundles: Vec < Bundle > = Vec :: new ( ) ;
4547 let package_types = settings. package_types ( ) ?;
4648
4749 let target_os = settings
@@ -56,14 +58,28 @@ pub fn bundle_project(settings: Settings) -> crate::Result<Vec<Bundle>> {
5658 }
5759
5860 for package_type in & package_types {
61+ // bundle was already built! e.g. DMG already built .app
62+ if bundles. iter ( ) . any ( |b| b. package_type == * package_type) {
63+ continue ;
64+ }
65+
5966 let bundle_paths = match package_type {
6067 #[ cfg( target_os = "macos" ) ]
6168 PackageType :: MacOsBundle => macos:: app:: bundle_project ( & settings) ?,
6269 #[ cfg( target_os = "macos" ) ]
6370 PackageType :: IosBundle => macos:: ios:: bundle_project ( & settings) ?,
6471 // dmg is dependant of MacOsBundle, we send our bundles to prevent rebuilding
6572 #[ cfg( target_os = "macos" ) ]
66- PackageType :: Dmg => macos:: dmg:: bundle_project ( & settings, & bundles) ?,
73+ PackageType :: Dmg => {
74+ let bundled = macos:: dmg:: bundle_project ( & settings, & bundles) ?;
75+ if !bundled. app . is_empty ( ) {
76+ bundles. push ( Bundle {
77+ package_type : PackageType :: MacOsBundle ,
78+ bundle_paths : bundled. app ,
79+ } ) ;
80+ }
81+ bundled. dmg
82+ }
6783
6884 #[ cfg( target_os = "windows" ) ]
6985 PackageType :: WindowsMsi => windows:: msi:: bundle_project ( & settings, false ) ?,
@@ -90,6 +106,33 @@ pub fn bundle_project(settings: Settings) -> crate::Result<Vec<Bundle>> {
90106 } ) ;
91107 }
92108
109+ #[ cfg( target_os = "macos" ) ]
110+ {
111+ // Clean up .app if only building dmg or updater
112+ if !package_types. contains ( & PackageType :: MacOsBundle ) {
113+ if let Some ( app_bundle_paths) = bundles
114+ . iter ( )
115+ . position ( |b| b. package_type == PackageType :: MacOsBundle )
116+ . map ( |i| bundles. remove ( i) )
117+ . map ( |b| b. bundle_paths )
118+ {
119+ for app_bundle_path in & app_bundle_paths {
120+ info ! ( action = "Cleaning" ; "{}" , app_bundle_path. display( ) ) ;
121+ match app_bundle_path. is_dir ( ) {
122+ true => std:: fs:: remove_dir_all ( app_bundle_path) ,
123+ false => std:: fs:: remove_file ( app_bundle_path) ,
124+ }
125+ . with_context ( || {
126+ format ! (
127+ "Failed to clean the app bundle at {}" ,
128+ app_bundle_path. display( )
129+ )
130+ } ) ?
131+ }
132+ }
133+ }
134+ }
135+
93136 let pluralised = if bundles. len ( ) == 1 {
94137 "bundle"
95138 } else {
0 commit comments