Skip to content
kronenthaler edited this page Jun 10, 2018 · 4 revisions

This repository allows you to use the project as a CLI tool or as python module inside your script. If you clone the repository you can execute the CLI, you need to navigate to the repository folder first. Once there, you can execute the CLI version with:

python -m pbxproj <args>

Note: If you installed it using pip, you can use the command above from any directory.

Usage

The CLI currently supports simple flag, files and folder manipulations via subcommands. The CLI is implemented using docopt.

General usage of the tool can be retrieved by executing:

python -m pbxproj --help

Which will print:

usage:
    pbxproj [--version] [--help] <command> [<args> ...]

options:
    -v, --version       Shows version of pbxproj running
    -h, --help          This message

commands:
    show                Displays information about the project targets
    file                Manipulates files on a project
    flag                Manipulates compilation flags on the project
    folder              Manipulates folders or groups on a project

See pbxproj <command> --help, for more information about a specific command.

Show information

You can query the project information using the show subcommand

usage:
    pbxproj show [options] <project>
    pbxproj show [options] (--target <target>...) <project> [(-s | --source-files) |
                                                             (-H | --header-files) |
                                                             (-r | --resource-files) |
                                                             (-f | --framework-files) |
                                                             (--build-phase-files <build_phase_type>)]

positional arguments:
    <project>                      Project path to the .xcodeproj folder.

generic options:
    -h, --help                      This message.
    -t, --target <target>           Target name to be modified. If there is no target specified, all targets are used.
    -b, --backup                    Creates a backup before start processing the command.

target options:
    -s, --source-files              Show the source files attached to the target
    -r, --resource-files            Show the resource files attached to the target
    -f, --framework-files           Show the library files attached to the target
    -H, --header-files              Show the header files attached to the target
    -c, --configurations            Show the configurations attached to the target
    -B, --build-phase-files <type>  Show the files associated to the build phase of the given type.

Only providing the <project> will provide the most basic information as targets available, the configurations, product name and file type counts.

When providing a --target name, you can choose what information to display.

Use:

  • --source-files to list all source files of the given target(s).
  • --resource-files to list all resource files of the given target(s).
  • --header-files to list all source files of the given target(s).
  • --frameworks-files to list all source files of the given target(s).
  • --configurations to list all configurations of the given target(s).
  • --build-phase-files <build-false-type> to list all files of a specific build phase type. Useful, to list build phases not considered on the aliases above.

File manipulation

You can add or delete files using the file subcommand.

usage:
    pbxproj file [options] <project> <path> [--target <target>...]
                                            [(--weak | -w)]
                                            [(--no-embed | -E)]
                                            [(--sign-on-copy | -s)]
                                            [(--ignore-unknown-types | -i)]
                                            [(--no-create-build-files | -C)]
                                            [(--header-scope <scope> | -H <scope>)]
    pbxproj file [options] (--delete | -D) <project> <path>

positional arguments:
    <project>                      Project path to the .xcodeproj folder.
    <path>                         Path of the file to add to the project.

generic options:
    -h, --help                     This message.
    --tree <tree>                  Tree to add the file relative to. Available options: <absolute>, <group>,
                                       SOURCE_ROOT, SDKROOT, DEVELOPER_DIR, BUILT_PRODUCTS_DIR. [default: SOURCE_ROOT]
    -t, --target <target>          Target name(s) to be modified. If there is no target specified, all targets are
                                       modified.
    -b, --backup                   Creates a backup before start processing the command.

delete options:
    -D, --delete                   Delete the file.

add options:
    -w, --weak                     Add the weak flag when libraries or frameworks are added. Linking optional.
    -E, --no-embed                 Do not embed frameworks when added.
    -s, --sign-on-copy             Sign frameworks when copied/embedded.
    -i, --ignore-unknown-types     Ignore unknown file types when added.
    -C, --no-create-build-files    Do not create build file phases when adding a file.
    -H, --header-scope <scope>     Add header file using the given scope. Available options: public or private, project. 
                                       [default: project]

--target and --tree affect where the file is going to be added or removed from.

To add a file, specify the <project>'s path and the file's <path> to be added. Some files have special meanings for Xcode, for instance, libraries and frameworks. Such special files, might require some additional flags to achieve the desired beahvior. --weak attribute only have effect on libraries and frameworks. --no-embed and --sign-on-copy only have effects on frameworks.

--ignore-unknonw-types and --no-create-build-files affect the way the files are added to the project, mostly by avoiding or forcing files to be added.

--header-scope allows to add header files as public or private.

--delete is mutually exclusive from the add file options and removes the file from the project if the <path> matches the path on the project.

Flag manipulation

