1 -----------------------------------------------------------------------------
2 -- Name: docs/mac/M5build.applescript
3 -- Purpose: Automatic build of projects with CodeWarrior 5
4 -- Author: Gilles Depeyrot
8 -- Copyright: (c) 2001 Gilles Depeyrot
9 -- Licence: wxWindows licence
10 -----------------------------------------------------------------------------
12 -- This AppleScript automatically recurses through the selected folder looking for
13 -- and building CodeWarrior projects.
14 -- To use this script, simply open it with the 'Script Editor' and run it.
18 -- Suffix used to recognize CodeWarrior project files
20 property gProjectSuffix : "M5.mcp"
23 -- Values used to create the log file
27 property gSeparator : "--------------------------------------------------------------------------------" & gEol
30 -- Project and build success count
32 set theProjectCount to 0
33 set theProjectSuccessCount to 0
36 -- Default log file name
38 set theDate to (day of (current date)) & "/" & GetMonthIndex(current date) & "/" & (year of (current date))
39 set theLogFileName to "wxMac samples " & theDate & ".log"
42 -- Ask the user to select the wxWindows samples folder
44 set theFolder to choose folder with prompt "Select the wxWindows samples folder"
47 -- Ask the user to choose the build log file
49 set theLogFile to choose file name with prompt "Create the wxWindows samples build log file" default name theLogFileName
52 -- Open the log file to record the build log
54 set theLogFileRef to open for access theLogFile with write permission
57 -- Write log file header
59 write gSeparator starting at 0 to theLogFileRef
60 write "wxWindows samples build log" & gEol to theLogFileRef
61 write gSeparator to theLogFileRef
62 write "start on " & ((current date) as string) & gEol to theLogFileRef
63 write gSeparator to theLogFileRef
64 write "building projects in '" & (theFolder as string) & "'" & gEol to theLogFileRef
65 write gSeparator to theLogFileRef
68 -- Build or Rebuild targets?
70 set theText to "Build or rebuild projects?"
71 set theBuild to button returned of (display dialog theText buttons {"Cancel", "Build", "Rebuild"} default button "Rebuild" with icon note)
72 if theBuild is not equal to "Cancel" then
74 -- Build which targets?
76 set theText to theBuild & " Classic or Carbon targets?"
77 set theType to button returned of (display dialog theText buttons {"Cancel", "Classic", "Carbon"} default button "Carbon" with icon note)
78 if theType is not equal to "Cancel" then
80 -- Build Debug or Release targets?
82 set theText to theBuild & " " & theType & " Debug or " & theType & " Release targets?"
83 set theOption to button returned of (display dialog theText buttons {"Cancel", "Release", "Debug"} default button "Debug" with icon note)
84 if theOption is not equal to "Cancel" then
85 set theTarget to theType & " " & theOption
87 write "building project targets '" & theTarget & "'" & gEol to theLogFileRef
88 write gSeparator to theLogFileRef
90 BuildProjects(theLogFileRef, theFolder, theTarget, theBuild is equal to "Rebuild")
97 -- Write log file footer
99 write "successful build of " & theProjectSuccessCount & " projects out of " & theProjectCount & gEol to theLogFileRef
100 write gSeparator to theLogFileRef
101 write "end on " & ((current date) as string) & gEol to theLogFileRef
102 write gSeparator to theLogFileRef
104 -- Close the log file
106 close access theLogFileRef
108 -- Open the file in BBEdit Lite
110 tell application "BBEdit Lite 6.1"
118 on BuildProjects(inLogFileRef, inFolder, inTarget, inRebuild)
119 global theProjectCount, theProjectSuccessCount
122 tell application "Finder" to set theProject to ((the first file of inFolder whose name ends with gProjectSuffix) as string)
127 if theProject is not "" then
128 set theProjectCount to theProjectCount + 1
130 write "building project '" & (theProject as string) & "'" & gEol to inLogFileRef
132 tell application "CodeWarrior IDE 4.0.4"
134 -- Open the project in CodeWarrior
136 open theProject as string
138 -- Change to the requested target
140 Set Current Target inTarget
142 -- Remove object code if rebuild requested
148 -- Build/Rebuild the selected target
150 set theBuildInfo to Make Project with ExternalEditor
157 -- Report errors to build log file
159 write gEol to inLogFileRef
160 ReportBuildInfo(inLogFileRef, theBuildInfo)
161 write gSeparator to inLogFileRef
164 tell application "Finder" to set theSubFolders to every folder of inFolder
165 repeat with theFolder in theSubFolders
166 BuildProjects(inLogFileRef, theFolder, inTarget, inRebuild)
174 on ReportBuildInfo(inLogFileRef, inBuildInfo)
175 global theProjectCount, theProjectSuccessCount
177 set theErrorCount to 0
178 set theWarningCount to 0
180 repeat with theInfo in inBuildInfo
181 tell application "CodeWarrior IDE 4.0.4"
182 set theKind to ((messageKind of theInfo) as string)
184 write "*** " & theKind & " *** " & message of theInfo & gEol to inLogFileRef
186 set theFile to ((file of theInfo) as string)
190 if theFile is not "" then
191 write theFile & " line " & lineNumber of theInfo & gEol to inLogFileRef
193 write gEol to inLogFileRef
196 if MessageKindIsError(theKind) then
197 set theErrorCount to theErrorCount + 1
199 set theWarningCount to theWarningCount + 1
203 if theErrorCount is 0 then
204 set theProjectSuccessCount to theProjectSuccessCount + 1
205 write "build succeeded with " & theWarningCount & " warning(s)" & gEol to inLogFileRef
207 write "build failed with " & theErrorCount & " error(s) and " & theWarningCount & " warning(s)" & gEol to inLogFileRef
212 -- MessageKindIsError
214 on MessageKindIsError(inKind)
215 if inKind is "compiler error" or inKind is "linker error" or inKind is "generic error" then
220 end MessageKindIsError
225 on GetMonthIndex(inDate)
226 set theMonth to the month of inDate
227 set theMonthList to {January, February, March, April, May, June, July, August, September, October, November, December}
228 repeat with i from 1 to the number of items in theMonthList
229 if theMonth is item i of theMonthList then