从xcodeproj文件中删除构建配置和方案的脚本?

时间:2019-02-27 06:16:28

标签: ios xcode macos command-line

有没有一种方法可以通过脚本/命令行从xcodeproj中删除构建配置和方案,而无需在文本编辑器中进行编辑(project.pbxproj),希望它不会交叉验证并影响构建。

我尝试过xcodeproj,它可以让您将prj读取并表示为yaml,我希望可以在其中编辑yaml并从中生成xcodeproj。

我还尝试从xcshareddata删除方案,但性能仍然没有改善。

shell> xcodebuild -project myproject.xcodeproj -list

# output
Information about project "myproject":
    Targets:
        myproject
        myprojectTests
        ScreensForManPages
        UITestsCA
        ....
        ....
        UITestsUS

    Build Configurations:
        ae-debug
        ae-debug-another-condition
        ae-release
        ae-release-another-condition
        ...
        ...
        250+ build config in between
        ...
        ...
        zw-debug
        zw-debug-another-condition
        zw-release
        zw-release-another-condition

    If no build configuration is specified and -scheme is not passed then "ae-release-another-condition" is used.

    Schemes:
        myproject-ae-debug
        myproject-ae-debug-another-condition
        myproject-ae-release
        ...
        ...
        250+ schemes in between
        ...
        ...
        myproject-zw-debug
        myproject-zw-debug-another-condition
        myproject-zw-release
        myproject-zw-release-another-condition

原因:

我最近继承了一个项目,该项目有250多个构建配置和250多个方案。不幸的是,我的工作机器是旧的mbp,带有运行xxcode 10的osx mojave的hdd无法打开项目。 (.xcodeproj文件约为10mb)

我可以打开项目,但是每次单击彩虹轮都会花费10分钟以上的时间来列出目标,而且我不知道xcode中可以一次删除多个配置/方案的选项。

PS:

Apple script solution xcode无法及时响应

1 个答案:

答案 0 :(得分:1)

开始之前

  
      
  • Xcode需要完全关闭
  •   
  • 如果要手动编辑Xcode项目,请明确   尝试备份之前!
  •   

方案

删除您不需要的方案文件:

/MyApp/MyApp.xcodeproj/xcshareddata/xcschemes

编辑管理列表

/MyApp/MyApp.xcodeproj/xcuserdata/Username.xcuserdatad/xcschemes/xcschememanagement.plist

在文件内部删除不需要的方案(例如MyApp Custom

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>SchemeUserState</key>
    <dict>
        ///////////////////////////////////////////////// remove start
        <key>MyApp Custom.xcscheme_^#shared#^_</key>
        <dict>
            <key>orderHint</key>
            <integer>1</integer>
        </dict>
        ///////////////////////////////////////////////// remove end
        <key>MyApp.xcscheme_^#shared#^_</key>
        <dict>
            <key>orderHint</key>
            <integer>0</integer>
        </dict>
    </dict>
    <key>SuppressBuildableAutocreation</key>
    <dict>
        <key>AFDACD5A2209867B00004213</key>
        <dict>
            <key>primary</key>
            <true/>
        </dict>
    </dict>
</dict>
</plist>

构建配置

/MyApp/SomeProgram.xcodeproj/project.pbxproj

我不建议手动编辑此文件,而是通过Xcode删除构建配置,但是,如果您勇敢地浏览文件,则会看到配置。您还可以使用plist编辑器(plistbuddy等)编辑此文件-删除不需要的文件:

AFADF25C22269ABE000D354D =         {
            buildSettings =             {
     ...
         };
     isa = XCBuildConfiguration;
     name = Custom;
};

您还将看到与其他配置分组的相应UID

AFDACD542209865600004213 =         {
            buildConfigurations =             (
                AFDACD552209865600004213,
                AFDACD562209865600004213,
                AFADF25C22269ABE000D354D ////// remove
            );
            defaultConfigurationIsVisible = 0;
            defaultConfigurationName = Release;
            isa = XCConfigurationList;
        };

现在,当您打开.xcodeproj时,更改应会反映出来。

相关问题