GithubHelp home page GithubHelp logo

kronenthaler / mod-pbxproj Goto Github PK

View Code? Open in Web Editor NEW
1.2K 1.2K 289.0 1.95 MB

A python module to manipulate XCode projects

License: MIT License

Python 99.84% Makefile 0.16%
cli hacktoberfest library pbxproj python xcode

mod-pbxproj's People

Contributors

12star9 avatar aparajita avatar artoria2e5 avatar chren avatar codacy-badger avatar crankycoder avatar dduan avatar drusy avatar fadookie avatar fuegofro avatar garvankeeley avatar jensayton avatar jialue avatar kayy avatar kronenthaler avatar markshep avatar matanrubin avatar mindeng avatar mrollins avatar petervdmeer avatar piazzean avatar prime31 avatar richy486 avatar sandychapman avatar sptramer avatar tobylobster avatar williamrexhardin avatar yixiaoqingyuz avatar yonitsafir avatar yoojene avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mod-pbxproj's Issues

Needs license

Hi!

We want to use your code in the Firefox build system - can you please add a license? Preferably MPL2.0 or BSD?

thanks!

Unable to Add file in xcode.

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.

method "get_groups_by_name"

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]

How can I get the project target

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

8dfa3268-ab1d-4e64-ad0f-d7f0904b6d2c

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()

39d31f05-c374-42fc-80ce-60fe593197eb

remove_other_ldflags appears to have incorrect key

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)

Specify where you want the settings applied: targets or project

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.

Help for calling add_framework_search_paths to add framework path

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

After processing, get error xcconfig file not found

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.

about flag

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

Ability to create projects from scratch

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 :)

Error on line 131 PBXDict(o)

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

Unity 5 Xcode project and Library Linking

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

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.
8dfa3268-ab1d-4e64-ad0f-d7f0904b6d2c

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()

missing framework

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')

Remove file by path feature request

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

Adding framework example in readme is reporting error

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-)

PBXLegacyTarget not supported

I'm getting warning: unknown PBX type: PBXLegacyTarget when trying to open a project with external build system target :(

Add run script

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>

The header phase is destroyed when modifying a Project

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.

Can mod-pbxproj support xcode5?

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.

Replace the call to the system plutil for a python library

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.

I ask for help about adding the embed frameworks.

hi kronenthaler,

  • Recently, I have been concerned about updating the mod-pbxproj。Today I saw the branch of the 2.0.0 version and learned about it, it seems that did not solve my problem.
  • The following code blocks from an project.pbxproj:

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";
    };`
  • I tried to modify the source code, but failed.I knew it's easy for you to change this. Can you help or guide me to add the embed frameworks?
  • Thank you very much!

Error on import

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),

Python 3.5 Compatibility?

Tried using this package on python 3.5 and it failed trying to import, saying

ImportError: cannot import name 'XcodeProject'

Does not support UTF-8 encoding

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!

Add more command line options

Currently the command line options are very limited (purposely), to add/remove compilation flags.
It would be nice to have some mechanisms to:

  • Add/remove files, groups
  • Add run-scripts to targets
  • Report potential errors:
    • Files in the tree not used in any target
    • Missing files in the tree (file doesn't exist in the filesystem)
    • Duplicated files in the tree.
  • Alternatively, offer some fixing capabilities (see report potential errors). Some times could be interactive.

.bundle file is in incorrect build phase

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.

Disable bit code of project?

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?

Remove target from XCode Project

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.

Cannot add files to a new folder in Xcode

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

Unit test

As this script is growing more complex it's clear that unit test will be necessary to ensure the stability.
This will also allow:

  1. Reduce the testing time for incoming PR's
  2. Show the level of stability of the script (add batch in the readme)
  3. Future proof new developments.
  4. [Done] Integration with travis-ci.
  5. More exposure and encourage use

Not support python3

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

remove_group does not seem to work

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()

How to add a file/folder for a specific target ?

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.

Xcode project add the custom dynamic libraries.

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.