vote up 3 vote down star
1

Since there is no Xcode script variable for "current project directory," how can you create a script menu item to run the Clang Static Analyzer on your current project from Xcode?

flag

67% accept rate

3 Answers

vote up 2 vote down check

From the XCode script menu item, "Edit User Scripts" enter the following script:

#!/bin/bash
result=$( osascript << END
tell application "Xcode"
 tell active project document
  set projectPath to path as string
 end tell 
end tell 
return projectPath
END
)

cd "$result"

/Developer/clangchecker/scan-build -k -V xcodebuild -configuration Debug -sdk iphonesimulator3.0

Obviously, you will need to adjust the path to your install of Clang, and adjust to the version of the SDK you are using.

Remember to do a "Clean All" immediately before using scan-build, or the results may be incomplete.

link|flag
Every time I run this script, I must restart Xcode to run it again. Why? Is there a way to run the script twice without restarting? It won't allow me to call it again! – IRTFM Sep 3 at 12:07
Hmmm.... I never had that problem... HOWEVER: This feature is built into XCode 3.2, I would simply upgrade, and forget this script altogether. – mmc Sep 3 at 14:38
vote up 0 vote down

I believe the ${PROJECT_DIR} environment variable is what you want for the directory of the project running a build-phase script.

link|flag
${PROJECT_DIR} will work in a build phase script, yes, but not in a user script that can be triggered from the script menu. – mmc Jun 7 at 15:26
Yes, your question was very clear. Sorry. You could still create a clang target in your project (this is what I usually do). Not as clean as a menu script (and you have to create one in each project, of course), but it works well. – Barry Wark Jun 8 at 3:59
Ah ha! I had not even thought of establishing a separate target. Lots of different ways to approach this one, I guess. – mmc Jun 8 at 23:43
vote up 0 vote down

nice script found @ http://allancraig.net/blog/?p=381

link|flag

Your Answer

Get an OpenID
or

Not the answer you're looking for? Browse other questions tagged or ask your own question.