-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove Exported Symbols command (#46)
- Loading branch information
Showing
3 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
require 'dry/cli' | ||
require 'xcodeproj' | ||
|
||
module EmergeCLI | ||
module Commands | ||
module Autofixes | ||
class ExportedSymbols < EmergeCLI::Commands::GlobalOptions | ||
desc 'Remove exported symbols from built binaries' | ||
|
||
option :path, type: :string, required: true, desc: 'Path to the xcarchive' | ||
|
||
# Constants | ||
DEFAULT_EXPORTED_SYMBOLS = %(_main | ||
__mh_execute_header).freeze | ||
EXPORTED_SYMBOLS_FILE = 'EXPORTED_SYMBOLS_FILE'.freeze | ||
EXPORTED_SYMBOLS_PATH = '$(SRCROOT)/EmergeToolsHelperFiles/ExportedSymbols'.freeze | ||
EXPORTED_SYMBOLS_FILE_NAME = 'ExportedSymbols'.freeze | ||
EMERGE_TOOLS_GROUP = 'EmergeToolsHelperFiles'.freeze | ||
|
||
def call(**options) | ||
@options = options | ||
before(options) | ||
|
||
raise 'Path must be an xcodeproj' unless @options[:path].end_with?('.xcodeproj') | ||
raise 'Path does not exist' unless File.exist?(@options[:path]) | ||
|
||
Sync do | ||
project = Xcodeproj::Project.open(@options[:path]) | ||
|
||
# Add the exported symbols file to the project | ||
group = project.main_group | ||
emergetools_group = group.find_subpath(EMERGE_TOOLS_GROUP, true) | ||
emergetools_group.set_path(EMERGE_TOOLS_GROUP) | ||
|
||
unless emergetools_group.find_file_by_path(EXPORTED_SYMBOLS_FILE_NAME) | ||
emergetools_group.new_file(EXPORTED_SYMBOLS_FILE_NAME) | ||
end | ||
|
||
# Create Folder if it doesn't exist | ||
|
||
FileUtils.mkdir_p(File.join(File.dirname(@options[:path]), EMERGE_TOOLS_GROUP)) | ||
|
||
# Create the exported symbols file | ||
path = File.join(File.dirname(@options[:path]), EMERGE_TOOLS_GROUP, EXPORTED_SYMBOLS_FILE_NAME) | ||
File.write(path, DEFAULT_EXPORTED_SYMBOLS) | ||
|
||
project.targets.each do |target| | ||
# Only do it for app targets | ||
next unless target.product_type == 'com.apple.product-type.application' | ||
|
||
target.build_configurations.each do |config| | ||
config.build_settings[EXPORTED_SYMBOLS_FILE] = EXPORTED_SYMBOLS_PATH | ||
end | ||
end | ||
|
||
project.save | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require 'test_helper' | ||
|
||
module EmergeCLI | ||
module Commands | ||
module Autofixes | ||
class ExportedSymbolsTest < Minitest::Test | ||
EMERGE_TOOLS_GROUP = 'EmergeToolsHelperFiles'.freeze | ||
EXPORTED_SYMBOLS_FILE = 'EXPORTED_SYMBOLS_FILE'.freeze | ||
EXPORTED_SYMBOLS_PATH = '$(SRCROOT)/EmergeToolsHelperFiles/ExportedSymbols'.freeze | ||
DEFAULT_EXPORTED_SYMBOLS = %(_main | ||
__mh_execute_header).freeze | ||
|
||
def setup | ||
@command = EmergeCLI::Commands::Autofixes::ExportedSymbols.new | ||
|
||
FileUtils.mkdir_p('tmp/test_autofix_exported_symbols') | ||
FileUtils.cp_r('test/test_files/ExampleApp.xcodeproj', | ||
'tmp/test_autofix_exported_symbols/ExampleApp.xcodeproj') | ||
end | ||
|
||
def teardown | ||
FileUtils.rm_rf('tmp/test_autofix_exported_symbols') | ||
end | ||
|
||
def test_exported_symbols_is_set | ||
options = { | ||
path: 'tmp/test_autofix_exported_symbols/ExampleApp.xcodeproj' | ||
} | ||
|
||
@command.call(**options) | ||
|
||
project = Xcodeproj::Project.open('tmp/test_autofix_exported_symbols/ExampleApp.xcodeproj') | ||
group = project.main_group | ||
|
||
emergetools_group = group.find_subpath(EMERGE_TOOLS_GROUP, false) | ||
assert !emergetools_group.nil? | ||
|
||
project.targets[0].build_configurations.each do |config| | ||
assert_equal EXPORTED_SYMBOLS_PATH, config.build_settings[EXPORTED_SYMBOLS_FILE] | ||
end | ||
|
||
file_path = 'tmp/test_autofix_exported_symbols/EmergeToolsHelperFiles/ExportedSymbols' | ||
assert File.exist?(file_path) | ||
assert_equal DEFAULT_EXPORTED_SYMBOLS, File.read(file_path) | ||
end | ||
end | ||
end | ||
end | ||
end |