CodeWarrior Palm Tips

CodeWarrior for Palm is a pretty good tool, at least relative to PRC-Tools, but it has some limitations.

  • Put RCP files at the top of your first segment. If you don’t, your compiles may fail once since RCP files can build H files that the rest of your project probably uses. Unfortunately, even this doesn’t guarantee success. I generally have my scripts attempt to build a project twice as a result: The first time, I ignore the errors.

Command line compiling

I have found cmdide and ide both to not respond well to command line options to run builds. Ben Combee suggested I give com a try. While I have never used COM or VBS before, I found this pretty easy.

I recommend installing cygwin. GNU make makes this a lot easier, and this is one of the easiest ways to get it. If you don’t install cygwin, you’ll need to build your own PRJ= line.

Two more things before we start:

  1. If you use PilRC to generate headers, builds will often fail the first time the structure is created. It seems CodeWarrior doesn’t know what order to build things in. If you recreate your directory each time from a source control system nightly, this will be every time the script runes! The only 100% fool proof method I’ve found for working around this problem is to have the makefile run the build twice and discard/ignore errors the first time. Sometimes the simplest solution is the best…
  2. In my testing, this never worked when Use Default Workspace was on. I’m not sure if this is a bug in the IDE, or a flaw in my script. Since I don’t like this option anyway, I just turned it off.

makefile

First, in the top of my makefile I define two variables:

PRJ = $(shell cygpath -d "$(shell pwd.exe)")

CCP = cscript /b "$(PRJ)\cwbuild.vbs"

The first line uses cygwin to set $(PRJ) to the current path. $(CCP) invokes our Visual Basic Script… more on that later.

When I want to compile a project, I use a sequence like this:

?


morepalmlib:

    @$(CCP) "$(PRJ)\projects\morepalmos\morepalm.mcp" Debug >> buildlog.txt

    @$(CCP) "$(PRJ)\projects\morepalmos\morepalm.mcp" Release >> buildlog.txt

1
2
3
4
5
morepalmlib:

    @$(CCP) "$(PRJ)\projects\morepalmos\morepalm.mcp" Debug >> buildlog.txt

    @$(CCP) "$(PRJ)\projects\morepalmos\morepalm.mcp" Release >> buildlog.txt

cwbuild.vbs

Next, the script that ties it all together:

?
Main



Sub Main

    Dim projectPath

    Dim targetName

    Dim cwApp, cwProj, cwTrg

    Dim trgCollection, trgName

    Dim buildMsgs

    Dim i



    ' Create the CodeWarrior Application Object

    Set cwApp = CreateObject("CodeWarrior.CodeWarriorApp")



    ' Don't interrupt the build process, take default actions for modal dialogs

    cwApp.AllowUserInteraction = FALSE



    projectPath = WScript.Arguments(0)

    if WScript.Arguments.Count=1 then

        targetName = "*"

    else

        targetName = WScript.Arguments(1)

    end if



    Set cwProj = cwApp.OpenProject( projectPath, TRUE, 0, 1 )



    ' Get the target collection

    Set trgCollection = cwProj.Targets



    ' For every target, build, log error messages

    if targetName = "*" then

        For i = 0 to trgCollection.Count - 1

            Set cwTrg = trgCollection.Item(i)

            trgName = cwTrg.Name

            BuildTarget cwProj, trgName, buildMsgs

        Next

    else

        BuildTarget cwProj, targetName, buildMsgs

    end if



    cwProj.Close



    ' Reset User Interaction Level

    cwApp.AllowUserInteraction = TRUE

End Sub





Sub BuildTarget( cwProj, targetName, buildMsgs )

    Dim errCollection

    Dim errMsg, errCnt

    Dim j

    Dim oStdOut

    Set oStdOut = Wscript.StdOut



    oStdOut.WriteLine "Build report for : " + cwProj.Name + " - " + targetName

    oStdOut.WriteLine "Date : " + CStr(Now)



    cwProj.SetCurrentTarget( targetName )

    cwProj.RemoveObjectCode 0, 1

    Set buildMsgs = cwProj.BuildandWaitToComplete



    Set errCollection = buildMsgs.Errors

    if ( errCollection.Count > 0 ) then

        oStdOut.WriteLine "****** ERRORS:"

        errCnt = errCollection.Count

        For j = 0 to errCnt - 1

            Set errMsg = errCollection.Item(j)

            oStdOut.WriteLine errMsg.MessageText

        Next

    else

        oStdOut.WriteLine "    No Errors."

    end if

        oStdOut.WriteLine ""

End Sub
  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
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
Main



Sub Main

    Dim projectPath

    Dim targetName

    Dim cwApp, cwProj, cwTrg

    Dim trgCollection, trgName

    Dim buildMsgs

    Dim i



    ' Create the CodeWarrior Application Object

    Set cwApp = CreateObject("CodeWarrior.CodeWarriorApp")



    ' Don't interrupt the build process, take default actions for modal dialogs

    cwApp.AllowUserInteraction = FALSE



    projectPath = WScript.Arguments(0)

    if WScript.Arguments.Count=1 then

        targetName = "*"

    else

        targetName = WScript.Arguments(1)

    end if



    Set cwProj = cwApp.OpenProject( projectPath, TRUE, 0, 1 )



    ' Get the target collection

    Set trgCollection = cwProj.Targets



    ' For every target, build, log error messages

    if targetName = "*" then

        For i = 0 to trgCollection.Count - 1

            Set cwTrg = trgCollection.Item(i)

            trgName = cwTrg.Name

            BuildTarget cwProj, trgName, buildMsgs

        Next

    else

        BuildTarget cwProj, targetName, buildMsgs

    end if



    cwProj.Close



    ' Reset User Interaction Level

    cwApp.AllowUserInteraction = TRUE

End Sub





Sub BuildTarget( cwProj, targetName, buildMsgs )

    Dim errCollection

    Dim errMsg, errCnt

    Dim j

    Dim oStdOut

    Set oStdOut = Wscript.StdOut



    oStdOut.WriteLine "Build report for : " + cwProj.Name + " - " + targetName

    oStdOut.WriteLine "Date : " + CStr(Now)



    cwProj.SetCurrentTarget( targetName )

    cwProj.RemoveObjectCode 0, 1

    Set buildMsgs = cwProj.BuildandWaitToComplete



    Set errCollection = buildMsgs.Errors

    if ( errCollection.Count > 0 ) then

        oStdOut.WriteLine "****** ERRORS:"

        errCnt = errCollection.Count

        For j = 0 to errCnt - 1

            Set errMsg = errCollection.Item(j)

            oStdOut.WriteLine errMsg.MessageText

        Next

    else

        oStdOut.WriteLine "    No Errors."

    end if

        oStdOut.WriteLine ""

End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>