aboutsummaryrefslogtreecommitdiff
path: root/XcodePlugin/Resources/EnableGCov.applescript
blob: 9baecb1537656a777653ea1232f40d0d8c22327c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
(*
	EnableGCov.applescript
	
    Copyright 2007-2009 Google Inc.
  
    Licensed under the Apache License, Version 2.0 (the "License"); you may not
    use this file except in compliance with the License.  You may obtain a copy
    of the License at
   
    http://www.apache.org/licenses/LICENSE-2.0
   
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
    License for the specific language governing permissions and limitations under
    the License.
	
	Enables and disables gcov by either setting or removing the 
	GCC_INSTRUMENT_PROGRAM_FLOW_ARCS & GCC_GENERATE_TEST_COVERAGE_FILES 
	settings as appropriate, and adding a link to the gcov library
	if necessary.
*)

(* 
	gets passed a list of args from Xcode
	first arg is whether to enable or disable gcov settings,
*)
on run (enable)
	tell application "Xcode"
		tell project of active project document
			set buildconfig to name of active build configuration type
			tell build configuration buildconfig of active target
				set needsGcovLib to true
				try
					set machOType to value of flattened build setting "MACH_O_TYPE"
					if (machOType is "staticlib") or (machOType is "mh_object") then
						set needsGcovLib to false
					end if
				end try
				
				if item 1 of enable is "YES" then
					set value of build setting "GCC_INSTRUMENT_PROGRAM_FLOW_ARCS" to "YES"
					set value of build setting "GCC_GENERATE_TEST_COVERAGE_FILES" to "YES"
					if needsGcovLib then
						try
							set a to value of build setting "OTHER_LDFLAGS"
						on error
							set a to "$(inherited)"
						end try
						if a does not contain "-lgcov" then
							set value of build setting "OTHER_LDFLAGS" to a & " -lgcov"
						end if
					end if
				else
					try
						delete build setting "GCC_INSTRUMENT_PROGRAM_FLOW_ARCS"
					end try
					try
						delete build setting "GCC_GENERATE_TEST_COVERAGE_FILES"
					end try
					if needsGcovLib then
						try
							set a to value of build setting "OTHER_LDFLAGS"
							set oldDelims to AppleScript's text item delimiters
							set AppleScript's text item delimiters to " "
							set a to every text item of a
							set c to {}
							repeat with b in a
								if b as string is not equal to "-lgcov" then
									set c to c & b
								end if
							end repeat
							set a to c as string
							set AppleScript's text item delimiters to oldDelims
							if (length of a > 0) and (a ­ "$(inherited)") then
								set value of build setting "OTHER_LDFLAGS" to a
							else
								delete build setting "OTHER_LDFLAGS"
							end if
						end try
					end if
				end if
			end tell
		end tell
	end tell
end run