github.com/xushiwei/go@v0.0.0-20130601165731-2b9d83f45bc9/misc/xcode/4/go4xcode.sh (about) 1 #!/usr/bin/env bash 2 # Copyright 2012 The Go Authors. All rights reserved. 3 # Use of this source code is governed by a BSD-style 4 # license that can be found in the LICENSE file. 5 6 # Illustrates how a Go language specification can be installed for Xcode 4.x., 7 # to enable syntax coloring, by adding an entry to a plugindata file. 8 # 9 # FIXME: Write a decent Xcode plugin to handle the file type association and 10 # language specification properly instead of altering Xcode library files. 11 12 set -e 13 14 # Assumes Xcode 4+. 15 XCODE_MAJOR_VERSION=`xcodebuild -version | awk 'NR == 1 {print substr($2,1,1)}'` 16 if [ "$XCODE_MAJOR_VERSION" -lt "4" ]; then 17 echo "Xcode 4.x not found." 18 exit 1 19 fi 20 21 # DVTFOUNDATION_DIR may vary depending on Xcode setup. Change it to reflect 22 # your current Xcode setup. Find suitable path with e.g.: 23 # 24 # find / -type f -name 'DVTFoundation.xcplugindata' 2> /dev/null 25 # 26 # Example of DVTFOUNDATION_DIR's from "default" Xcode 4.x setups; 27 # 28 # Xcode 4.1: /Developer/Library/PrivateFrameworks/DVTFoundation.framework/Versions/A/Resources/ 29 # Xcode 4.3: /Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/ 30 # 31 DVTFOUNDATION_DIR="/Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/" 32 PLUGINDATA_FILE="DVTFoundation.xcplugindata" 33 34 PLISTBUDDY=/usr/libexec/PlistBuddy 35 PLIST_FILE=tmp.plist 36 37 # Provide means of deleting the Go entry from the plugindata file. 38 if [ "$1" = "--delete-entry" ]; then 39 echo "Removing Go language specification entry." 40 $PLISTBUDDY -c "Delete :plug-in:extensions:Xcode.SourceCodeLanguage.Go" $DVTFOUNDATION_DIR/$PLUGINDATA_FILE 41 echo "Run 'sudo rm -rf /var/folders/*' and restart Xcode to update change immediately." 42 exit 0 43 fi 44 45 GO_VERSION="`go version`" 46 47 GO_LANG_ENTRY=" 48 <?xml version=\"1.0\" encoding=\"UTF-8\"?> 49 <!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"> 50 <plist version=\"1.0\"> 51 <dict> 52 <key>Xcode.SourceCodeLanguage.Go</key> 53 <dict> 54 <key>conformsTo</key> 55 <array> 56 <dict> 57 <key>identifier</key> 58 <string>Xcode.SourceCodeLanguage.Generic</string> 59 </dict> 60 </array> 61 <key>documentationAbbreviation</key> 62 <string>go</string> 63 <key>fileDataType</key> 64 <array> 65 <dict> 66 <key>identifier</key> 67 <string>com.apple.xcode.go-source</string> 68 </dict> 69 </array> 70 <key>id</key> 71 <string>Xcode.SourceCodeLanguage.Go</string> 72 <key>languageName</key> 73 <string>Go</string> 74 <key>languageSpecification</key> 75 <string>xcode.lang.go</string> 76 <key>name</key> 77 <string>The Go Programming Language</string> 78 <key>point</key> 79 <string>Xcode.SourceCodeLanguage</string> 80 <key>version</key> 81 <string>$GO_VERSION</string> 82 </dict> 83 </dict> 84 </plist> 85 " 86 87 echo "Backing up plugindata file." 88 cp $DVTFOUNDATION_DIR/$PLUGINDATA_FILE $DVTFOUNDATION_DIR/$PLUGINDATA_FILE.bak 89 90 echo "Adding Go language specification entry." 91 echo $GO_LANG_ENTRY > $PLIST_FILE 92 $PLISTBUDDY -c "Merge $PLIST_FILE plug-in:extensions" $DVTFOUNDATION_DIR/$PLUGINDATA_FILE 93 94 rm -f $PLIST_FILE 95 96 echo "Installing Go language specification file for Xcode." 97 cp $GOROOT/misc/xcode/4/go.xclangspec $DVTFOUNDATION_DIR 98 99 echo "Run 'sudo rm -rf /var/folders/*' and restart Xcode to update change immediately." 100 echo "Syntax coloring must be manually selected from the Editor - Syntax Coloring menu in Xcode."