You can add or delete flags on targets and configurations using the flag subcommand.

usage:
    pbxproj flag [options] <project> [--target <target>...] [--] (<flag_name> <flag_value>)...
    pbxproj flag [options] (--delete | -D) <project> [--] (<flag_name> <flag_value>)...

positional arguments:
    <project>                               Project path to the .xcodeproj folder.
    <flag_name>                             Flag name to be modified in the project's configuration(s).
    <flag_value>                            Flag value to be modified in the project's configuration(s).

generic options:
    --                                      Force to read the flag_value's and flag_name's as they are, otherwise they
                                                might be interpreted as an option and detected as such. Use when a
                                                flag_value starts with -, like -ObjC
    -h, --help                              This message.
    -t, --target <target>                   Target name(s) to be modified. If there is no target specified, all targets 
                                                are modified.
    -b, --backup                            Creates a backup before start processing the command.
    -c, --configuration <configuration>     Configuration name to modify the flags. If no configuration name is
                                                provided, all configurations are affected.

delete options:
    -D, --delete                            Removes the given flag_value's from the pairing flag_name.

-- allows to force the processing of the <flag_name> and <flag_value> as they are, otherwise they can be considered part of this CLI options.

--target and --configuration affect where the flag is going to be added or removed from.

--delete is mutually exclusive from the add flag options and removes the flags from the project matching the <flag_name> and <flag_value> pairs.

<flag_name> and <flag_value> are readed in pairs, which allows to set multiple flags in the same command, for instance, to add to OTHER_LDFLAGS the values -ObjC and -all_load, you can execute:

python -m pbxproj flag -- OTHER_LDFLAGS -ObjC OTHER_LDFLAGS -all_load

Similarly for deleting multiple flag values in one go, you can specify pairs <flag_name> and <flag_value>. To remove -ObjC from OTHER_LDFLAGS and -isystem "${PODS_ROOT}/Headers/Public" from OTHER_CFLAGS, execute:

python -m pbxproj flag --delete -- OTHER_LDFLAGS -ObjC OTHER_CFLAGS "-isystem \"${PODS_ROOT}/Headers/Public\""

Folder manipulation

Note: this subcommand is still experimental

You can add entire folders in one go, and replicate the structure as a group structure or add folders as references using the folder subcommand.

usage:
    pbxproj folder [options] <project> <path> [--target <target>...]
                                              [--exclude <regex>...]
                                              [(--recursive | -r)]
                                              [(--no-create-groups | -G)]
                                              [(--weak | -w)]
                                              [(--no-embed | -E)]
                                              [(--sign-on-copy | -s)]
                                              [(--ignore-unknown-types | -i)]
                                              [(--no-create-build-files | -C)]
                                              [(--header-scope <scope> | -H <scope>)]
    pbxproj folder [options] (--delete | -D) <project> <path> [--tree <tree>]

positional arguments:
    <project>                      Project path to the .xcodeproj folder.
    <path>                         Path of the file to add to the project.

generic options:
    -h, --help                      This message.
    -t, --target <target>           Target name(s) to be modified. If there is no target specified, all targets are
                                        modified.
    -b, --backup                    Creates a backup before start processing the command.

delete options:
    -D, --delete                    Delete the file.
    --tree <tree>                   Tree to add the file relative to. Available options: <absolute>, <group>,
                                        SOURCE_ROOT, SDKROOT, DEVELOPER_DIR, BUILT_PRODUCTS_DIR. [default: SOURCE_ROOT]

add options:
    -e, --exclude <regex>           Pattern to exclude during the insertion of a folder. The pattern applies to file
                                        names and folder names.
    -r, --recursive                 Add folders and files recursively.
    -G, --no-create-groups          Add the folder as a file reference instead of creating group(s).
    -w, --weak                      Add the weak flag when libraries or frameworks are added. Linking optional.
    -E, --no-embed                  Do not embed frameworks when added.
    -s, --sign-on-copy              Sign frameworks when copied/embedded.
    -i, --ignore-unknown-types      Ignore unknown file types when added.
    -C, --no-create-build-files     Do not create build file phases when adding a file.
    -H, --header-scope <scope>      Add header file using the given scope. Available options: public or private, project.
                                       [default: project]

Most options are inherit from the file subcommand, as they are used when a file is processed.

--no-create-groups by default, the folder will be added as groups instead of references. If you want to add the folder as a reference use this flag.

--recursive by default, just the given folder is added. any other subfolder is skipped at least this option is given.

--exclude allows to exclude certain patterns of files/folders during the addition process. It is possible to specify multiple exclusion patterns by adding the option multiple times. The patterns must be in (python) regex format.