Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

update website: Using Clang on iPhone #4548

Open Quuxplusone opened 15 years ago

Quuxplusone commented 15 years ago
Bugzilla Link PR4083
Status CONFIRMED
Importance P enhancement
Reported by Chad Jones (chadsspameateremail@yahoo.com)
Reported on 2009-04-26 17:40:45 -0700
Last modified on 2010-02-22 12:50:43 -0800
Version unspecified
Hardware Macintosh MacOS X
CC daniel@zuster.org, garyspamless@gmail.com, kremenek@apple.com, llvm-bugs@lists.llvm.org
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
When trying to use Clang on a project built for the iPhone (on Mac OS X) I
found that the instructions didn't provide the correct result.  Instead I
created alternate instructions which I have attached below.  Feel free to use
this to update your documentation for people building for the iPhone.

-----

DOWNLOADING
Step 1: Download the Mac OS X version of clang from this website:
http://clang.llvm.org/StaticAnalysis.html

Step 2: Double click on the download to unarchive it.

INSTALLING
Step 3: Place the checker-xxx directory where you want to install Clang.  For
this example I'll place it in the Documents directory which would be
~/Documents.  The folder name is checker-0.189 in my example.

Step 4: Open Terminal and add Clang to your path by typing:
echo 'export PATH=~/Documents/checker-0.189/:$PATH' >> ~/.bash_profile

Replace ~/Documents and checker-0.189 as appropriate.

Step 5: Close the current terminal window or open a new terminal window.  This
must be done for the changes in the path to take effect.

RUNNING
Step 6: At this point you may need to set the code signing identity of the
project you want to scan.  This must be setup correctly or Clang will not be
able to build your project correctly.  In XCode you can set the code signing
identity to yourself by going to "Project->Edit Project Settings" in XCode and
then under the build tab finding "Code Signing Identity" and selecting
yourself.  This is the same step which is necessary to build on the device.
Note that Clang will often try and build the release version of the application
so be sure the "Code Signing Identity" is also set correctly for the Release
"Configuration" you can select your "Configuration" by using the
"Configuration" pop-up menu.

Step 7: In the "Edit Project Settings" window above under the build tab you
should also set the Base SDK to Simulator-iPhone OS 2.2.1.  This will allow
Clang to better analyze the project.  You should not be building for the device
here or you will see warnings on the terminal that the arm processor is not
recognized by Clang and it can't find the appropriate version of GCC.

Step 7: In Terminal Navigate to the directory where the project you want to
test is located.  Make sure you are in the directory with the project.  In my
example the iCS folder is located on the desktop so I type:
cd ~/Desktop/iCS

Step 8: Once we are in the proper directory where the xcode project file is
located we can run the scan-build program which launches Clang.  It keys off of
the current path in terminal and builds the files/project within that
directory.  You should not specify a project name.  Though you can specify and
output directory using the -o option as I do below.  Once run successfully
Clang will create a series of HTML files in the output directory you specified.
In my example I type:

scan-build -V -o ~/Desktop/ClangOutput xcodebuild

After the program finishes it automatically launches a web browser displaying
the Clang results.

NOTES
Each time you run Clang will build the project and during the building finds
the errors it reports.  If you run Clang twice in a row the second time it will
generate no output because no files need to be built.  If you want Clang to
retest the entire project you will need to make a change that makes Clang
rebuild the entire project.  One example would be to modify the iCS_Prefix.pch
file by adding some whitespace.
Quuxplusone commented 15 years ago

Ted, this is all you :)

Quuxplusone commented 15 years ago

This is great! I'll look into adding it to the website soon. Thanks Chad!

Quuxplusone commented 15 years ago

Couple of thoughts:

$ xcodebuild clean; ~/Documents/checker-0.189/scan-build -k -V

Running xcodebuild clean ensures that fresh output is produced each time you run it.

export PATH=~/Documents/checker-0.189/:$PATH

to .bash_profile. The problem with the line as written in the bug report is that repeating the command will add unnecessary copies of the line to .bash_profile.

Quuxplusone commented 15 years ago

any progress on this?

Quuxplusone commented 15 years ago

Ping, what is this bug about?

Quuxplusone commented 15 years ago

It's about me updating the clang-analyzer website. I still plan on doing this.