2010-04-22 24 views
30

से नए एक्सकोड लक्ष्यों के निर्माण को स्वचालित करने के लिए कैसे मैं वर्तमान में अपने एक्सकोड परियोजनाओं में नए लक्ष्य जोड़ने की प्रक्रिया को स्वचालित करने के तरीके पर काम कर रहा हूं। एक लक्ष्य को कई एक्सकोड परियोजनाओं में जोड़ा जाना है और विभिन्न परियोजनाओं में प्रत्येक लक्ष्य को समान स्रोत फ़ाइलों को जोड़ने की आवश्यकता है, एक्सकोड प्रोजेक्ट में स्रोत फ़ाइलों को संग्रहीत करने के लिए समान समूह, और समान बिल्ड सेटिंग्स। इसे मैन्युअल रूप से करने में कुछ समय लग सकता है और यह मानव त्रुटि से बहुत प्रवण है, और मुझे यह कार्य काफी बार करना है। मैंने नई स्रोत फ़ाइलों को उत्पन्न करने के लिए पहले से ही एक स्क्रिप्ट लिखी है, उन्हें सिस्टम फ़ोल्डर्स में कॉपी करें, नई सूचनाओं के साथ स्रोत फाइलों को संपादित करें, लेकिन अब मुझे एक्सकोड भाग को स्वचालित करने की आवश्यकता है।एप्पलस्क्रिप्ट/ऑटोमेटर/शैल स्क्रिप्ट

इस का सार है कि मैं क्या मेरी स्वचालन हासिल करना चाहते हैं:

ओपन /this/path/project.xcodeproj

में एक XCode प्रोजेक्ट मौजूदा लक्षित डुप्लिकेट और यह

संपादित नाम बदलने बिल्ड नया लक्ष्य

की सेटिंग्स स्रोत और संसाधन अनुभाग के लिए एक समूह जोड़ें, तो उनका नाम बदल

जोड़ें स्रोत च समूहों के लिए Iles, और नए लक्ष्य

बंद XCode

आदर्श रूप में मैं यह मेरी बॉर्न शैल स्क्रिप्ट से चलाना चाहते हैं के लिए फ़ाइल जोड़ने के लिए, मैं जानता हूँ कि तुम वहाँ से स्वचालक वर्कफ़्लो शुरू कर सकते हैं। मुझे यकीन नहीं है कि यह हासिल करने के लिए सबसे अच्छा तरीका क्या है, कोई विचार? अग्रिम :-)

+1

अगर ऐसा है एक ही स्रोत फ़ाइलों आदि नहीं कर सका उन्हें फ्रेमवर्क या बंडल में न बनाएं और सभी परियोजनाओं में संकलित संस्करण का उपयोग करें - फिर समस्या सिर्फ प्रत्येक प्रोजेक्ट में एक ढांचा जोड़ रही है – Mark

उत्तर

2

धन्यवाद मुझे इस स्क्रिप्ट (Xcode 4.2.1 के लिए) के साथ शुरू करते हैं,

  • ओपन /this/path/project.xcodeproj में एक XCode प्रोजेक्ट (किया)
  • डुप्लिकेट एक मौजूदा लक्ष्य है और यह (कार्यान्वित नहीं)
  • संपादित नया लक्ष्य (किया)
  • स्रोत और संसाधन अनुभाग के लिए एक समूह जोड़ें, तो उनका नाम बदल की सेटिंग बिल्ड (किया)
  • लिए स्रोत फ़ाइलें जोड़ें नाम बदलने समूह, और टी जोड़ें वह नए लक्ष्य (आंशिक रूप से)
  • बंद XCode (किया) फ़ाइल

!/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