Skip to content

Commit

Permalink
Validate Linkmaps (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
Itaybre authored Dec 17, 2024
1 parent 87086d3 commit 489bb65
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
55 changes: 55 additions & 0 deletions lib/commands/order_files/validate_linkmaps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
require 'dry/cli'
require 'cfpropertylist'

module EmergeCLI
module Commands
class ValidateLinkmaps < EmergeCLI::Commands::GlobalOptions
desc 'Validate linkmaps in xcarchive'

option :path, type: :string, required: true, desc: 'Path to the xcarchive to validate'

def initialize(network: nil)
@network = network
end

def call(**options)
@options = options
before(options)

Sync do
executable_name = get_executable_name
raise 'Executable not found' if executable_name.nil?

Logger.info "Using executable: #{executable_name}"

linkmaps_path = File.join(@options[:path], 'Linkmaps')
raise 'Linkmaps folder not found' unless File.directory?(linkmaps_path)

linkmaps = Dir.glob("#{linkmaps_path}/*.txt")
raise 'No linkmaps found' if linkmaps.empty?

executable_linkmaps = linkmaps.select do |linkmap|
File.basename(linkmap).start_with?(executable_name)
end
raise 'No linkmaps found for executable' if executable_linkmaps.empty?

Logger.info "✅ Found linkmaps for #{executable_name}"
end
end

private

def get_executable_name
raise 'Path must be an xcarchive' unless @options[:path].end_with?('.xcarchive')

app_path = Dir.glob("#{@options[:path]}/Products/Applications/*.app").first
info_path = File.join(app_path, 'Info.plist')
plist_data = File.read(info_path)
plist = CFPropertyList::List.new(data: plist_data)
parsed_data = CFPropertyList.native_types(plist.value)

parsed_data['CFBundleExecutable']
end
end
end
end
2 changes: 2 additions & 0 deletions lib/emerge_cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
require_relative 'commands/reaper/reaper'
require_relative 'commands/snapshots/validate_app'
require_relative 'commands/order_files/download_order_files'
require_relative 'commands/order_files/validate_linkmaps'

require_relative 'reaper/ast_parser'
require_relative 'reaper/code_deleter'
Expand Down Expand Up @@ -53,6 +54,7 @@ module EmergeCLI

register 'order-files' do |prefix|
prefix.register 'download', Commands::DownloadOrderFiles
prefix.register 'validate-linkmaps', Commands::ValidateLinkmaps
end
end

Expand Down

0 comments on commit 489bb65

Please sign in to comment.