Set xcode "build setting" from terminal?
Asked Answered
R

3

18

Is there anyway that I can change a setting in xcode without opening xcode? I have an automated xcodebuild / xcrun process going on but I need to change 1 value:

Targets > Select your target > Build Settings > Code Signing Resource Rules Path add : $(SDKROOT)/ResourceRules.plist

I can't find any file where I might put this line...

Redbreast answered 27/11, 2014 at 20:46 Comment(0)
N
32

What You can do is to run:

xcodebuild -target <target> -configuration <configuration> -showBuildSettings

This command shows all the settings that are filled for target and configuration passed. Find the name of the key that contains $(SDKROOT)/ResourceRules.plist (let call it THE_KEY) and then try:

xcodebuild -target <target> -configuration <configuration> THE_KEY=<new_value>

Don't guarantee that it will work.

Naranjo answered 28/11, 2014 at 13:13 Comment(5)
I also need the exactly same thing. Does this work? Can you please confirm.Hyoscyamine
Yeah. Definitely. I have not tried it. After trying, definitely will upvote.Hyoscyamine
Just a small doubt. What should I pass as configuration? Is it "debug" or "Release"?Hyoscyamine
Debug or Release depending on which configuration you'd like to resolve.Naranjo
Yeah. It worked. I am using ANT script to build my Xcode project. I was able to pass the build settings from ANT script. ThanksHyoscyamine
C
5

You could try pbxproj. This is a python module that helps you manipulate Xcode projects with commandline.

The related part to your probelm may be https://github.com/kronenthaler/mod-pbxproj/wiki/flags#add-code-sign

You can pip install pbxproj to have it.

And here's an example provided in the official repo:

from pbxproj import XcodeProject
# open the project
project = XcodeProject.load('myapp.xcodeproj/project.pbxproj')

# add a file to it, force=false to not add it if it's already in the project
project.add_file('MyClass.swift', force=False)

# set a Other Linker Flags
project.add_other_ldflags('-ObjC')

# save the project, otherwise your changes won't be picked up by Xcode
project.save()
Cissiee answered 1/3, 2017 at 13:36 Comment(0)
E
0

If you use CocoaPods, you already have Xcodeproj installed as a dependency: https://github.com/CocoaPods/Xcodeproj

Here's an example that prints the change for each build config (Debug, Release, ...):

#!/usr/bin/env ruby

require "xcodeproj"

project_path = File.join(File.dirname(__FILE__), 'MultiMarkdown', 'build-xcode', 'libMultiMarkdown.xcodeproj')
project = Xcodeproj::Project.open(project_path)
target = project.targets.select { |t| t.name == "libMultiMarkdown" }.first

new_build_dir = '$SYMROOT/$CONFIGURATION'
outdated_configs = target.build_configurations.select { |c| c.build_settings['CONFIGURATION_BUILD_DIR'] != new_build_dir }

if outdated_configs.empty?
  puts "All up-to-date"
  exit
end

outdated_configs.each do |config|
  old = config.build_settings['CONFIGURATION_BUILD_DIR']
  config.build_settings['CONFIGURATION_BUILD_DIR'] = new_build_dir
  puts "- [#{config.name}]:  Changed `CONFIGURATION_BUILD_DIR` from #{old} to #{new_build_dir}"
end

if project.dirty?
  puts "Saving changes ..."
  project.save
end

You can replace the key with CODE_SIGN_RESOURCE_RULES_PATH and modify that. For all targets:

new_path = "path/to/append"
target.build_configurations.each do |config|
  config.build_settings['CODE_SIGN_RESOURCE_RULES_PATH'] += new_path
end

Again, since this is shipped with CocoaPods, if you have a dependency that needs that, you can use almost the same code in a CocoaPods hook.

Endive answered 2/7, 2021 at 13:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.