kronenthaler / mod-pbxproj Goto Github PK
View Code? Open in Web Editor NEWA python module to manipulate XCode projects
License: MIT License
A python module to manipulate XCode projects
License: MIT License
Tried using this package on python 3.5 and it failed trying to import, saying
ImportError: cannot import name 'XcodeProject'
i see the message
can you add ttf, caf
hi kronenthaler,
I only can write the basic python, now I have a problem, I need your help.
The problem is the Title Description。
For example:
/* Begin PBXCopyFilesBuildPhase section /
96AABB551CC874F1000DF362 / Embed Frameworks / = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
96AABB541CC874F1000DF362 / xxx.framework in Embed Frameworks /,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
/ End PBXCopyFilesBuildPhase section */
Like this situation, how to do?
group = project.get_or_create_group("Hola")
project.remove_group_by_name("Hola")
project.save()
is it remove "Hola" group?
if not , please teach me the right writing way
PlistWriter was never meant to be exposed in the public interface of plistlib, so it has been renamed in python 3 implementation. You can get away with just referencing _PlistWriter, but that doesn't seem viable long-term.
See:
https://hg.python.org/cpython/file/2.7/Lib/plistlib.py#l230
https://hg.python.org/cpython/file/3.4/Lib/plistlib.py#l454
Is it possible to disable bit code of project with this thing?
I think I have a version of this from ~6 months ago. Should I update to a newer version for Xcode 7?
In the readme, when using below line:
project.add_file_if_doesnt_exist('System/Library/Frameworks/AdSupport.framework', parent=frameworks, weak=True, tree='SDKROOT')
We'll receive error that "NameError: global name 'frameworks' is not defined".
Changed the line into:
project.add_file_if_doesnt_exist('System/Library/Frameworks/AdSupport.framework', parent='frameworks', weak=True, tree='SDKROOT')
And it worked. 8-)
You can close this issue, just wanted to ask this question.
How can I get the project target. because when I use this script to add files to Pods project, the code seems not work, But if I drag the folder to Pods project, it can works.
This is my code, the file exactly add to Pods folder but it seems not work
project = XcodeProject.Load(pbxproj_file_path)
project.remove_group_by_name('UIKit', True)
project.save()
if production:
main_group = project.get_groups_by_name('DKNightVersion')[0]
uikit_group = project.get_or_create_group('UIKit', None, main_group)
else:
main_group = project.get_or_create_group('DKNightVersion')
pod_group = project.get_or_create_group('Pod', None, main_group)
class_group = project.get_or_create_group('Classes', None, pod_group)
uikit_group = project.get_or_create_group('UIKit', None, class_group)
groups = json.load(open(json_file_path))
for group, files in groups.iteritems():
new_group = project.get_or_create_group(group, None, uikit_group)
for f in files:
project.add_file(f, new_group)
project.save()
Hi there,
nice script! Although i have been missing the remove file feature, it was only possible with its UUID known. So i came up with my solution. You can improve / include it freely.
def get_file_id_by_path(self, f_path):
for k, v in self.objects.iteritems():
if str(v.get('path')) == f_path:
return k
return 0
def remove_file_by_path(self, f_path, recursive=True):
id = self.get_file_id_by_path(f_path)
if id != 0:
self.remove_file(id, recursive=recursive)
return
Cheers,
BuXY
exceuse me, kronenthaler, ask your a question.
i want ask a quesiton.
in xcode project (kronenthaler's python script). how to add some flag, like -ObjC, Preprocessor Macros, Enable C++ Exception? use which method?
please forgive my poor english, thank you a lot, kronenthaler
add_other_ldflags works fine, however remove_other_ldflags doesn't work.
My XCode version: Version 4.5.2 (4G2008a)
I was trying to add a plist file to a xcode project through command line, some of the blogs suggested to edit the project.pbxproj file. I searched about the project.pbxproj file but was not able to get much information about it. Can any one let me know what is use of project.pbxproj file in xcode ? How to add entries to it ?
I am using https://github.com/kronenthaler/mod-pbxproj repo to work with it.
the script that i wrote is as follows :
import sys
import os
from mod_pbxproj import XcodeProject
def addPlistInProject(corodova_proj_name,xcode_proj_name,plist_file_name):
print "Cordova project name : "+corodova_proj_name
present_directory = os.getcwd()
path_to_xcode_proj = present_directory+'/'+corodova_proj_name +'/platforms/ios/'+xcode_proj_name+'.xcodeproj/project.pbxproj';
print "Xcode Project Path : "+path_to_xcode_proj
project = XcodeProject.Load(path_to_xcode_proj)
new_group = project.get_or_create_group('new group')
project.add_file(plist_file_name);
if name == "main":
corodova_proj_name = sys.argv[1]
xcode_proj_name = sys.argv[2]
plist_file_name = sys.argv[3]
print "Xcode Project Name = : "+ xcode_proj_name
print "Plist File Path = : "+plist_file_name
addPlistInProject(corodova_proj_name,xcode_proj_name,plist_file_name
I will be invoking the script as python myscript.py hello HelloWorld manisha-rules_camdo.plist
myscript.py is the script I wrote, hello is the existing cordova project and HelloWorld is the Xcode project created by using cordova platform add iOS command.
Command Sequence I will be following will be as follows : cordova create hello com.example.hello HelloWorld
cordova platform add iOS
py myscript.py hello HelloWorld manisha-rules_camdo.plist
hello is the name of cordova project. HelloWorld name of iOS Target.
Currently when you run the commandline tool with -af
it changes the settings in all targets and in the project. This is extremely redundant.
When you specify f.i. HEADER_SEARCH_PATHS as \$(inherited):/usr/local/include
, Xcode will eventually expand it into /usr/local/include /usr/local/include
.
That becomes extremely tedious, when you have multiple search paths.
Hey I am going to pop this open as a new issue. Basically I just installed the latest version and I am getting the following error when I try to run it.
File "Assets/Editor/post_process.py", line 4, in
from mod_pbxproj import XcodeProject
File "/Users/bueno/Developer/sm/MightyIO-Unity-iOS-Binding/MightyIO-UnityDemo/Assets/Editor/mod_pbxproj.py", line 131
return PBXDict(o)
Apologies this info might not be super helpful I am pretty new to Python
Hi,
I'm trying to integrate Crashlytics with Unity and part of the install process is to run a script as the last step of the build phase. I can't find a way to do this with the current mod-pbxproj code.
The run script is a very simple file:
/bin/sh
./Crashlytics.framework/run <api_key>
As this script is growing more complex it's clear that unit test will be necessary to ensure the stability.
This will also allow:
this example is unlinkd framework
project.add_file('System/Libray/UIKit.framework', tree='SDKROOT')
in my case
project.add_file('System/Library/Frameworks/StoreKit.framework', tree='SDKROOT')
Using Python 2.7.6.
Error is: NameError: name 'PBXSourcesBuildPhase' is not defined
Traceback (most recent call last):
File "zzz.py", line 3, in <module>
from mod_pbxproj import XcodeProject
File "/Users/xx/Dropbox/vv/scripts/yy/mod_pbxproj.py", line 148, in <module>
class PBXFileReference(PBXType):
File "/Users/xx/Dropbox/vv/scripts/yy/mod_pbxproj.py", line 162, in PBXFileReference
'.swift': ('sourcecode.swift', PBXSourcesBuildPhase),
I'm getting warning: unknown PBX type: PBXLegacyTarget
when trying to open a project with external build system target :(
i find a issue, this method "get_groups_by_name" also cannot use it, like this:
new_group1 = pbproject.get_groups_by_name('Test_Group')
pbproject.remove_group(new_group1.id)
error: Traceback (most recent call last):
File "/Users/liangma/QinMoon/Editor_pbxproj/Build_pbxproj.py", line 61, in
pbproject.remove_group(new_group1.id)
AttributeError: 'list' object has no attribute 'id'
[Finished in 0.3s with exit code 1]
Hey. I cannot for the life of me figure out why XcodeProject will not import. the class is defined and mod_pbxproj is installed. Any ideas?
I know that this project mainly meant to be used in read-modify-write fashion. Is there anything in particular stopping us from actually creating projects from scratch?
When I'm just trying to create XcodeProject instance directly by doing prj = XcodeProject()
I get crash on for k, v in self.objects.iteritems():
here with objects being NoneType. It's probably just a minor thing :) Should I expect anything major?
PS. This sort of feature is useful for project generators in build systems :)
We try to load swift framework in OC project,We found that the framework add as 'PBXSourcesBuildPhase' type can be load success.So I want to know is there any way can add a framework file as 'PBXSourcesBuildPhase'?
you can write demo?
Hello,
Thank for your script, it works like a charm.
Being able to add files and references to my project, I would love to add a file for a specific target.
The following code is adding the files to all my targets (for example the main one and the Test one).
for phase in phases:
build_file = PBXBuildFile.Create(file_ref, weak=weak)
phase.add_build_file(build_file)
results.append(build_file)
My problem is that I am not able to find anything in the phase object that can be linked to a target name.
I am missing something ?
Thanks in advance.
Hi ,kronenthaler.
I use mod-pbxproj to parse the pbxproject file of xcode5 project , there's some error happend ,such as follows:
b'D:/project.pbxproj: Property List error: Cannot parse a NULL or zero-length data / JSON error: No value.\r\n'。
I think its because mod-pbxproj only can support xcode 4, can you update this project so that it can support xcode5.
Well it's curious, that this never popped up, but I guess most people don't write libraries.
$ grep PBXHeadersBuildPhase A.xcodeproj/project.pbxproj
/* Begin PBXHeadersBuildPhase section */
isa = PBXHeadersBuildPhase;
/* End PBXHeadersBuildPhase section */
$ python -m mod_pbxproj -b -af "FOO=1" A.xcodeproj All
$ grep PBXHeadersBuildPhase A.xcodeproj/project.pbxproj
$
That's pretty bad.
Using add_file() to add .bundle to pbxproj will render the bundle not included in build phase.
See mod_pbxproj.py, line 192
if os.path.isdir(self.get('path')) and ext != '.framework':
it only take cares of .framework. I changed it to
if os.path.isdir(self.get('path')) and ext != '.framework' and ext != '.bundle':
Problem solved.
project.remove_group_by_name("Hola")
Does not remove the group "Hola".
And the following code creates the group "Hola" and leaves it present in the project.
Shouldn't it remove it too?
group = project.get_or_create_group("Hola")
project.remove_group(group)
project.save()
Hi!
We want to use your code in the Firefox build system - can you please add a license? Preferably MPL2.0 or BSD?
thanks!
I use python2.7 in OSX and my projectPath include Chinese so I add # coding=utf-8
to my script.Then script run failed with error described
Traceback (most recent call last):
File "mergePbxproj.py", line 8, in <module>
project.save()
File "/Library/Python/2.7/site-packages/mod_pbxproj-1.3.1-py2.7.egg/mod_pbxproj/mod_pbxproj.py", line 1265, in save
self.save_new_format(file_name, sort)
File "/Library/Python/2.7/site-packages/mod_pbxproj-1.3.1-py2.7.egg/mod_pbxproj/mod_pbxproj.py", line 1327, in save_new_format
self._printNewXCodeFormat(out, self.data, '', enters=True, sort=sort)
File "/Library/Python/2.7/site-packages/mod_pbxproj-1.3.1-py2.7.egg/mod_pbxproj/mod_pbxproj.py", line 1420, in _printNewXCodeFormat
self._printNewXCodeFormat(out, value, '\t\t' + deep, enters=section[1])
File "/Library/Python/2.7/site-packages/mod_pbxproj-1.3.1-py2.7.egg/mod_pbxproj/mod_pbxproj.py", line 1427, in _printNewXCodeFormat
self._printNewXCodeFormat(out, root[key], '\t' + deep, enters=enters)
File "/Library/Python/2.7/site-packages/mod_pbxproj-1.3.1-py2.7.egg/mod_pbxproj/mod_pbxproj.py", line 1468, in _printNewXCodeFormat
out.write('"' + XcodeProject.addslashes(root.encode("utf-8")) + '"')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe7 in position 14: ordinal not in range(128)
I am new to python and I hope you could help me with the issue,thx!
I've noticed that for the Xcode (v6.2) projects generated by Unity 5 (v5.0.0f4) add_file_if_doesnt_exist()
no longer appears to be adding some frameworks to the list of libraries linked with the binary under the Build Phases tab of the Xcode project. The references to the frameworks to be added exist under the PBXFileReference
section of the project.pbxproj but they don't exist under the PBXBuildFile
section. I've seen this when adding the AdSupport.framework:
project_path = '<project_path>/Unity-iPhone.xcodeproj/project.pbxproj'
framework_path = '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/AdSupport.framework'
framework_group = project.get_or_create_group('Frameworks')
project = XcodeProject.Load(project_path)
project.add_file_if_doesnt_exist(framework_path, tree='SDKROOT', parent=framework_group )
The create_build_files argument defaults to True and the weak argument defaults to False.
I think what's happening is that only the objects under the PBXFileReference
section of the project.pbxproj are being checked for the existence of the framework in the project where it should instead be checking both the reference and build sections. I believe that add_file_if_doesnt_exist()
should work like the following:
if (framework exists in PBXFileReference) {
if (create_build_files == true) {
if (!framework exists in PBXBuildFile) {
create build files entry in project.pbxproj for the framework
}
}
return [] // not sure about this in the case that the build files entry is added
}
return result from calling add_file()
How can I get the project target. because when I use this script to add files to Pods project, the code seems not work, But if I drag the folder to Pods project, it can works. This is my code
project = XcodeProject.Load(pbxproj_file_path)
project.remove_group_by_name('UIKit', True)
project.save()
if production:
main_group = project.get_groups_by_name('DKNightVersion')[0]
uikit_group = project.get_or_create_group('UIKit', None, main_group)
else:
main_group = project.get_or_create_group('DKNightVersion')
pod_group = project.get_or_create_group('Pod', None, main_group)
class_group = project.get_or_create_group('Classes', None, pod_group)
uikit_group = project.get_or_create_group('UIKit', None, class_group)
groups = json.load(open(json_file_path))
for group, files in groups.iteritems():
new_group = project.get_or_create_group(group, None, uikit_group)
for f in files:
project.add_file(f, new_group)
project.save()
hi kronenthaler,
96F0E2B21CC8BBEC00C2DD4A /* xsdkFramework.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 96F0E2AC1CC8BBE100C2DD4A /* xsdkFramework.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
`/* Begin PBXCopyFilesBuildPhase section */
96AABB4B1CC871BB000DF362 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
96F0E2B21CC8BBEC00C2DD4A /* xsdkFramework.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */`
`963754661B413BF500F67766 /* XsdkIMP */ = {
isa = PBXNativeTarget;
buildConfigurationList = 963754731B413BF500F67766 /* Build configuration list for PBXNativeTarget "XsdkIMP" */;
buildPhases = (
963754671B413BF500F67766 /* Sources */,
9637546C1B413BF500F67766 /* Frameworks */,
9637546E1B413BF500F67766 /* Resources */,
96AABB4B1CC871BB000DF362 /* Embed Frameworks */,
);
buildRules = (
);
dependencies = (
);
name = "XsdkIMP";
productName = XsdkIMP;
productReference = 963754761B413BF500F67766 /* XsdkIMP.app */;
productType = "com.apple.product-type.application";
};`
when use python3, it say that:
from mod_pbxproj import XcodeProject
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named 'mod_pbxproj'
Great and useful project, but support python3 will be better
Currently the command line options are very limited (purposely), to add/remove compilation flags.
It would be nice to have some mechanisms to:
not support xcode5.0
Just started happening recently (Xcode 7.3 maybe?).
My project has a single xcconfig file, and after processing with mod-pbxproj to add files, Xcode fails to build as it claims the xcconfig "path couldn't be resolved, it may be missing."
Prior to processing with mod-pxproj, the build does not complain about a missing xcconfig.
I found that after I open the project if I trigger the project to resave, then quit and restart Xcode, I no longer get the error.
For now, anyone know a way to get Xcode to open a project and re-save it, without doing this manually? To trigger the save, one has to make a project modification, it isn't enough to simply open and close the project in Xcode.
Unrelated:
Skimming the code in regards to xcconfig, I notice this line is incorrect (although would have no effect as it is in comment section):
https://github.com/kronenthaler/mod-pbxproj/blame/master/mod_pbxproj/mod_pbxproj.py#L1304
The string
'Build configuration list for PBXProject "Unity-iPhone"'
should have correct file name, not Unity-iPhone
Still investigating, but reporting in case someone can direct me to an answer.
new_group = project.get_or_create_group('new_group')
group = project.get_or_create_group('classes')
new_group.add_child(group)
project.add_file('file.m', group)
project.save()
These code doesn't create a subfolder in new_group
folder, it just create a folder in the root of a project... How can I make the classes
group under the new_group
folder
Hello:
I am new to python.
Can you please help me in calling add_framework_search_paths method?
I called it as follows
project.add_framework_search_paths(appPath+'/Plugins/iOS/Frameworks', true)
here appPath, I am setting with some value.
but it does not work
Thanks,
Ashwani
Currently this project has a hard dependency on a system command (plutil) it'd be nice to have the ability to switch it a python library.
Reason 1: quick patches could be written in a non-mac computer.
Reason 2: travis automation could be not running on a mac-environment or it could not have access to the system commands.
Hello:
Can you help me in how to enable ARC for some files using this script?
See the below code:
I believe it should be 'OTHER_LDFLAGS', not 'OTHER_LD_FLAGS'
def add_other_ldflags(self, flags):
return self.add_flag('OTHER_LDFLAGS', flags)
def remove_other_ldflags(self, flags):
return self.remove_flag('OTHER_LD_FLAGS', flags)
Hi kronenthaler,
This is more a question than a request.
Is there any way to remove a target from the xcode project ?
Or need I to develop some thing in PBXNativeTarget, PBXVariantGroup, PBXContainerItemProxy, PBXTargetDependency, ...
cause a target is referenced in all those sections.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.