Ruby-скрипт (xcodeproj) для добавления всех исходных файлов к цели
Я пытаюсь запустить игровую площадку в моем проекте. Проблема в том, что проект содержит тысячи тесно связанных файлов. Я создал сенсорный фреймворк Cocoa, который я могу импортировать, чтобы использовать источник приложений на игровой площадке. Единственная проблема заключается в том, что нажатие на каждый исходный файл и добавление его к цели займет несколько часов. Даже при выборе нескольких файлов. (если вы выбираете между группами, опция добавления к цели недоступна).
Есть ли способ использовать библиотеку Ruby xcodeproj для программного добавления всех файлов? Я не знаком с Ruby или той библиотекой, и поэтому поиск точного кода для этого будет непомерно трудоемким. Если нет, то есть ли способ эффективно добавить все файлы в моей рабочей области в эту новую платформу через сам интерфейс XCode?
Если добавление всего источника рабочих пространств в среду оказывается неэффективным решением по другим причинам, существует ли какой-либо способ заставить игровую площадку (с доступом к источнику приложения) работать в этом рабочем пространстве?
2 ответа
Похоже, что new_file
метод делает то, что вам нужно. На GitHub есть проблема, которая показывает, как рекурсивно пройти по каталогу и добавить файлы к цели:
def addfiles (direc, current_group, main_target) Dir.glob(direc) do |item| next if item == '.' or item == '.DS_Store' if File.directory?(item) new_folder = File.basename(item) created_group = current_group.new_group(new_folder) addfiles("#{item}/*", created_group, main_target) else i = current_group.new_file(item) if item.include? ".m" main_target.add_file_references([i]) end end end end
Это не идеально. Например, некоторые имена файлов могут включать ".m" без расширения "m". Но основная идея использования рекурсии - это звук.
def is_resource_group(file)
extname= file[/\.[^\.]+$/]
if extname == '.bundle' || extname == '.xcassets' then
return true
end
return false
end
def add_files_togroup(project, target, group)
if File.exist?(group.real_path)
Dir.foreach(group.real_path) do |entry|
filePath = File.join(group.real_path, entry)
# puts filePath
if filePath.to_s.end_with?(".DS_Store", ".xcconfig") then
# ignore
elsif filePath.to_s.end_with?(".lproj") then
if @variant_group.nil?
@variant_group = group.new_variant_group("Localizable.strings");
end
string_file = File.join(filePath, "Localizable.strings")
fileReference = @variant_group.new_reference(string_file)
target.add_resources([fileReference])
elsif is_resource_group(entry) then
fileReference = group.new_reference(filePath)
target.add_resources([fileReference])
elsif !File.directory?(filePath) then
# 向group中增加文件引用
fileReference = group.new_reference(filePath)
# 如果不是头文件则继续增加到Build Phase中
if filePath.to_s.end_with?(".m", ".mm", ".cpp") then
target.add_file_references([fileReference])
# elsif filePath.to_s.end_with?("pbobjc.m", "pbobjc.mm") then
# target.add_file_references([fileReference], '-fno-objc-arc')
elsif filePath.to_s.end_with?(".pch") then
elsif filePath.to_s.end_with?("Info.plist") && entry == "Info.plist" then
elsif filePath.to_s.end_with?(".h") then
# target.headers_build_phase.add_file_reference(fileReference)
elsif filePath.to_s.end_with?(".framework") || filePath.to_s.end_with?(".a") then
target.frameworks_build_phases.add_file_reference(fileReference)
elsif
target.add_resources([fileReference])
end
# 目录情况下, 递归添加
elsif File.directory?(filePath) && entry != '.' && entry != '..' then
subGroup = group.find_subpath(entry, true)
subGroup.set_source_tree(group.source_tree)
subGroup.set_path(File.join(group.real_path, entry))
add_files_togroup(project, target, subGroup)
end
end
end
end
new_project_obj = Xcodeproj::Project.open(new_proj_fullname)
new_proj_target = new_project_obj.new_target(:application, "Targetname", :ios, "9.0", nil, :objc)
new_group = new_project_obj.main_group.find_subpath("GroupName", true)