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 "build-" & theDate & ".log"
 
  42 -- Ask the user to select the wxWindows samples folder
 
  44 set theFolder to choose folder with prompt "Select the folder in which to build the projects"
 
  47 -- Ask the user to choose the build log file
 
  49 set theLogFile to choose file name with prompt "Save the 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 "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
 
 111 on BuildProjects(inLogFileRef, inFolder, inTarget, inRebuild)
 
 112         global theProjectCount, theProjectSuccessCount
 
 114         tell application "Finder" to update inFolder
 
 117                 tell application "Finder" to set theProject to ((the first file of inFolder whose name ends with gProjectSuffix) as string)
 
 122         if theProject is not "" then
 
 123                 set theProjectCount to theProjectCount + 1
 
 125                 write "building project '" & theProject & "'" & gEol to inLogFileRef
 
 127                 tell application "CodeWarrior IDE 4.0.4"
 
 129                         -- Open the project in CodeWarrior
 
 133                         -- Change to the requested target
 
 135                         Set Current Target inTarget
 
 137                         -- Remove object code if rebuild requested
 
 143                         -- Build/Rebuild the selected target
 
 145                         set theBuildInfo to Make Project with ExternalEditor
 
 152                 -- Report errors to build log file
 
 154                 write gEol to inLogFileRef
 
 155                 ReportBuildInfo(inLogFileRef, theBuildInfo)
 
 156                 write gSeparator to inLogFileRef
 
 159         tell application "Finder" to set theSubFolders to every folder of inFolder whose name does not end with " Data"
 
 160         repeat with theFolder in theSubFolders
 
 161                 BuildProjects(inLogFileRef, theFolder, inTarget, inRebuild)
 
 169 on ReportBuildInfo(inLogFileRef, inBuildInfo)
 
 170         global theProjectCount, theProjectSuccessCount
 
 172         set theErrorCount to 0
 
 173         set theWarningCount to 0
 
 175         repeat with theInfo in inBuildInfo
 
 176                 tell application "CodeWarrior IDE 4.0.4"
 
 177                         set theKind to ((messageKind of theInfo) as string)
 
 179                         tell me to write "*** " & theKind & " *** " & message of theInfo & gEol to inLogFileRef
 
 181                                 set theFile to ((file of theInfo) as string)
 
 185                         if theFile is not "" then
 
 186                                 tell me to write theFile & " line " & lineNumber of theInfo & gEol to inLogFileRef
 
 188                         tell me to write gEol to inLogFileRef
 
 191                 if MessageKindIsError(theKind) then
 
 192                         set theErrorCount to theErrorCount + 1
 
 194                         set theWarningCount to theWarningCount + 1
 
 198         if theErrorCount is 0 then
 
 199                 set theProjectSuccessCount to theProjectSuccessCount + 1
 
 200                 write "build succeeded with " & theWarningCount & " warning(s)" & gEol to inLogFileRef
 
 202                 write "build failed with " & theErrorCount & " error(s) and " & theWarningCount & " warning(s)" & gEol to inLogFileRef
 
 207 -- MessageKindIsError
 
 209 on MessageKindIsError(inKind)
 
 210         if inKind is "compiler error" or inKind is "linker error" or inKind is "generic error" then
 
 215 end MessageKindIsError
 
 220 on GetMonthIndex(inDate)
 
 221         set theMonth to the month of inDate
 
 222         set theMonthList to {January, February, March, April, May, June, July, August, September, October, November, December}
 
 223         repeat with i from 1 to the number of items in theMonthList
 
 224                 if theMonth is item i of theMonthList then