PageRenderTime 27ms CodeModel.GetById 16ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/update-engine/externals/google-toolbox-for-mac/XcodePlugin/Resources/EnableGCov.applescript

http://macfuse.googlecode.com/
Unknown | 86 lines | 79 code | 7 blank | 0 comment | 0 complexity | 3f3dd56dcf2efb2e6c7751e3f03bf9b7 MD5 | raw file
 1(*
 2	EnableGCov.applescript
 3	
 4    Copyright 2007-2009 Google Inc.
 5  
 6    Licensed under the Apache License, Version 2.0 (the "License"); you may not
 7    use this file except in compliance with the License.  You may obtain a copy
 8    of the License at
 9   
10    http://www.apache.org/licenses/LICENSE-2.0
11   
12    Unless required by applicable law or agreed to in writing, software
13    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
15    License for the specific language governing permissions and limitations under
16    the License.
17	
18	Enables and disables gcov by either setting or removing the 
19	GCC_INSTRUMENT_PROGRAM_FLOW_ARCS & GCC_GENERATE_TEST_COVERAGE_FILES 
20	settings as appropriate, and adding a link to the gcov library
21	if necessary.
22*)
23
24(* 
25	gets passed a list of args from Xcode
26	first arg is whether to enable or disable gcov settings,
27*)
28on run (enable)
29	tell application "Xcode"
30		tell project of active project document
31			set buildconfig to name of active build configuration type
32			tell build configuration buildconfig of active target
33				set needsGcovLib to true
34				try
35					set machOType to value of flattened build setting "MACH_O_TYPE"
36					if (machOType is "staticlib") or (machOType is "mh_object") then
37						set needsGcovLib to false
38					end if
39				end try
40				
41				if item 1 of enable is "YES" then
42					set value of build setting "GCC_INSTRUMENT_PROGRAM_FLOW_ARCS" to "YES"
43					set value of build setting "GCC_GENERATE_TEST_COVERAGE_FILES" to "YES"
44					if needsGcovLib then
45						try
46							set a to value of build setting "OTHER_LDFLAGS"
47						on error
48							set a to "$(inherited)"
49						end try
50						if a does not contain "-lgcov" then
51							set value of build setting "OTHER_LDFLAGS" to a & " -lgcov"
52						end if
53					end if
54				else
55					try
56						delete build setting "GCC_INSTRUMENT_PROGRAM_FLOW_ARCS"
57					end try
58					try
59						delete build setting "GCC_GENERATE_TEST_COVERAGE_FILES"
60					end try
61					if needsGcovLib then
62						try
63							set a to value of build setting "OTHER_LDFLAGS"
64							set oldDelims to AppleScript's text item delimiters
65							set AppleScript's text item delimiters to " "
66							set a to every text item of a
67							set c to {}
68							repeat with b in a
69								if b as string is not equal to "-lgcov" then
70									set c to c & b
71								end if
72							end repeat
73							set a to c as string
74							set AppleScript's text item delimiters to oldDelims
75							if (length of a > 0) and (a ­ "$(inherited)") then
76								set value of build setting "OTHER_LDFLAGS" to a
77							else
78								delete build setting "OTHER_LDFLAGS"
79							end if
80						end try
81					end if
82				end if
83			end tell
84		end tell
85	end tell
86end run