A python module to manipulate XCode projects

Overview
GitHub Workflow Status (branch) Codacy branch coverage Codacy grade PyPI PyPI - Downloads PyPI - License

pbxproj

This module can read, modify, and write a .pbxproj file from an Xcode 4+ projects. The file is usually called project.pbxproj and can be found inside the .xcodeproj bundle. Because some task cannot be done by clicking on an UI or opening Xcode to do it for you, this python module lets you automate the modification process.

How to use it

The typical tasks with an Xcode project are adding files to the project and setting some standard compilation flags. It can be achieved with a simple snippet like this:

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

That's it. More details about available API's visit the wiki.

Installation

For installation instructions visit the wiki

CLI

For instructions and commands available visit the wiki

Documentation

For general documentation, visit the wiki. For technical documentation, the public functions are documented and contains details about what is expected.

Reporting bugs

Did you find a bug? Too bad, but we want to help you, we need you to:

  • Check you are running python3 and installed the package using the pip3 command.
  • Provide as many details about the error you are having.
  • If possible provide a sample project.pbxproj to reproduce the steps
  • If possible, try the sequence of steps on Xcode and provide the project.pbxproj generated by Xcode.

We cannot help you if your issue is a title: "it does not work". Or if there is no sequence of steps to reproduce the error. Those kind of issues will be ignored or closed automatically.

Contributing

Do you want to fix an issue yourself? Great! some house rules:

  • Provide a description of what problem you are solving, what case was not being taking into account
  • Provide unit tests for the case you have fixed. Pull request without unit test or PRs that decrease the coverage will not be approved until this changes.
  • Adhere to the coding style and conventions of the project, for instance, target_name is used to specify the target across all functions that use this parameter. Changes will be requested on PRs that don't follow this.
  • Write descriptive commit messages.

License

This project is licensed using MIT license.

