2 -- File: BuildSamplesM5.as
3 -- Purpose: Automatic build of samples with CodeWarrior 5
4 -- Author: Gilles Depeyrot
9 -- This AppleScript automatically recurses through the selected folder looking for
10 -- and building CodeWarrior projects.
11 -- To use this script, simply open it with the 'Script Editor' and run it.
15 -- Suffix used to recognize CodeWarrior project files
17 property gProjectSuffix : "M5.mcp"
20 -- Values used to create the log file
24 property gSeparator : "--------------------------------------------------------------------------------" & gEol
27 -- Project and build success count
29 set theProjectCount to 0
30 set theProjectSuccessCount to 0
33 -- Default log file name
35 set theDate to (day of (current date)) & "/" & GetMonthIndex(current date) & "/" & (year of (current date))
36 set theLogFileName to "wxMac samples " & theDate & ".log"
39 -- Ask the user to select the wxWindows samples folder
41 set theFolder to choose folder with prompt "Select the wxWindows samples folder"
44 -- Ask the user to choose the build log file
46 set theLogFile to choose file name with prompt "Create the wxWindows samples build log file" default name theLogFileName
49 -- Open the log file to record the build log
51 set theLogFileRef to open for access theLogFile with write permission
54 -- Write log file header
56 write gSeparator starting at 0 to theLogFileRef
57 write "wxWindows samples build log" & gEol to theLogFileRef
58 write gSeparator to theLogFileRef
59 write "start on " & ((current date) as string) & gEol to theLogFileRef
60 write gSeparator to theLogFileRef
61 write "building projects in '" & (theFolder as string) & "'" & gEol to theLogFileRef
62 write gSeparator to theLogFileRef
65 -- Build or Rebuild targets?
67 set theText to "Build or rebuild projects?"
68 set theBuild to button returned of (display dialog theText buttons {"Cancel", "Build", "Rebuild"} default button "Rebuild" with icon note)
69 if theBuild is not equal to "Cancel" then
71 -- Build which targets?
73 set theText to theBuild & " Classic or Carbon targets?"
74 set theType to button returned of (display dialog theText buttons {"Cancel", "Classic", "Carbon"} default button "Carbon" with icon note)
75 if theType is not equal to "Cancel" then
77 -- Build Debug or Release targets?
79 set theText to theBuild & " " & theType & " Debug or " & theType & " Release targets?"
80 set theOption to button returned of (display dialog theText buttons {"Cancel", "Release", "Debug"} default button "Debug" with icon note)
81 if theOption is not equal to "Cancel" then
82 set theTarget to theType & " " & theOption
84 write "building project targets '" & theTarget & "'" & gEol to theLogFileRef
85 write gSeparator to theLogFileRef
87 BuildProjects(theLogFileRef, theFolder, theTarget, theBuild is equal to "Rebuild")
94 -- Write log file footer
96 write "successful build of " & theProjectSuccessCount & " projects out of " & theProjectCount & gEol to theLogFileRef
97 write gSeparator to theLogFileRef
98 write "end on " & ((current date) as string) & gEol to theLogFileRef
99 write gSeparator to theLogFileRef
101 -- Close the log file
103 close access theLogFileRef
105 -- Open the file in BBEdit Lite
107 tell application "BBEdit Lite 6.1"
115 on BuildProjects(inLogFileRef, inFolder, inTarget, inRebuild)
116 global theProjectCount, theProjectSuccessCount
118 tell application "Finder" to set theSubFolders to every folder of inFolder
120 repeat with theFolder in theSubFolders
122 tell application "Finder" to set theProject to (the first file of theFolder whose name ends with gProjectSuffix)
124 if theProject as string is not "" then
125 set theProjectCount to theProjectCount + 1
126 write "building project '" & (theProject as string) & "'" & gEol to inLogFileRef
128 tell application "CodeWarrior IDE 4.0.4"
130 -- Open the project in CodeWarrior
132 open theProject as string
134 -- Change to the requested target
136 Set Current Target inTarget
138 -- Remove object code if rebuild requested
144 -- Build/Rebuild the selected target
146 set theBuildInfo to Make Project with ExternalEditor
153 -- Report errors to build log file
155 write gEol to inLogFileRef
156 ReportBuildInfo(inLogFileRef, theBuildInfo)
157 write gSeparator to inLogFileRef
159 BuildProjects(inLogFileRef, theFolder, inTarget, inRebuild)
168 on ReportBuildInfo(inLogFileRef, inBuildInfo)
169 global theProjectCount, theProjectSuccessCount
171 set theErrorCount to 0
172 set theWarningCount to 0
174 repeat with theInfo in inBuildInfo
175 tell application "CodeWarrior IDE 4.0.4"
176 set theKind to ((messageKind of theInfo) as string)
178 write "*** " & theKind & " *** " & message of theInfo & gEol to inLogFileRef
180 set theFile to ((file of theInfo) as string)
184 if theFile is not "" then
185 write theFile & " line " & lineNumber of theInfo & gEol to inLogFileRef
187 write gEol to inLogFileRef
190 if MessageKindIsError(theKind) then
191 set theErrorCount to theErrorCount + 1
193 set theWarningCount to theWarningCount + 1
197 if theErrorCount is 0 then
198 set theProjectSuccessCount to theProjectSuccessCount + 1
199 write "build succeeded with " & theWarningCount & " warning(s)" & gEol to inLogFileRef
201 write "build failed with " & theErrorCount & " error(s) and " & theWarningCount & " warning(s)" & gEol to inLogFileRef
206 -- MessageKindIsError
208 on MessageKindIsError(inKind)
209 if inKind is "compiler error" or inKind is "linker error" or inKind is "generic error" then
214 end MessageKindIsError
219 on GetMonthIndex(inDate)
220 set theMonth to the month of inDate
221 set theMonthList to {January, February, March, April, May, June, July, August, September, October, November, December}
222 repeat with i from 1 to the number of items in theMonthList
223 if theMonth is item i of theMonthList then