Managing Xcode projects from command line

March 3, 2011 — 1 Comment

Update: XCS2: next generation of XCS

One of the most irritating flaws of Xcode is lack of proper command-line tools for project file management. There is no easy way to add file to project or remove them from command line. Of course, it’s impossible to develop Cocoa application in SSH session , but working on a utility or framework if you stuck with PC and have a couple hours to waste would be nice. And I thought of coding such tools myself.

This idea was on the back burner for awhile but then on stackoverflow I stumbled across question about Xcode automation using applescript. That was it: pieces fell into place. Several days of experiments and tinkering with rb-appscript and here it is: xcs. In order to save time Thor was used to a dirty job of options parsing.

xcs provides minimal set of tasks required to modify xcode project from command line: create/remove file group, add file to group, remove file, list project content. That’s pretty much what I wanted from this kind of tool. Help output looks like this:

% thor xcs:help
Tasks:
  thor xcs:add File [Group]  # Add file to a group. By default adds to "Source"
  thor xcs:help [TASK]       # Describe available tasks or one specific task
  thor xcs:list [--verbose]  # List project contents
  thor xcs:mkgroup Group     # Create new subgroup in root group
  thor xcs:rm Group/File     # Remove file reference from a project
  thor xcs:rmgroup Group     # Remove Group

Generic session is something like:

%thor xcs:list
Using /Users/gonzo/Projects/EPUBToolkit/EPUBToolkit.xcodeproj
    EPUBToolkit/
      EPUBFile.h
      EPUBFile.m
      Source/
        main.m
      Documentation/
        EPUBToolkit.1
      Products/
        EPUBToolkit
      Frameworks/
        Foundation.framework
      Other Sources/
        EPUBToolkit-Prefix.pch

% echo '#import "Foo.h"' > Foo.m
% thor xcs:mkgroup FooSources
% thor xcs:add Foo.m FooSources

Further documentation available on github

Oleksandr Tymoshenko

Posts

One response to Managing Xcode projects from command line

  1. Hi.
    I’ve faced similar task in my developing. We are developing cross-platform games on c++ and all our teem is working in Visual Studio.
    Keeping xCode project up-to-date manually is dummy work.
    So I’m thinking about a script that parses Visual Studio project and updates xCode project to actual state.
    I have a script that builds IOS apps on base of Visual Studio project directly without creating and using xCode project. We use this script for now, but it has it’s own drawbacks.

    I want to take useful pieces from it and expand you XCS script to make required solution. Would you be so kind to assist me with a couple advices about XCS code?

    You can access me directly via enclosed email.
    Thanks in advance.

Leave a Reply

*

Text formatting is available via select HTML. <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>