mirror of
https://github.com/jimeh/build-emacs-for-macos.git
synced 2026-02-19 02:36:39 +00:00
feat(icon): add support for Tahoe icons with --tahoe-icon-uri and --tahoe-icon-name options
This commit is contained in:
@@ -156,6 +156,8 @@ Options:
|
|||||||
--build-name NAME Override generated build name
|
--build-name NAME Override generated build name
|
||||||
--dist-include x,y,z List of extra files to copy from Emacs source into build folder/archive (default: COPYING)
|
--dist-include x,y,z List of extra files to copy from Emacs source into build folder/archive (default: COPYING)
|
||||||
--icon-uri URI Local path or URL to a .icns file to replace the default app icon
|
--icon-uri URI Local path or URL to a .icns file to replace the default app icon
|
||||||
|
--tahoe-icon-uri URI Local path or URL to an Assets.car file for macOS 26 icons. Requires --tahoe-icon-name.
|
||||||
|
--tahoe-icon-name NAME Name of the icon in Assets.car to set as CFBundleIconName
|
||||||
--[no-]self-sign Enable/disable self-signing of Emacs.app (default: enabled)
|
--[no-]self-sign Enable/disable self-signing of Emacs.app (default: enabled)
|
||||||
--[no-]archive Enable/disable creating *.tbz archive (default: enabled)
|
--[no-]archive Enable/disable creating *.tbz archive (default: enabled)
|
||||||
--[no-]archive-keep-build-dir
|
--[no-]archive-keep-build-dir
|
||||||
|
|||||||
@@ -229,7 +229,14 @@ class Build
|
|||||||
|
|
||||||
handle_native_lisp(app)
|
handle_native_lisp(app)
|
||||||
|
|
||||||
IconEmbedder.new(app, options[:icon_uri]).embed if options[:icon_uri]
|
if options[:icon_uri] || options[:tahoe_icon_uri] || options[:tahoe_icon_name]
|
||||||
|
IconEmbedder.new(
|
||||||
|
app,
|
||||||
|
icon_uri: options[:icon_uri],
|
||||||
|
tahoe_icon_uri: options[:tahoe_icon_uri],
|
||||||
|
tahoe_icon_name: options[:tahoe_icon_name]
|
||||||
|
).embed
|
||||||
|
end
|
||||||
CLIHelperEmbedder.new(app).embed
|
CLIHelperEmbedder.new(app).embed
|
||||||
CSourcesEmbedder.new(app, @source_dir).embed
|
CSourcesEmbedder.new(app, @source_dir).embed
|
||||||
LibEmbedder.new(
|
LibEmbedder.new(
|
||||||
@@ -1417,53 +1424,92 @@ end
|
|||||||
class IconEmbedder < AbstractEmbedder
|
class IconEmbedder < AbstractEmbedder
|
||||||
include Helpers
|
include Helpers
|
||||||
|
|
||||||
def initialize(app, icon_uri)
|
def initialize(app, icon_uri: nil, tahoe_icon_uri: nil, tahoe_icon_name: nil)
|
||||||
super(app)
|
super(app)
|
||||||
|
|
||||||
@icon_uri = icon_uri
|
@icon_uri = icon_uri
|
||||||
|
@tahoe_icon_uri = tahoe_icon_uri
|
||||||
|
@tahoe_icon_name = tahoe_icon_name
|
||||||
end
|
end
|
||||||
|
|
||||||
def embed
|
def embed
|
||||||
return if @icon_uri.nil? || @icon_uri.strip.empty?
|
handle_icns if present?(@icon_uri)
|
||||||
|
handle_tahoe if present?(@tahoe_icon_uri)
|
||||||
source = resolve_source(@icon_uri)
|
|
||||||
|
|
||||||
unless File.extname(source).downcase == '.icns'
|
|
||||||
fatal 'Icon must be a .icns file'
|
|
||||||
end
|
|
||||||
|
|
||||||
target = File.join(resources_dir, 'Emacs.icns')
|
|
||||||
info 'Replacing application icon...'
|
|
||||||
run_cmd('cp', '-pRL', source, target)
|
|
||||||
ensure
|
ensure
|
||||||
cleanup_download_tmpdir(source)
|
cleanup_tmpdir
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def resolve_source(uri)
|
def present?(val)
|
||||||
if valid_url?(uri)
|
!val.nil? && !val.strip.empty?
|
||||||
download_icon(uri)
|
|
||||||
else
|
|
||||||
path = File.expand_path(uri)
|
|
||||||
fatal "Icon file does not exist: #{path}" unless File.exist?(path)
|
|
||||||
path
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def download_icon(url)
|
def handle_icns
|
||||||
@download_tmpdir = Dir.mktmpdir(%w[emacs-icon .tmp])
|
source = resolve_source(@icon_uri, '.icns', 'icon.icns')
|
||||||
path = File.join(@download_tmpdir, 'icon.icns')
|
target = File.join(resources_dir, 'Emacs.icns')
|
||||||
info "Downloading icon from: #{url}"
|
info 'Replacing application icon (Emacs.icns)...'
|
||||||
|
run_cmd('cp', '-pRL', source, target)
|
||||||
|
source
|
||||||
|
end
|
||||||
|
|
||||||
|
def handle_tahoe
|
||||||
|
fatal '--tahoe-icon-name is required with --tahoe-icon-uri' \
|
||||||
|
unless present?(@tahoe_icon_name)
|
||||||
|
|
||||||
|
source = resolve_source(@tahoe_icon_uri, '.car', 'Assets.car')
|
||||||
|
target = File.join(resources_dir, 'Assets.car')
|
||||||
|
info 'Placing Tahoe Assets.car into Resources...'
|
||||||
|
run_cmd('cp', '-pRL', source, target)
|
||||||
|
|
||||||
|
set_cf_bundle_icon_name(@tahoe_icon_name)
|
||||||
|
source
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_cf_bundle_icon_name(name)
|
||||||
|
info 'Setting CFBundleIconName in Info.plist...'
|
||||||
|
info_plist = File.join(app, 'Contents', 'Info.plist')
|
||||||
|
fatal "Info.plist not found: #{info_plist}" unless File.exist?(info_plist)
|
||||||
|
|
||||||
|
# Use plutil which adds/replaces the key as needed
|
||||||
|
run_cmd(
|
||||||
|
'plutil', '-replace', 'CFBundleIconName', '-string',
|
||||||
|
name, info_plist
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def resolve_source(uri, expected_ext, download_name)
|
||||||
|
file_path = if valid_url?(uri)
|
||||||
|
download_file(uri, download_name)
|
||||||
|
else
|
||||||
|
local = File.expand_path(uri)
|
||||||
|
unless File.exist?(local)
|
||||||
|
fatal "File does not exist: #{local}"
|
||||||
|
end
|
||||||
|
local
|
||||||
|
end
|
||||||
|
|
||||||
|
ext = File.extname(file_path).downcase
|
||||||
|
fatal "Unexpected file type: #{ext} (expected #{expected_ext})" \
|
||||||
|
unless ext == expected_ext
|
||||||
|
|
||||||
|
file_path
|
||||||
|
end
|
||||||
|
|
||||||
|
def tmpdir
|
||||||
|
@tmpdir ||= Dir.mktmpdir(%w[emacs-assets .tmp])
|
||||||
|
end
|
||||||
|
|
||||||
|
def download_file(url, name)
|
||||||
|
path = File.join(tmpdir, name)
|
||||||
|
info "Downloading asset from: #{url}"
|
||||||
run_cmd('curl', '-L#', url, '-o', path)
|
run_cmd('curl', '-L#', url, '-o', path)
|
||||||
path
|
path
|
||||||
end
|
end
|
||||||
|
|
||||||
def cleanup_download_tmpdir(source)
|
def cleanup_tmpdir
|
||||||
return unless @download_tmpdir && source
|
return unless @tmpdir
|
||||||
return unless source.start_with?(@download_tmpdir)
|
|
||||||
|
|
||||||
FileUtils.rm_rf(@download_tmpdir)
|
FileUtils.rm_rf(@tmpdir)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -2155,6 +2201,14 @@ class CLIOptions
|
|||||||
|
|
||||||
def parse!(args)
|
def parse!(args)
|
||||||
parser.parse!(args)
|
parser.parse!(args)
|
||||||
|
|
||||||
|
if options[:tahoe_icon_uri] &&
|
||||||
|
(
|
||||||
|
options[:tahoe_icon_name].nil? ||
|
||||||
|
options[:tahoe_icon_name].strip.empty?
|
||||||
|
)
|
||||||
|
fatal '--tahoe-icon-name is required when --tahoe-icon-uri is specified'
|
||||||
|
end
|
||||||
rescue OptionParser::InvalidOption => e
|
rescue OptionParser::InvalidOption => e
|
||||||
fatal e.message
|
fatal e.message
|
||||||
end
|
end
|
||||||
@@ -2182,6 +2236,8 @@ class CLIOptions
|
|||||||
github_auth: true,
|
github_auth: true,
|
||||||
dist_include: ['COPYING', 'configure_output.txt'],
|
dist_include: ['COPYING', 'configure_output.txt'],
|
||||||
icon_uri: nil,
|
icon_uri: nil,
|
||||||
|
tahoe_icon_uri: nil,
|
||||||
|
tahoe_icon_name: nil,
|
||||||
self_sign: true,
|
self_sign: true,
|
||||||
archive: true,
|
archive: true,
|
||||||
archive_keep: false,
|
archive_keep: false,
|
||||||
@@ -2383,6 +2439,17 @@ class CLIOptions
|
|||||||
'Local path or URL to a .icns file to replace the default app icon'
|
'Local path or URL to a .icns file to replace the default app icon'
|
||||||
) { |v| options[:icon_uri] = v }
|
) { |v| options[:icon_uri] = v }
|
||||||
|
|
||||||
|
opts.on(
|
||||||
|
'--tahoe-icon-uri URI',
|
||||||
|
'Local path or URL to an Assets.car file for macOS 26 icons. ' \
|
||||||
|
'Requires --tahoe-icon-name.'
|
||||||
|
) { |v| options[:tahoe_icon_uri] = v }
|
||||||
|
|
||||||
|
opts.on(
|
||||||
|
'--tahoe-icon-name NAME',
|
||||||
|
'Name of the icon in Assets.car to set as CFBundleIconName'
|
||||||
|
) { |v| options[:tahoe_icon_name] = v }
|
||||||
|
|
||||||
opts.on(
|
opts.on(
|
||||||
'--[no-]self-sign',
|
'--[no-]self-sign',
|
||||||
'Enable/disable self-signing of Emacs.app (default: enabled)'
|
'Enable/disable self-signing of Emacs.app (default: enabled)'
|
||||||
|
|||||||
Reference in New Issue
Block a user