关于-ld_classic的脚本

2023-11-12  本文已影响0人  执拗的男孩
#!/usr/bin/ruby
# 运行此脚本 ruby project_version.rb
# 需要先安装xcodeproj
# sudo gem install -n /usr/local/bin xcodeproj
require 'xcodeproj'
require 'json'  

puts "需要传入 xcodeproj 文件路径"
project_path = gets.chomp.strip  
# puts project_path 

puts "需要添加或者删除-ld_classic,1:添加,2:删除"
ld_classic = gets.chomp.strip  
# puts ld_classic 
# 打开项目
project = Xcodeproj::Project.open(project_path)

# 修改构建设置  
project.targets.each do |target|
    # puts target
    target.build_configurations.each do |config|
      if config.build_settings.key?('OTHER_LDFLAGS')
        puts "Config #{config.name} contains OTHER link flags"
        other_ldflags = config.build_settings['OTHER_LDFLAGS']
        if ld_classic == '1' #添加
            if !other_ldflags.include?('-ld_classic')
                other_ldflags.push('-ld_classic')
            end  
        else #删除
            if other_ldflags.include?('-ld_classic')
                other_ldflags.delete('-ld_classic')
                puts "Removed -ld_classic from OTHER_LDFLAGS in config #{config.name}"
            end  
        end
        # puts JSON.pretty_generate(OTHER_LDFLAGS)
      else
        # puts "Config #{config.name} does not contain OTHER link flags"
            #如果不存在OTHER_LDFLAGS 则添加
          if ld_classic == '1' #添加
            if config.build_settings['OTHER_LDFLAGS'].nil? == true
                puts "#{target.name} #{config.name} add $(inherited), -ld_classic"
                config.build_settings['OTHER_LDFLAGS'] = ["$(inherited)", "-ld_classic"]
            end
          end
      end
    end
  end
# 保存项目 
  project.save

上一篇下一篇

猜你喜欢

热点阅读