2010-04-22 2 views
30

현재 XCode 프로젝트에 새 대상을 추가하는 과정을 자동화하는 방법을 연구 중입니다. 한 대상을 여러 XCode 프로젝트에 추가해야하며 다른 프로젝트의 각 대상에는 추가 할 동일한 원본 파일, XCode 프로젝트에 원본 파일을 저장하는 동일한 그룹 및 동일한 빌드 설정이 필요합니다. 이 작업을 수동으로 수행하는 데는 시간이 걸릴 수 있으며 인적 오류가 발생하기 쉽기 때문에이 작업을 자주 수행해야합니다. 이미 새 소스 파일을 생성하고 시스템 폴더에 복사하고 새 정보로 소스 파일을 편집하는 스크립트를 작성했지만 이제는 XCode 부분을 자동화해야합니다.Applescript/Automator/Shell 스크립트에서 새 XCode 대상을 만드는 방법을 자동화하는 방법

열기 /this/path/project.xcodeproj

에서 Xcode 프로젝트는 기존 대상을 복제하고

편집 빌드의 이름을 바꿉니다

이것은 내가 내 자동화를 달성 할 것을 요약 새 대상

의 설정은 그들에게

추가 소스 F의 이름을 변경, 소스 및 자료 섹션에 그룹을 추가 그룹에 세틸 및

가 이상적으로 나는이 내 Bourne 쉘 스크립트에서 실행하려는 새로운 대상

닫기 엑스 코드에 파일을 추가, 당신이 거기에서 자동화 워크 플로우를 시작할 수 있습니다 알고 있습니다. 나는 최선의 접근 방식이 이것을 달성하는 것이 무엇인지 모르겠다. 어떤 생각 일까?

+1

같은 소스 파일 등은 할 수 없었다 그것들을 프레임 워크 나 번들로 만들지 않고 모든 프로젝트에서 컴파일 된 버전을 사용하지 마십시오. 그러면 문제는 각 프로젝트에 프레임 워크를 추가하는 것입니다. – Mark

답변

2

:-) 사전에 감사는, 내가 (엑스 코드 4.2.1에 대한)이 스크립트를 시작하자

  • 열기 (완료) /this/path/project.xcodeproj에서 Xcode 프로젝트
  • 중복 기존 대상은 그것을 (구현되지 않음)
  • 은에 소스 파일을 추가 (완료) (완료) 새 대상
  • 다음, 소스 및 자료 섹션에 그룹을 추가 이름을 바꿉니다의
  • 편집 빌드 설정의 이름을 변경 그룹을 추가하고 그는 새로운 목표 (부분적으로)
  • 닫기 엑스 코드는 (다)에 파일이있는 경우

!는/usr/빈/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 
관련 문제