github.com/spotify/syslog-redirector-golang@v0.0.0-20140320174030-4859f03d829a/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+, 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+ not found." 18 exit 1 19 fi 20 21 # DVTFOUNDATION_DIR may vary depending on Xcode setup. If Xcode has installed 22 # the `xcode-select` command, it will be determined automatically. Otherwise, 23 # change it to reflect your current Xcode setup. Find suitable path with e.g.: 24 # 25 # find / -type f -name 'DVTFoundation.xcplugindata' 2> /dev/null 26 # 27 # Example of DVTFOUNDATION_DIR's from "default" Xcode 4+ setups; 28 # 29 # Xcode 4.1: /Developer/Library/PrivateFrameworks/DVTFoundation.framework/Versions/A/Resources/ 30 # Xcode 4.3: /Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/ 31 32 # Defaults to Xcode 4.3's DVTFOUNDATION_DIR. Path is modified automatically if 33 # `xcode-select` command is available, as mentioned above. 34 DVTFOUNDATION_DIR="/Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/" 35 36 if type "xcode-select" > /dev/null; then 37 DVTFOUNDATION_DIR=`xcode-select --print-path` 38 DVTFOUNDATION_DIR+="/.." 39 FRAMEWORK_NAME="DVTFoundation.framework" 40 DVTFOUNDATION_DIR=`find $DVTFOUNDATION_DIR -name $FRAMEWORK_NAME -print` 41 DVTFOUNDATION_DIR+="/Versions/A/Resources" 42 fi 43 44 PLUGINDATA_FILE="DVTFoundation.xcplugindata" 45 46 PLISTBUDDY=/usr/libexec/PlistBuddy 47 PLIST_FILE=tmp.plist 48 49 # Provide means of deleting the Go entry from the plugindata file. 50 if [ "$1" = "--delete-entry" ]; then 51 echo "Removing Go language specification entry." 52 $PLISTBUDDY -c "Delete :plug-in:extensions:Xcode.SourceCodeLanguage.Go" $DVTFOUNDATION_DIR/$PLUGINDATA_FILE 53 echo "Run 'sudo rm -rf /var/folders/*' and restart Xcode to update change immediately." 54 exit 0 55 fi 56 57 GO_VERSION="`go version`" 58 59 GO_LANG_ENTRY=" 60 <?xml version=\"1.0\" encoding=\"UTF-8\"?> 61 <!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"> 62 <plist version=\"1.0\"> 63 <dict> 64 <key>Xcode.SourceCodeLanguage.Go</key> 65 <dict> 66 <key>conformsTo</key> 67 <array> 68 <dict> 69 <key>identifier</key> 70 <string>Xcode.SourceCodeLanguage.Generic</string> 71 </dict> 72 </array> 73 <key>documentationAbbreviation</key> 74 <string>go</string> 75 <key>fileDataType</key> 76 <array> 77 <dict> 78 <key>identifier</key> 79 <string>com.apple.xcode.go-source</string> 80 </dict> 81 </array> 82 <key>id</key> 83 <string>Xcode.SourceCodeLanguage.Go</string> 84 <key>languageName</key> 85 <string>Go</string> 86 <key>languageSpecification</key> 87 <string>xcode.lang.go</string> 88 <key>name</key> 89 <string>The Go Programming Language</string> 90 <key>point</key> 91 <string>Xcode.SourceCodeLanguage</string> 92 <key>version</key> 93 <string>$GO_VERSION</string> 94 </dict> 95 </dict> 96 </plist> 97 " 98 99 echo "Backing up plugindata file (copied to $PLUGINDATA_FILE.bak)." 100 cp $DVTFOUNDATION_DIR/$PLUGINDATA_FILE $DVTFOUNDATION_DIR/$PLUGINDATA_FILE.bak 101 102 echo "Adding Go language specification entry." 103 echo $GO_LANG_ENTRY > $PLIST_FILE 104 $PLISTBUDDY -c "Merge $PLIST_FILE plug-in:extensions" $DVTFOUNDATION_DIR/$PLUGINDATA_FILE 105 106 rm -f $PLIST_FILE 107 108 echo "Installing Go language specification file for Xcode." 109 cp $GOROOT/misc/xcode/4/go.xclangspec $DVTFOUNDATION_DIR 110 111 echo "Run 'sudo rm -rf /var/folders/*' and restart Xcode to update change immediately." 112 echo "Syntax coloring must be manually selected from the Editor - Syntax Coloring menu in Xcode."