@@ -229,6 +229,7 @@ class Build
229229
230230 handle_native_lisp ( app )
231231
232+ IconEmbedder . new ( app , options [ :icon_uri ] ) . embed if options [ :icon_uri ]
232233 CLIHelperEmbedder . new ( app ) . embed
233234 CSourcesEmbedder . new ( app , @source_dir ) . embed
234235 LibEmbedder . new (
@@ -1413,6 +1414,59 @@ class CSourcesEmbedder < AbstractEmbedder
14131414 end
14141415end
14151416
1417+ class IconEmbedder < AbstractEmbedder
1418+ include Helpers
1419+
1420+ def initialize ( app , icon_uri )
1421+ super ( app )
1422+
1423+ @icon_uri = icon_uri
1424+ end
1425+
1426+ def embed
1427+ return if @icon_uri . nil? || @icon_uri . strip . empty?
1428+
1429+ source = resolve_source ( @icon_uri )
1430+
1431+ unless File . extname ( source ) . downcase == '.icns'
1432+ fatal 'Icon must be a .icns file'
1433+ end
1434+
1435+ target = File . join ( resources_dir , 'Emacs.icns' )
1436+ info 'Replacing application icon...'
1437+ run_cmd ( 'cp' , '-pRL' , source , target )
1438+ ensure
1439+ cleanup_download_tmpdir ( source )
1440+ end
1441+
1442+ private
1443+
1444+ def resolve_source ( uri )
1445+ if valid_url? ( uri )
1446+ download_icon ( uri )
1447+ else
1448+ path = File . expand_path ( uri )
1449+ fatal "Icon file does not exist: #{ path } " unless File . exist? ( path )
1450+ path
1451+ end
1452+ end
1453+
1454+ def download_icon ( url )
1455+ @download_tmpdir = Dir . mktmpdir ( %w[ emacs-icon .tmp ] )
1456+ path = File . join ( @download_tmpdir , 'icon.icns' )
1457+ info "Downloading icon from: #{ url } "
1458+ run_cmd ( 'curl' , '-L#' , url , '-o' , path )
1459+ path
1460+ end
1461+
1462+ def cleanup_download_tmpdir ( source )
1463+ return unless @download_tmpdir && source
1464+ return unless source . start_with? ( @download_tmpdir )
1465+
1466+ FileUtils . rm_rf ( @download_tmpdir )
1467+ end
1468+ end
1469+
14161470class LibEmbedder < AbstractEmbedder
14171471 attr_reader :lib_sources
14181472 attr_reader :extra_libs
@@ -2127,6 +2181,7 @@ class CLIOptions
21272181 github_src_repo : nil ,
21282182 github_auth : true ,
21292183 dist_include : [ 'COPYING' , 'configure_output.txt' ] ,
2184+ icon_uri : nil ,
21302185 self_sign : true ,
21312186 archive : true ,
21322187 archive_keep : false ,
@@ -2323,6 +2378,11 @@ class CLIOptions
23232378 'folder/archive (default: COPYING)'
23242379 ) { |v | options [ :dist_include ] = v }
23252380
2381+ opts . on (
2382+ '--icon-uri URI' ,
2383+ 'Local path or URL to a .icns file to replace the default app icon'
2384+ ) { |v | options [ :icon_uri ] = v }
2385+
23262386 opts . on (
23272387 '--[no-]self-sign' ,
23282388 'Enable/disable self-signing of Emacs.app (default: enabled)'
0 commit comments