-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
prepare_spm_support.rb
executable file
·130 lines (99 loc) · 4.92 KB
/
prepare_spm_support.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/ruby
require 'fileutils'
shim_header_path = File.expand_path("HexFiendShims/include/")
shim_src_path = File.expand_path("HexFiendShims/src/")
include_path = File.expand_path("HexFiendFramework/include/")
src_path = File.expand_path("HexFiendFramework/src/")
#cleanup
Dir.foreach(src_path) do |f|
fn = File.join(src_path, f)
FileUtils.rm_rf(fn) if f != '.' && f != '..'
end
Dir.foreach(include_path) do |f|
fn = File.join(include_path, f)
FileUtils.rm_rf(fn) if f != '.' && f != '..'
end
Dir.mkdir(File.join(include_path, "HexFiend"))
require 'xcodeproj'
input_project_path = 'HexFiend/HexFiend_2.xcodeproj'
input_project = Xcodeproj::Project.open(input_project_path)
input_target = input_project.targets.select do |target|
target.name == "HexFiend_Framework"
end.first
output_project_path = Pathname(File.expand_path("HexFiendFramework"))
output_project = Xcodeproj::Project.new(output_project_path.join("HexFiend.xcodeproj"))
output_project.build_configurations.each do |config|
config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'
config.build_settings['GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS'] = 'NO'
end
output_target = output_project.new_target(:framework, 'HexFiend', :osx, '10.14')
#headers
output_headers_group = output_project.new_group("Headers")
files = input_target.headers_build_phase.files.to_a.map do |pbx_header_file|
pbx_header_file
end.select do |pbx_header_file|
not(pbx_header_file.file_ref.real_path.to_s.include?("PrivilegedHelper"))
end.each do |pbx_header_file|
file = pbx_header_file.file_ref.real_path
output_file_reference = output_headers_group.new_file(file)
output_build_file = output_target.headers_build_phase.add_file_reference(output_file_reference)
file2 = file.relative_path_from(src_path)
File.symlink(file2, File.join(src_path, File.basename(file)))
file3 = file.relative_path_from(File.join(include_path, "HexFiend"))
File.symlink(file3, File.join(File.join(include_path, "HexFiend"), File.basename(file)))
if pbx_header_file.settings.nil?
else
output_build_file.settings = pbx_header_file.settings
end
end
Dir.each_child(shim_header_path) do |shim_header_filename|
file = Pathname(File.expand_path(shim_header_filename, shim_header_path))
output_file_reference = output_headers_group.new_file(file)
output_build_file = output_target.headers_build_phase.add_file_reference(output_file_reference)
file2 = file.relative_path_from(src_path)
File.symlink(file2, File.join(src_path, File.basename(file)))
file3 = file.relative_path_from(File.join(include_path, "HexFiend"))
File.symlink(file3, File.join(File.join(include_path, "HexFiend"), File.basename(file)))
end
#manual
file = Pathname(File.expand_path("HexFiend/framework/tests/HFTest.h"))
output_file_reference = output_headers_group.new_file(file)
output_target.add_file_references([output_file_reference])
file2 = file.relative_path_from(src_path)
File.symlink(file2, File.join(src_path, File.basename(file)))
file3 = file.relative_path_from(File.join(include_path, "HexFiend"))
File.symlink(file3, File.join(File.join(include_path, "HexFiend"), File.basename(file)))
#sources
output_sources_group = output_project.new_group("Sources")
files = input_target.source_build_phase.files.to_a.map do |pbx_build_file|
pbx_build_file.file_ref.real_path
end.select do |path|
path.to_s.end_with?(".h", ".m", ".mm")
end.select do |path|
not(path.to_s.include?("PrivilegedHelper"))
end.select do |path|
File.exists?(path)
end.each do |file|
output_file_reference = output_sources_group.new_file(file)
output_target.add_file_references([output_file_reference])
file2 = file.relative_path_from(src_path)
File.symlink(file2, File.join(src_path, File.basename(file)))
end
Dir.each_child(shim_src_path) do |shim_source_filename|
file = Pathname(File.expand_path(shim_source_filename, shim_src_path))
output_file_reference = output_sources_group.new_file(file)
output_target.add_file_references([output_file_reference])
file2 = file.relative_path_from(src_path)
File.symlink(file2, File.join(src_path, File.basename(file)))
end
infoPlistFile = Pathname(File.expand_path("HexFiend/framework/HexFiend_Framework-Info.plist")).relative_path_from(output_project_path)
infoPlistPreprocessFile = Pathname(File.expand_path("HexFiend/version.h")).relative_path_from(output_project_path)
output_target.build_configurations.each do |config|
config.build_settings["GCC_PREPROCESSOR_DEFINITIONS"] = ["HF_NO_PRIVILEGED_FILE_OPERATIONS=1"]
config.build_settings["INFOPLIST_PREFIX_HEADER"] = infoPlistPreprocessFile.to_s
config.build_settings["INFOPLIST_FILE"] = infoPlistFile.to_s
config.build_settings["INFOPLIST_PREPROCESS"] = input_target.build_configurations.first.build_settings["INFOPLIST_PREPROCESS"]
config.build_settings["PRODUCT_BUNDLE_IDENTIFIER"] = "com.ridiculousfish.HexFiend-Framework"
config.build_settings["WARNING_CFLAGS"] = "-Wno-conditional-uninitialized"
end
output_project.save(output_project_path.join("HexFiend.xcodeproj"))