2010-04-22 5 views
30

Actualmente estoy trabajando en una forma de automatizar el proceso de agregar nuevos objetivos a mis proyectos de XCode. Se debe agregar un objetivo a múltiples proyectos XCode y cada objetivo en el proyecto diferente necesita los mismos archivos fuente para agregar, los mismos grupos para almacenar los archivos fuente en el proyecto XCode y la misma configuración de compilación. Hacer esto manualmente puede llevar un tiempo y es muy propenso a errores humanos, y tengo que hacer esta tarea con bastante frecuencia. Ya he escrito una secuencia de comandos para generar nuevos archivos fuente, copiarlos en carpetas del sistema, editar archivos fuente con nueva información, etc., pero ahora necesito automatizar la parte XCode.Cómo automatizar la creación de nuevos destinos de XCode desde Applescript/Automator/Shell Script

Esto resume lo que yo quiero que mi automatización para lograr:

Abra un proyecto XCode en /this/path/project.xcodeproj

duplicar un destino existente y cambiarle el nombre

Editar la construcción ajustes de la nueva meta

Adición de un grupo a la sección origen y Recursos, a continuación, cambiar el nombre de ellos

Agregar origen f Iles a los grupos y añada el archivo al nuevo objetivo

Cerrar XCode

Lo ideal sería que yo quiero esto para ejecutar mi script de shell Bourne, sé que puede iniciar flujos de trabajo de Automator a partir de ahí. No estoy seguro de cuál es el mejor enfoque para lograr esto, ¿alguna idea? Gracias de antemano :-)

+1

Si se trata de los mismos archivos de origen, etc. no podía no compilarlos en un Framework o paquete y usar la versión compilada en todos los proyectos, entonces el problema es simplemente agregar un framework a cada proyecto – Mark

Respuesta

2

permítanme comenzar con este script (por Xcode 4.2.1),

  • Abra un proyecto XCode en /this/path/project.xcodeproj (hecho)
  • Duplicar un objetivo existente y cambiarle el nombre (no implementado)
  • editar la configuración de construcción de la nueva meta (hecho)
  • añadir un grupo a la sección Origen y Recursos, a continuación, cambiar el nombre de ellos (hecho)
  • Añadir archivos de origen a los grupos, y agregar t que presentar al nuevo destino (parcialmente)
  • Cerrar XCode (hecho)

!/usr/bin/osascript

# Reference: AppleScript Editor -> File -> Open Directory ... -> Xcode 4.2.1 

# http://vgable.com/blog/2009/04/24/how-to-check-if-an-application-is-running-with-applescript/ 
on ApplicationIsRunning(appName) 
    tell application "System Events" to set appNameIsRunning to exists (processes where name is appName) 
    return appNameIsRunning 
end ApplicationIsRunning 

if not ApplicationIsRunning("Xcode") then 
    log ("Launching Xcode ...") 
    launch application id "com.apple.dt.Xcode" 
    delay 5 
else 
    log("Xcode is already running ...") 
end if 

set project_path to "/PATH/TO/YOUR_PROJECT.xcodeproj" 
log ("Open an XCode project at " & project_path) 

set _project_name to (do shell script "echo $(basename " & project_path & ") | sed -e 's/.xcodeproj//'") 
log ("project_name set to " & _project_name) 

set _target_name to "YOUR_TARGET" 

tell application id "com.apple.dt.Xcode" 
    set _project_file to (POSIX file project_path as alias) 
    open _project_file 
    # load documentation set with path path_to_project display yes 
    set _workspace to active workspace document 
    set _project to first item of (projects of _workspace whose name = _project_name) 
    set _target to first item of (targets of _project whose name = _target_name) 

    # as this won't work, cannot event resort to system event 
    # duplicate _target with properties {name:_target_name & "_clone"} 
    # make new build configuration with data build configurations of _target with properties {name:_target_name & "_clone"} 
    # activate 

    log ("Edit the Build Settings of the new target") 
    set _build_configuration to first item of (build configurations of _target whose name = "Debug") 
    set value of build setting "PRODUCT_NAME" of _build_configuration to "KeySING" 

    # http://lists.apple.com/archives/xcode-users//2008/Feb/msg00497.html 
    log ("Add a group to the Source and Resources section, then rename them") 
    set _new_group_name to "groupX" 
    tell root group of _project 
     set _groups to (get groups whose name = _new_group_name) 
     if (length of _groups) = 0 then 
      set _new_group to make new group with properties {name:_new_group_name, path:_new_group_name, path type:group relative} 
     else 
      set _new_group to first item of _groups 
     end if 

     log ("Add source files to the groups, and add the file to the new Target") 
     tell _new_group 
      set _new_file_name to "whatever.h" 
      set _new_files to get (file references whose name = _new_file_name) 
      if (length of _new_files) = 0 then 
       # Xcode crashes 
       # make new file reference with properties ¬ 
       #  {name:_new_file_name, file encoding:utf8, path type:group relative,¬ 
       #  path:_new_file_name} 
      end if 
     end tell 
    end tell 

    log ("Close XCode") 
    quit 

end tell 
Cuestiones relacionadas