Issues
  • remove_group does not seem to work

    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()
    
    bug 
    opened by da-mian 20
  • Unity 5 Xcode project and Library Linking

    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()       
    
    bug 
    opened by jp-at-work 16
  • How can I get the project target

    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

    opened by draveness 16
  • Enhancement Request: cli show/list content of pbxproj file

    Enhancement Request: cli show/list content of pbxproj file

    Hi,

    I was looking for a way to print out the content of a pbxproj file in a human readable format and came across this project. It would be awesome if I could use this project to print out information about build targets like the src files required, flags, etc. I don't believe this is currently supported by the cli program or the library.

    Thanks!

    enhancement 
    opened by kwhat 12
  • 'PBXBuildFile' object has no attribute 'fileRef'

    'PBXBuildFile' object has no attribute 'fileRef'

    I have the problem, if the module is adding flags and the project.pbxproj has errors like

    9D1494321F73F8AB0078CFF8 /* (null) in Sources */ = {isa = PBXBuildFile; };

    i'm getting

    'PBXBuildFile' object has no attribute 'fileRef'

    Is it possible to ignore these entries, or to remove this entries automatically from the file?

    enhancement 
    opened by erdnussflips 9
  • Is it possible to add a file to multiple targets?

    Is it possible to add a file to multiple targets?

    I'm developing a script to generate boilerplate code to my project. I have two targets (ag: Debug and Production) and I need to add files to these ones only. Right now we have the option to specify one target or add to all. Is it possible change the target to accept an array?

    enhancement 
    opened by leoneparise 8
  • AttributeError: 'NoneType' object has no attribute 'isa'

    AttributeError: 'NoneType' object has no attribute 'isa'

    I'm using mod-pbxproj to manipulate an Xcode project file generated by Unity. In the script it removes a file from the project then adds some others, but it's raising the exception when it tries to add the first of those additional files. If the deletion is skipped then it works fine. It's quite a complicated project file, but I've reduced it down to a smaller test case and worked out that the presence of a file assigned to the "Unity-iPhone Tests" target triggers this problem - if that's removed from the project file then the script works.

    I've attached a tarball containing two example project files (one exhibiting this behaviour and one that doesn't) and a test script demonstrating the issue:

    bug.tar.gz

    bug answered 
    opened by markshep 7
  • [FEAT] Support XML format of pbxproj

    [FEAT] Support XML format of pbxproj

    Hello there! The issue arises in the XCode projects generated via openFrameworks (https://github.com/openframeworks/openFrameworks) projectGenerator that generates projects in XML format that it creates by modifying this template: https://github.com/openframeworks/openFrameworks/blob/b674f7ec1f41d8f0fcfea86e3d3d3df3e9bdcf36/scripts/templates/osx/emptyExample.xcodeproj/project.pbxproj

    If you open a project in XCode and then save it with some minimal change, it'll open, but without it it'll crash, apparently expecting JSON (?). Would be glad if anyone has anything to tell on this! Thanks.

    enhancement 
    opened by yeswecan 7
  • [BUG] add_folder always resolves paths as absolute

    [BUG] add_folder always resolves paths as absolute

    Describe the bug add_folder method in class ProjectFiles add absolute path to PBXGroup.

    I used the new script to provide a method like the old "apply_mods" , I found the add_folder method in class ProjectFiles add wrong path to PBXGroup, which expect the relpath,but absolute path wrote.

    System information

    1. pbxproj version used: 2.11
    2. python version used: python 3.8
    3. Xcode version used: 11.2.1
    bug not-enough-info 
    opened by u8-xiaohei 7
  • Variant groups

    Variant groups

    This is an amended version of the variant groups branch. I'm not sure if this is the best way to submit changes.

    While testing it, I noticed a few issues which are fixed in this pull request:

    • attempting to add a PBXVariantGroup as a child of a PBXGroup gives an exception as it isn't one of the expected types.
    • adding multiple localisation files adds duplicate PBXBuildFiles for the variant group, which causes builds to fail as Xcode tries to copy the same file repeatedly.

    With these two fixes, I can confirm that the variant groups work as expected for our use case (localising the app icon name by localising the Info.plist file).

    But...

    One thing I did find is that the system will automatically add the variants to any existing variant group that exists with the same name - even when that variant group is for a different target. For example, our project has a 'tests' target that contains a InfoPlist.strings variant group that's stored in a separate folder. With the system as it is, any InfoPlist.strings files we add to the project get added to this variant group - even though we want to add them for our main target. This code in question is this:

    for variant in self.objects.get_objects_in_section(u'PBXVariantGroup'):
        if variant.name == expected_name:
    

    I don't entirely understand how all of this works, but to me this seems like the incorrect - or at least, unexpected behaviour. I believe you should be able to have multiple variant groups for the same file. I've worked around this by removing the exiting variant group.

    I also noticed that adding a strings file that's outside the project causes an exception on this line in ProjectFiles.py - I have't fixed this:

    library_path = os.path.join(u'$(SRCROOT)', os.path.split(file_ref.path)[0])

    AttributeError: 'PBXVariantGroup' object has no attribute 'path'

    opened by eAi 7
  • [BUG]

    [BUG]

    Describe the bug I'm trying to add a Run Script Phase using: project.add_run_script('ls -l .') But this results in a "Workspace integrity" - "Couldn't load project"

    System information

    1. pbxproj version used: 2.10.2
    2. python version used: 2.7.16
    3. Xcode version used: 11.4.1

    To Reproduce

    from pbxproj import XcodeProject
    # open the project
    project = XcodeProject.load('starter.xcodeproj/project.pbxproj')
    
    print("adding pre-build script")
    #project.add_run_script('ls -l .', 'starter', True)
    project.add_run_script('ls -l .')
    
    # save the project, otherwise your changes won't be picked up by Xcode
    project.save()
    

    Expected behavior I expected a working project

    invalid not-enough-info 
    opened by gomerser 6
  • Speed up saving large projects

    Speed up saving large projects

    Large projects can be very slow to save. I have a 10 MB project file that took about 20 minutes to save. Upon profiling the save operation with cProfile it became clear it was spending most of its time in PBXObjects.__getitem__ and PBXBuildFile._get_section. These both perform lookups over that are linear in the size of the project for each call, leading to (at least) an n^2 algorithm. While most of the time we need to perform the lookups like this (since people could have modified the project data structures in arbitrary ways) if we make the simplifying assumption that the project won't change during saves, we can greatly speed these operations up by pre-computing a mapping from the ID we care about to the object we're looking for and make each of these calls constant time.

    This optimization brings the save time for the same project down to just 2.3 seconds on my machine (4 orders of magnitude faster). This would likely also help in the case of https://github.com/kronenthaler/mod-pbxproj/issues/247.

    opened by FuegoFro 6
  • bundle format unrecognized, invalid, or unsuitable

    bundle format unrecognized, invalid, or unsuitable

    I try to use this moudle to package My XcodeProject , I use the xcodebuild command to build it.

    I used to use the 1.0.0 , it works well , but today I updated the moudle , the error code like this :
    **``` Signing Identity: "iPhone Developer: ruiqi shi (5UYM39ZA5R)"

    /usr/bin/codesign --force --sign 0B6CCF1493AF0B415323309622B1AB1EE1456A8D --preserve-metadata=identifier,entitlements --timestamp=none 
    

    /Users/chenxi/autopack_lzws/ios/build/blank.proj_01GameCHINA/project/build/Release-iphoneos/TheThreeKingdoms.app/Frameworks/MobileCoreServices.framework /Users/chenxi/autopack_lzws/ios/build/blank.proj_01GameCHINA/project/build/Release-iphoneos/TheThreeKingdoms.app/Frameworks/MobileCoreServices.framework: bundle format unrecognized, invalid, or unsuitable Command /usr/bin/codesign failed with exit code 1

    
    I add the system Framework like this :
    
    

    framework = 'System/Library/Frameworks/' + framework file_options = FileOptions(weak=True) parent = XcodeProject.get_or_create_group("Frameworks") XcodeProject.add_file(framework,parent=parent,tree='SDKROOT',force=False,file_options=file_options)

    opened by chenxi92 6
  • [BUG] Error in openstep_parser: string index out of range

    [BUG] Error in openstep_parser: string index out of range

    Describe the bug I'm trying to use the default sample code on the homepage just to check how mod-pbxproj works, however I stumbled upon this error:

    Traceback (most recent call last): File "xcode_python_setup.py", line 3, in project = XcodeProject.load('../myapp/myapp.xcodeproj/project.pbxproj') File "/Library/Python/2.7/site-packages/pbxproj/XcodeProject.py", line 90, in load tree = osp.OpenStepDecoder.ParseFromFile(open(path, 'r')) File "build/bdist.macosx-10.15-x86_64/egg/openstep_parser/openstep_parser.py", line 42, in ParseFromFile File "build/bdist.macosx-10.15-x86_64/egg/openstep_parser/openstep_parser.py", line 46, in ParseFromString File "build/bdist.macosx-10.15-x86_64/egg/openstep_parser/openstep_parser.py", line 51, in _parse IndexError: string index out of range

    System information

    1. pbxproj version used: 3.2.0
    2. python version used: 3.6.12
    3. Xcode version used: 12.0 (12A7209)

    To Reproduce Steps to reproduce the behavior:

    1. Created a .py file with this code

    from pbxproj import XcodeProject project = XcodeProject.load('../myapp/myapp.xcodeproj/project.pbxproj') project.save()

    1. On the terminal, cd to a related folder and ran: "python xcode_python_setup.py"
    2. See error

    Expected behavior Just expected to see a clear python command without any errors.

    bug invalid 
    opened by VitorMMOliveira 6
  • Update ProjectFiles to support xcframeworks

    Update ProjectFiles to support xcframeworks

    Adding support for Apple-native xcframework file types

    opened by masterrex 6
  • Variant groups

    Variant groups

    Attempt to solve #113. Needs confirmation from @st3fan. How to use:

    # load project as usual
    project.add_file('en.lproj/<file1>.strings', ...)
    project.add_file('en.lproj/<file2>.strings', ...)
    project.add_file('en.lproj/<file3>.strings', ...)
    

    Maybe i will add a helper method to add a full folder later on, after confirm that this works as expected.

    opened by kronenthaler 6
  • How to show the system framework?

    How to show the system framework?

    How to get show the system framework? not contain show third framework 屏幕快照 2020-01-09 上午11 15 17

    enhancement answered 
    opened by Kratos28 6
  • load file incorrect with some special format

    load file incorrect with some special format

    projectReferences = (
    	{
    		ProductGroup = E248929D1CE31272000CB2D7 /* Products */;
    		ProjectRef = E248929C1CE31272000CB2D7 /* Breakpad.xcodeproj */;
    	},
    	{
    		ProductGroup = 15A8A4041834BDA200142BE0 /* Products */;
    		ProjectRef = 15A8A4031834BDA200142BE0 /* cocos2d_libs.xcodeproj */;
    	},
    	{
    		ProductGroup = C03781AF18BF654500FE4F13 /* Products */;
    		ProjectRef = C03781AE18BF654500FE4F13 /* cocos2d_lua_bindings.xcodeproj */;
    	},
    	{
    		ProductGroup = 9FF504791A5E86D600AFDA55 /* Products */;
    		ProjectRef = 9FF504781A5E86D600AFDA55 /* libsimulator.xcodeproj */;
    	},
    	{
    		ProductGroup = BE51F2891C216CDB00E29367 /* Products */;
    		ProjectRef = BE51F2881C216CDB00E29367 /* libsocket.xcodeproj */;
    	},
    	{
    		ProductGroup = 18FECF7C1DB9D9EB00D9D583 /* Products */;
    		ProjectRef = 18FECF7B1DB9D9EB00D9D583 /* pbc.xcodeproj */;
    	},
    );
    

    For example, there is an object witch named projectReferences. This list contains some dict items. I load the file witch contains this object, and save it.

    projectReferences = (
    	{
    		ProductGroup = 18FECF7C1DB9D9EB00D9D583 /* Products */;
    		ProjectRef = 18FECF7B1DB9D9EB00D9D583 /* pbc.xcodeproj */;
    	},
    	{
    		ProductGroup = 18FECF7C1DB9D9EB00D9D583 /* Products */;
    		ProjectRef = 18FECF7B1DB9D9EB00D9D583 /* pbc.xcodeproj */;
    	},
    	{
    		ProductGroup = 18FECF7C1DB9D9EB00D9D583 /* Products */;
    		ProjectRef = 18FECF7B1DB9D9EB00D9D583 /* pbc.xcodeproj */;
    	},
    	{
    		ProductGroup = 18FECF7C1DB9D9EB00D9D583 /* Products */;
    		ProjectRef = 18FECF7B1DB9D9EB00D9D583 /* pbc.xcodeproj */;
    	},
    	{
    		ProductGroup = 18FECF7C1DB9D9EB00D9D583 /* Products */;
    		ProjectRef = 18FECF7B1DB9D9EB00D9D583 /* pbc.xcodeproj */;
    	},
    	{
    		ProductGroup = 18FECF7C1DB9D9EB00D9D583 /* Products */;
    		ProjectRef = 18FECF7B1DB9D9EB00D9D583 /* pbc.xcodeproj */;
    	},
    );
    

    As you can see, only one dict saved.

    opened by jiang1095 5
  • big pbxproj file need very long time

    big pbxproj file need very long time

    When i use my project pbxproj.file it will take a very long time to save it.

    Can you fix it?

    opened by 99848873 5
  • When I try to add a file with embed framework, it only adds it to the Unity-iPhone Tests target

    When I try to add a file with embed framework, it only adds it to the Unity-iPhone Tests target

    When I try to add a file with embed framework, it only adds it to the Unity-iPhone Tests target. My code is as follows:

    framework_group = project.get_or_create_group('Frameworks')
    file_options = FileOptions(embed_framework=True, weak=True)
    build_files = project.add_file('/path/to/my.framework', parent=framework_group, file_options=file_options)
    

    It does not embed the framework on the Unity-iPhone target, but I do see it correctly added to the Unity-Iphone Tests target.

    /* Begin PBXNativeTarget section */
    		1D6058900D05DD3D006BFB54 /* Unity-iPhone */ = {
    			isa = PBXNativeTarget;
    			buildConfigurationList = 1D6058960D05DD3E006BFB54 /* Build configuration list for PBXNativeTarget "Unity-iPhone" */;
    			buildPhases = (
    				1D60588D0D05DD3D006BFB54 /* Resources */,
    				83D0C1FD0E6C8D7700EBCE5D /* CopyFiles */,
    				1D60588E0D05DD3D006BFB54 /* Sources */,
    				1D60588F0D05DD3D006BFB54 /* Frameworks */,
    				033966F41B18B03000ECD701 /* ShellScript */,
    			);
    			buildRules = (
    			);
    			dependencies = (
    			);
    			name = "Unity-iPhone";
    			productName = "iPhone-target";
    			productReference = 1D6058910D05DD3D006BFB54 /* Unity-Target-New.app */;
    			productType = "com.apple.product-type.application";
    		};
    		5623C57217FDCB0800090B9E /* Unity-iPhone Tests */ = {
    			isa = PBXNativeTarget;
    			buildConfigurationList = 5623C58517FDCB0900090B9E /* Build configuration list for PBXNativeTarget "Unity-iPhone Tests" */;
    			buildPhases = (
    				5623C56F17FDCB0800090B9E /* Sources */,
    				5623C57017FDCB0800090B9E /* Frameworks */,
    				5623C57117FDCB0800090B9E /* Resources */,
    				766B4D729752207B9FD4EEC7 /* Embed Frameworks */,
    			);
    			buildRules = (
    			);
    			dependencies = (
    				5623C58217FDCB0900090B9E /* PBXTargetDependency */,
    			);
    			name = "Unity-iPhone Tests";
    			productName = "Unity-iPhone Tests";
    			productReference = 5623C57317FDCB0800090B9E /* Unity-iPhone Tests.xctest */;
    			productType = "com.apple.product-type.bundle.unit-test";
    		};
    /* End PBXNativeTarget section */
    

    If I manually go into the Begin PBXNativeTarget section, under build phase I can copy the entry Embed Frameworks from the Unity-IPhone tests section into the Unity-iPhone entry above and then it will correctly show the embedded library in Xcode. The change makes the file look as below:

    /* Begin PBXNativeTarget section */
    		1D6058900D05DD3D006BFB54 /* Unity-iPhone */ = {
    			isa = PBXNativeTarget;
    			buildConfigurationList = 1D6058960D05DD3E006BFB54 /* Build configuration list for PBXNativeTarget "Unity-iPhone" */;
    			buildPhases = (
    				1D60588D0D05DD3D006BFB54 /* Resources */,
    				83D0C1FD0E6C8D7700EBCE5D /* CopyFiles */,
    				1D60588E0D05DD3D006BFB54 /* Sources */,
    				1D60588F0D05DD3D006BFB54 /* Frameworks */,
    				033966F41B18B03000ECD701 /* ShellScript */,
    				766B4D729752207B9FD4EEC7 /* Embed Frameworks */,
    			);
    			buildRules = (
    			);
    			dependencies = (
    			);
    			name = "Unity-iPhone";
    			productName = "iPhone-target";
    			productReference = 1D6058910D05DD3D006BFB54 /* Unity-Target-New.app */;
    			productType = "com.apple.product-type.application";
    		};
    		5623C57217FDCB0800090B9E /* Unity-iPhone Tests */ = {
    			isa = PBXNativeTarget;
    			buildConfigurationList = 5623C58517FDCB0900090B9E /* Build configuration list for PBXNativeTarget "Unity-iPhone Tests" */;
    			buildPhases = (
    				5623C56F17FDCB0800090B9E /* Sources */,
    				5623C57017FDCB0800090B9E /* Frameworks */,
    				5623C57117FDCB0800090B9E /* Resources */,
    				766B4D729752207B9FD4EEC7 /* Embed Frameworks */,
    			);
    			buildRules = (
    			);
    			dependencies = (
    				5623C58217FDCB0900090B9E /* PBXTargetDependency */,
    			);
    			name = "Unity-iPhone Tests";
    			productName = "Unity-iPhone Tests";
    			productReference = 5623C57317FDCB0800090B9E /* Unity-iPhone Tests.xctest */;
    			productType = "com.apple.product-type.bundle.unit-test";
    		};
    /* End PBXNativeTarget section */
    

    I've tried using target_name to set targets to no avail, but I was under the impression leaving that leaving this blank would embed the framework in all targets.

    Any help would be appreciated.

    Thanks!

    opened by xmuskrat 5
  •  Xcode project add the custom dynamic libraries.

    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?

    enhancement 
    opened by dgynfi 5
  • PBXLegacyTarget not supported

    PBXLegacyTarget not supported

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

    opened by jimon 5
  • Python 3.5 Compatibility?

    Python 3.5 Compatibility?

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

    ImportError: cannot import name 'XcodeProject'

    enhancement 
    opened by alexk403 5
  • Add run script

    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>

    enhancement 
    opened by soofaloofa-zz 5
  • NameError: name 'PBXGenericObject' is not defined

    NameError: name 'PBXGenericObject' is not defined

    Traceback:

    iMac:package justbilt$ python test.py
    Traceback (most recent call last):
      File "test.py", line 6, in <module>
        from pbxproj import XcodeProject
      File "/Library/Python/2.7/site-packages/pbxproj/__init__.py", line 24, in <module>
        from pbxproj.PBXGenericObject import PBXGenericObject
      File "/Library/Python/2.7/site-packages/pbxproj/PBXGenericObject.py", line 6, in <module>
        standard_library.install_aliases()
      File "/Library/Python/2.7/site-packages/future/standard_library/__init__.py", line 483, in install_aliases
        import test
      File "/Users/justbilt/Documents/work/package/test.py", line 6, in <module>
        from pbxproj import XcodeProject
      File "/Library/Python/2.7/site-packages/pbxproj/XcodeProject.py", line 3, in <module>
        from pbxproj.pbxextensions import *
      File "/Library/Python/2.7/site-packages/pbxproj/pbxextensions/__init__.py", line 1, in <module>
        from pbxproj.pbxextensions.ProjectFiles import *
      File "/Library/Python/2.7/site-packages/pbxproj/pbxextensions/ProjectFiles.py", line 1, in <module>
        from pbxproj.pbxsections import *
      File "/Library/Python/2.7/site-packages/pbxproj/pbxsections/__init__.py", line 1, in <module>
        from pbxproj.pbxsections.PBXBuildFile import *
      File "/Library/Python/2.7/site-packages/pbxproj/pbxsections/PBXBuildFile.py", line 4, in <module>
        class PBXBuildFile(PBXGenericObject):
    NameError: name 'PBXGenericObject' is not defined
    

    test.py

    #!/usr/bin/env python  
    # coding=utf-8  
    # Python 2.7.3  
    from pbxproj import XcodeProject
    

    Python version:

    Python 2.7.10
    

    pbxproj version:

    iMac:package justbilt$ pip show pbxproj
    Name: pbxproj
    Version: 2.2.2
    Summary: XCode Project manipulation library for Python
    Home-page: http://github.com/kronenthaler/mod-pbxproj
    Author: Ignacio Calderon
    Author-email: UNKNOWN
    License: MIT License
    Location: /Library/Python/2.7/site-packages
    Requires: openstep-parser, docopt, future
    

    And it work fine when i changed PBXBuildFile.py :

    from pbxproj import *
    from pbxproj import PBXGenericObject
    
    opened by justbilt 5
  • AttributeError: 'unicode' object has no attribute '_get_comment' [BUG]

    AttributeError: 'unicode' object has no attribute '_get_comment' [BUG]

    Describe the bug I installed mod-pbxproj and created a simple perl script

    from pbxproj import XcodeProject project = XcodeProject.load('ActivationEngineIOS.xcodeproj/project.pbxproj') project.add_file('MyClass.swift', force=False) project.save()

    I got the following error: Traceback (most recent call last): File "prepare-project.py", line 9, in project.save() File "/Library/Python/2.7/site-packages/pbxproj/XcodeProject.py", line 35, in save f.write(self.repr() + "\n") File "/Library/Python/2.7/site-packages/pbxproj/XcodeProject.py", line 47, in repr return '// !$UTF8$!\n' + super(XcodeProject, self).repr() File "/Library/Python/2.7/site-packages/pbxproj/PBXGenericObject.py", line 75, in repr return self._print_object() File "/Library/Python/2.7/site-packages/pbxproj/PBXGenericObject.py", line 83, in _print_object indentation_increment) File "/Library/Python/2.7/site-packages/pbxproj/PBXGenericObject.py", line 107, in _format indentation_increment) File "/Library/Python/2.7/site-packages/pbxproj/PBXObjects.py", line 42, in _print_object result += indentation_depth + '\t{0} = {1};\n'.format(value.get_id().repr(), obj) File "/Library/Python/2.7/site-packages/pbxproj/PBXKey.py", line 8, in repr comment = self._get_comment() File "/Library/Python/2.7/site-packages/pbxproj/PBXKey.py", line 20, in _get_comment return self.get_parent()._resolve_comment(self) File "/Library/Python/2.7/site-packages/pbxproj/PBXGenericObject.py", line 154, in _resolve_comment return self[key]._get_comment() File "/Library/Python/2.7/site-packages/pbxproj/pbxsections/PBXBuildFile.py", line 41, in _get_comment comment = self.fileRef._get_comment() AttributeError: 'unicode' object has no attribute '_get_comment'

    System information

    1. pbxproj version used: 2.9.0
    2. python version used: 2.7
    3. Xcode version used:11.2.1

    As a side effect my project can't be opened by Xcode any more

    bug 
    opened by kamendo 5
  • CLI refactor

    CLI refactor

    Now the CLI offers more functionality and it's structured in a more git-like way, allowing new subcommands to be be added in a simpler way. Also it's using docopt to simplify the parsing of the arguments. Also, in the setup process now the commands are installed as entry points.

    opened by kronenthaler 5
  • Disable bit code of project?

    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?

    opened by jonnyijapan 4
  • Help, open project Xcode crashed!

    Help, open project Xcode crashed!

    test.zip

    The origin project is good in the path test->aaa->bbb->ROGame.xcodeproj. The target project is crash in the path test->aaa->bbb->ROGame-iapps.xcodeproj.

    Help me , please check out the attachment , thanks.

    opened by shanghaiMichael 4
  • [FEAT] How to add sub-project into current project, but sub-project has two kinds of target type

    [FEAT] How to add sub-project into current project, but sub-project has two kinds of target type

    Is your feature request related to a problem? Please describe. There is a framework xcode project B, which has two different kinds of platform targets, iOS and MacOS. After I added this framework project B into another app xcode project A as a dependency library. You will find out that, the list of the Build Phases -> Link Binary With Libraries, has both two targets which belong xcode proj B, one is for iOS, another is for MacOS. But the aim of this action is to add one compatible framework into current project as a dependency library, and this behavior should be ensure the dependency library must match the major app's target platform type, like iOS only, or MacOS only.

    I think the method below should be refactored.

    def add_project(self, path, parent=None, tree=TreeType.GROUP, target_name=None, force=True, file_options=FileOptions())
    
    enhancement 
    opened by imeteora 0
  • support for easily adding swift packages to project

    support for easily adding swift packages to project

    hacktoberfest-accepted 
    opened by garrik 3
  • Missing support for easily adding swift packages to project

    Missing support for easily adding swift packages to project

    I have not found an api to perform all steps required to add a swift package to project. When a swift package is added to an xcode project, it is modified as follows:

    • a single entry is added to XCRemoteSwiftPackageReference section
    • a single entry is added to PBXProject section
    • an entry for each package product is added to XCSwiftPackageProductDependency section
    • an entry for each package product is added to PBXFrameworksBuildPhase section, for given target
    • an entry for each package product is added to PBXBuildFile section (the entry has productRef attribute in place of fileRef), for given target
    • an entry for each package product is added to PBXNativeTarget section, for given target

    As a side note, a file *.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved is also created, but I think this is out of scope.

    I have modified mod-pbxproj and added an add_package function that performs the steps stated above. It can be used as follows:

    from pbxproj import XcodeProject
        
    # open the project
    project = XcodeProject.load('DummyProject/DummyProject.xcodeproj/project.pbxproj')
    
    project.add_package('https://github.com/SnapKit/SnapKit.git', 'SnapKit', 'DummyProject (iOS)', {
        "kind": "upToNextMajorVersion",
        "minimumVersion": "5.0.1"
    })
    project.add_package('https://github.com/openid/AppAuth-iOS.git', ['AppAuth','AppAuthCore'], 'DummyProject (iOS)', {
        "kind": "upToNextMajorVersion",
        "minimumVersion": "1.4.0"
    })
    
    project.save()
    

    You can take a look the patch https://github.com/kronenthaler/mod-pbxproj/compare/master...garrik:develop

    This code just suits my needs but if you find it a viable solution, I would be happy to add tests, refactor, accept suggestion for improvement and contribute a pull request. Regards

    enhancement 
    opened by garrik 1
  • [FEAT] Add support for Creating/Deleting On Demand Resource Tags

    [FEAT] Add support for Creating/Deleting On Demand Resource Tags

    Is your feature request related to a problem? Please describe. On Demand Resource tags can only be manipulated through Xcode's project settings GUI. This is very annoying when you have processes that install new resources into your application, but then need to manually tag their resources

    Describe the solution you'd like

    • Asset Tags are defined in the KnownAssetTags object in the 
 /* Begin PBXProject section */ It seems it would be fairly easy to mutate this list.
    • Additionally, each file references it's created ODR tag at the end of it's resource declaration 6A73EA5125C074F800669235 /* 265 in Resources */ = {isa = PBXBuildFile; fileRef = 6A73EA2725C074F000669235 /* 265 */; settings = {ASSET_TAGS = (265, ); }; };

    Describe alternatives you've considered Doesn't seem to be any support for this in the ecosystem, seems people are mutating their pbx files directly via shell scripts. Would be nice to add to this very nice library :)

    enhancement answered 
    opened by ignkarman 3
  • [BUG] Missing support for handling productRef file references

    [BUG] Missing support for handling productRef file references

    Describe the bug When using Swift Packages in a project, running this tool crashes due to the library being unsure of how to handle productRef file references. Below is an example line from a .pbxproj file that contains Swift Packages:

    58AFD9DF24D2077900331519 /* Core in Frameworks */ = {isa = PBXBuildFile; productRef = 58AFD9DE24D2077900331519 /* Core */; };

    And here is the trace error:

    Traceback (most recent call last):
      File "modpbx.py", line 57, in <module>
        resultClasses = project.remove_group_by_id(classesGroup.get_id(), True)
      File "/usr/local/lib/python3.7/site-packages/pbxproj-2.9.0-py3.7.egg/pbxproj/pbxextensions/ProjectGroups.py", line 65, in remove_group_by_id
      File "/usr/local/lib/python3.7/site-packages/pbxproj-2.9.0-py3.7.egg/pbxproj/pbxextensions/ProjectGroups.py", line 70, in remove_group_by_id
      File "/usr/local/lib/python3.7/site-packages/pbxproj-2.9.0-py3.7.egg/pbxproj/pbxextensions/ProjectFiles.py", line 317, in remove_file_by_id
    AttributeError: 'PBXBuildFile' object has no attribute 'fileRef'
    

    System information

    1. pbxproj version used: latest code from master
    2. python version used: 3.7.6
    3. Xcode version used: 11.5

    To Reproduce Steps to reproduce the behavior:

    1. Add a Swift Package to your project
    2. Add the framework to the targets frameworks area
    3. Run the following script:
    #! /usr/bin/env python3
    import os
    from pbxproj import XcodeProject
    from pbxproj.pbxextensions.ProjectFiles import *
    
    from pbxproj.pbxextensions.ProjectFiles import FileOptions
    ProjectFiles._FILE_TYPES[u'.icalls'] = (u'library.icalls', u'PBXResourcesBuildPhase')
    del ProjectFiles._FILE_TYPES['.h'] # to prevent header files from being attached to a
    
    project = XcodeProject.load('./App/App.xcodeproj/project.pbxproj')
    
    rootGroup = project._get_parent_group( None )
    
    unityGroup = None
    unityGroups = project.get_groups_by_name('Unity', rootGroup)
    
    if unityGroups.__len__() > 0:
    	unityGroup = unityGroups[0]
    
    classesGroups = project.get_groups_by_name('Classes', unityGroup)
    classesGroup = None
    
    if classesGroups.__len__() > 0:
    	classesGroup = classesGroups[0]
    
    librariesGroups = project.get_groups_by_name('Libraries', unityGroup)
    librariesGroup = None
    
    if librariesGroups.__len__() > 0:
    	librariesGroup = librariesGroups[0]
    
    if classesGroup is not None:
    	resultClasses = project.remove_group_by_id(classesGroup.get_id(), True)
    

    Expected behavior Remove the specified groups.

    bug enhancement 
    opened by davidohyer 7
  • How to remove_project from the main project?

    How to remove_project from the main project?

    Is there a reverse operation to add_project?

    enhancement answered 
    opened by zhangao0086 1
  • Is it possible to add build phase from pbxproj command

    Is it possible to add build phase from pbxproj command

    Is it possible to add build phase (especially runs scrip) from pbxproj command in terminal I am expecting something like, pbxproj --add-run-script "echo 'its here'"

    I can find its doable from python code with, project.add_run_script("something")

    enhancement 
    opened by jkmathew 3
  • Is there any way to control the Capabilities?

    Is there any way to control the Capabilities?

    Is there any way to control the Capabilities? such as turn on the 'Push Notifications'.

    enhancement 
    opened by chenxi92 6
  • Adding files to variants

    Adding files to variants

    (I know this is not really a bug report, but I don't know where else to ask questions - I'm happy to convert this into a wiki page as an example usage though)

    Hello and thank you for maintaining this project. At Mozilla we are trying to use this for the following use case:

    We have a product called Focus at https://github.com/mozilla-mobile/focus which currently is English only.

    We localize the product by exporting an en.XLIFF file to our localization volunteers and we get back XLIFF files for other locales. To import these we run xcodebuild -importLocalizations -localizationPath l10n/nl.xliff for example. This spits out .strings files in the proper .lproj directories.

    The problem is that xcodebuild only generates the files. It does not actually add them to the project.

    This is where pbxproj comes in. I'd like to use it to find for example the PBXVariantGroup for Localizable.strings and then add a PBXFileReference reference for it.lproj/Localizable.strings to it.

    However, we are lost in the complexity of both the Xcode projects and the pbxproj API.

    My question to you is if we can get some help to find out how to do this. I'm happy to turn the end result in some reusable code that anyoen can use. Or a blog post or a wiki page.

    🧀

    enhancement 
    opened by st3fan 5
  • Integration Test (e2e)

    Integration Test (e2e)

    Create an integration tests that allows to check that the project generated actually compiles. Any error during, compilation or execution of the final product should fail the test.

    • [ ] seed empty project
    • [ ] some source code classes that will be added using the module
    • [ ] using the module, link against some frameworks and set some flags
    • [ ] compile the Xcode project and run it's product
    • [ ] compare some output of the product against some expected string.
    enhancement 
    opened by kronenthaler 0
Releases(3.2.3)
Owner
Ignacio Calderon
Ignacio Calderon
Pyfunctools is a module that provides functions, methods and classes that help in the creation of projects in python

Pyfunctools Pyfunctools is a module that provides functions, methods and classes that help in the creation of projects in python, bringing functional

Natanael dos Santos Feitosa 4 Nov 27, 2021
A small python library that helps you to generate localization strings for your mobile projects.

LocalizationUtiltiy A small python library that helps you to generate localization strings for your mobile projects. This small script aims to help yo

null 1 Nov 12, 2021
A utility that makes it easy to work with Python projects containing lots of packages, of which you only want to develop some.

Mixed development source packages on top of stable constraints using pip mxdev [mɪks dɛv] is a utility that makes it easy to work with Python projects

BlueDynamics Alliance 4 Feb 28, 2022
Go through a random file in your favourite open source projects!

Random Source Codes Never be bored again! Staring at your screen and just scrolling the great world wide web? Would you rather read through some code

Mridul Seth 1 Oct 29, 2021
Simple python module to get the information regarding battery in python.

Battery Stats A python3 module created for easily reading the current parameters of Battery in realtime. It reads battery stats from /sys/class/power_

Shreyas Ashtamkar 3 Jun 4, 2021
A python module to update the console without flashing.

A python module to update the console without flashing.

Matthias 101 Jan 17, 2022
A python module to validate input.

A python module to validate input.

Matthias 4 Jan 16, 2022
A module for account creation with python

A module for account creation with python

Fayas Noushad 3 Dec 1, 2021
A string extractor module for python

A string extractor module for python

Fayas Noushad 3 Dec 6, 2021
A python module for extract domains

A python module for extract domains

Fayas Noushad 4 Jan 12, 2022
An URL checking python module

An URL checking python module

Fayas Noushad 4 Nov 28, 2021
A multipurpose python module

pysherlock pysherlock is a Python library for dealing with web scraping using images, it's a Python application of the rendertron headless browser API

Sachit 2 Nov 11, 2021
Python module and its web equivalent, to hide text within text by manipulating bits

cacherdutexte.github.io This project contains : Python modules (binary and decimal system 6) with a dedicated tkinter program to use it. A web version

null 1 Nov 5, 2021
A python mathematics module

A python mathematics module

Fayas Noushad 4 Nov 28, 2021
A hashtag from string extract python module

A hashtag from string extract python module

Fayas Noushad 3 Dec 12, 2021
A random cats photos python module

A random cats photos python module

Fayas Noushad 6 Dec 1, 2021
glip is a module for retrieve ip address like local-ip, global-ip, external-ip as string.

gle_ip_info glip is a module for retrieve ip address like local-ip, global-ip, external-ip as string.

Fatin Shadab 3 Nov 21, 2021
Import the module and create an object of the class LocalVariable.

LocalVariable Import the module and create an object of the class LocalVariable. Call the save method with the name and the value of a variable as arg

Sajedur Rahman Fiad 2 Dec 5, 2021
Extends the pyranges module with operations on joined genomic intervals

tiedpyranges Extends the pyranges module with operations on joined genomic intervals (e.g. exons of same transcript) Install with: pip install tiedpyr

Marco Mariotti 3 Dec 2, 2021