ProjectBuilder.st
author Claus Gittinger <cg@exept.de>
Sun, 11 Oct 2009 02:27:08 +0200
changeset 2613 b8d38caaa884
parent 2612 2e735008a4d8
child 2614 ff815b56c808
permissions -rw-r--r--
changed: #buildWithOutputTo:errorTo:
cg@2596
     1
"{ Package: 'stx:libtool2' }"
cg@2596
     2
cg@2596
     3
Object subclass:#ProjectBuilder
cg@2596
     4
	instanceVariableNames:'package projectDefinitionClass sourceCodeManager buildDirectory
cg@2598
     5
		myWorkingDirectory mySTXTopDirectory myTopDirectory'
cg@2596
     6
	classVariableNames:'PreviousBuildDirectory'
cg@2596
     7
	poolDictionaries:''
cg@2596
     8
	category:'System-Support-Projects'
cg@2596
     9
!
cg@2596
    10
cg@2596
    11
cg@2596
    12
!ProjectBuilder class methodsFor:'examples'!
cg@2596
    13
cg@2596
    14
example1
cg@2596
    15
    Smalltalk loadPackage:'stx:projects/helloWorldApp' asAutoloaded:true.
cg@2596
    16
cg@2596
    17
    self new
cg@2596
    18
        package:'stx:projects/helloWorldApp';
cg@2596
    19
        build
cg@2596
    20
! !
cg@2596
    21
cg@2596
    22
!ProjectBuilder methodsFor:'accessing'!
cg@2596
    23
cg@2596
    24
package:aPackageIDOrSymbol
cg@2596
    25
    package := aPackageIDOrSymbol asPackageId.
cg@2596
    26
!
cg@2596
    27
cg@2596
    28
projectDefinitionClass:something
cg@2596
    29
    projectDefinitionClass := something.
cg@2596
    30
! !
cg@2596
    31
cg@2596
    32
!ProjectBuilder methodsFor:'building'!
cg@2596
    33
cg@2596
    34
build
cg@2596
    35
    "/ intermediate - this will move into a commonly used utility class
cg@2596
    36
    "/ (where all the project code support will be collected).
cg@2596
    37
cg@2611
    38
    |makeOutput stdOut stdErr lock|
cg@2611
    39
cg@2611
    40
    lock := Semaphore forMutualExclusion.
cg@2611
    41
    makeOutput := TextStream on:(Text new:10000).
cg@2611
    42
    stdErr := ActorStream new
cg@2611
    43
                    nextPutBlock:[:char |
cg@2611
    44
                        lock critical:[
cg@2611
    45
                            makeOutput emphasis:{#backgroundColor->Color red. #color->Color white.}.
cg@2611
    46
                            makeOutput nextPut:char.
cg@2611
    47
                            makeOutput emphasis:nil.
cg@2611
    48
                        ]
cg@2611
    49
                    ];
cg@2611
    50
                    nextPutAllBlock:[:char |
cg@2611
    51
                        lock critical:[
cg@2611
    52
                            makeOutput emphasis:{#backgroundColor->Color red. #color->Color white.}.
cg@2611
    53
                            makeOutput nextPutAll:char.
cg@2611
    54
                            makeOutput emphasis:nil.
cg@2611
    55
                        ]
cg@2611
    56
                    ].
cg@2611
    57
    stdOut := ActorStream new
cg@2611
    58
                    nextPutBlock:[:char |
cg@2611
    59
                        lock critical:[
cg@2611
    60
                            makeOutput nextPut:char.
cg@2611
    61
                        ]
cg@2611
    62
                    ];
cg@2611
    63
                    nextPutAllBlock:[:char |
cg@2611
    64
                        lock critical:[
cg@2611
    65
                            makeOutput nextPutAll:char.
cg@2611
    66
                        ]
cg@2611
    67
                    ].
cg@2611
    68
cg@2611
    69
    self buildWithOutputTo:stdOut errorTo:stdErr.
cg@2611
    70
cg@2611
    71
    TextView openWith:makeOutput contents.
cg@2611
    72
!
cg@2611
    73
cg@2611
    74
buildWithOutputTo:stdOut errorTo:stdErr
cg@2611
    75
    "/ intermediate - this will move into a commonly used utility class
cg@2611
    76
    "/ (where all the project code support will be collected).
cg@2611
    77
cg@2596
    78
    |module directory|
cg@2596
    79
cg@2596
    80
    projectDefinitionClass := ProjectDefinition definitionClassForPackage:package.
cg@2596
    81
    projectDefinitionClass isNil ifTrue:[
cg@2596
    82
        self error:('Missing ProjectDefinition class for "',package asString,'"')
cg@2596
    83
    ].
cg@2596
    84
cg@2596
    85
    "/ ensure that everything is loaded...
cg@2596
    86
    projectDefinitionClass loadAsAutoloaded:false.
cg@2596
    87
    projectDefinitionClass loadExtensions.
cg@2596
    88
    projectDefinitionClass loadAllClassesAsAutoloaded:false.
cg@2596
    89
cg@2596
    90
    module := package module.
cg@2596
    91
    directory := package directory.
cg@2596
    92
cg@2596
    93
    buildDirectory := PreviousBuildDirectory ifNil:[ UserPreferences current buildDirectory ].
cg@2596
    94
    buildDirectory isNil ifTrue:[
cg@2596
    95
        buildDirectory := Filename tempDirectory construct:'stx_build'.
cg@2596
    96
    ].
cg@2596
    97
    buildDirectory := buildDirectory asFilename.
cg@2596
    98
cg@2596
    99
    "/ self validateBuildDirectoryIsPresent.
cg@2596
   100
cg@2596
   101
    PreviousBuildDirectory := buildDirectory.
cg@2596
   102
cg@2596
   103
    "/ UserPreferences current localBuild:true
cg@2596
   104
    UserPreferences current localBuild ifFalse:[
cg@2596
   105
        SourceCodeManager notNil ifTrue:[
cg@2596
   106
            sourceCodeManager := SourceCodeManagerUtilities sourceCodeManagerFor:projectDefinitionClass.
cg@2596
   107
        ]
cg@2596
   108
    ].
cg@2596
   109
    sourceCodeManager := nil.
cg@2596
   110
cg@2598
   111
    myTopDirectory := 
cg@2596
   112
        Smalltalk packagePath 
cg@2596
   113
            detect:[:aPath |
cg@2596
   114
                (aPath asFilename / 'stx' / 'include') exists
cg@2596
   115
                and: [ (aPath asFilename / 'stx' / 'rules') exists ]]
cg@2596
   116
            ifNone:nil.       
cg@2598
   117
    myTopDirectory isNil ifTrue:[
cg@2598
   118
        self error:('Cannot figure out my top directory (where stx/include and stx/rules are)')
cg@2596
   119
    ].
cg@2598
   120
    myTopDirectory := myTopDirectory asFilename.
cg@2598
   121
    mySTXTopDirectory := myTopDirectory / 'stx'.
cg@2613
   122
cg@2596
   123
    self setupBuildDirectory.
cg@2599
   124
    self copySTCDirectoryForBuild.
cg@2596
   125
    self generateSourceFiles.
cg@2600
   126
    self copyDLLsForLinkage.
cg@2600
   127
    self copySupportFilesForLinkage.
cg@2600
   128
    self copyStartupFilesFromSmalltalk.
cg@2596
   129
cg@2611
   130
    self makeWithOutputTo:stdOut errorTo:stdErr.
cg@2596
   131
!
cg@2596
   132
cg@2613
   133
stdErr.
cg@2600
   134
!
cg@2600
   135
cg@2613
   136
].
cg@2596
   137
!
cg@2596
   138
cg@2613
   139
'stx').
cg@2598
   140
!
cg@2598
   141
cg@2613
   142
ion:nil
cg@2600
   143
!
cg@2600
   144
cg@2613
   145
].
cg@2599
   146
!
cg@2599
   147
cg@2613
   148
ion:nil
cg@2600
   149
!
cg@2600
   150
cg@2613
   151
]
cg@2600
   152
!
cg@2600
   153
cg@2613
   154
].
cg@2596
   155
!
cg@2596
   156
cg@2613
   157
].
cg@2596
   158
!
cg@2596
   159
cg@2613
   160
]
cg@2596
   161
!
cg@2596
   162
cg@2613
   163
f halt.
cg@2596
   164
!
cg@2596
   165
cg@2611
   166
makeWithOutputTo:stdOut errorTo:stdErr
cg@2611
   167
    |module directory|
cg@2611
   168
cg@2611
   169
    module := package module.
cg@2611
   170
    directory := package directory.
cg@2611
   171
cg@2612
   172
    projectDefinitionClass isLibraryDefinition ifTrue:[
cg@2612
   173
        OperatingSystem
cg@2612
   174
            executeCommand:(ParserFlags makeCommand,' classLibRule')
cg@2612
   175
            inputFrom:nil
cg@2612
   176
            outputTo:stdOut
cg@2612
   177
            errorTo:stdErr
cg@2612
   178
            inDirectory:(buildDirectory / module / directory)
cg@2612
   179
            onError:[:status| self error:'make failed'].
cg@2612
   180
    ] ifFalse:[
cg@2612
   181
        OperatingSystem
cg@2612
   182
            executeCommand:(ParserFlags makeCommand,' exe')
cg@2612
   183
            inputFrom:nil
cg@2612
   184
            outputTo:stdOut
cg@2612
   185
            errorTo:stdErr
cg@2612
   186
            inDirectory:(buildDirectory / module / directory)
cg@2612
   187
            onError:[:status| self error:'make failed'].
cg@2611
   188
cg@2612
   189
        OperatingSystem
cg@2612
   190
            executeCommand:(ParserFlags makeCommand,' setup')
cg@2612
   191
            inputFrom:nil
cg@2612
   192
            outputTo:stdOut
cg@2612
   193
            errorTo:stdErr
cg@2612
   194
            inDirectory:(buildDirectory / module / directory)
cg@2612
   195
            onError:[:status| self error:'make failed'].
cg@2612
   196
    ]
cg@2611
   197
!
cg@2611
   198
cg@2613
   199
errorTo:stdErr
cg@2613
   200
            inDirectory:(buildDirectory / module / directory)
cg@2613
   201
            onError:[:status| self error:'make failed'].
cg@2596
   202
cg@2613
   203
        OperatingSystem
cg@2613
   204
            executeCommand:(ParserFlags makeCommand,' setup')
cg@2613
   205
            inputFrom:nil
cg@2613
   206
            outputTo:stdOut
cg@2613
   207
            errorTo:stdErr
cg@2613
   208
            inDirectory:(buildDirectory / module / directory)
cg@2613
   209
            onError:[:status| self error:'make failed'].
cg@2613
   210
    ]
cg@2596
   211
!
cg@2596
   212
cg@2613
   213
:stdErr
cg@2613
   214
            inDirectory:(buildDirectory / module / directory)
cg@2613
   215
            onError:[:status| self error:'make failed'].
cg@2613
   216
    ]
cg@2596
   217
! !
cg@2596
   218
cg@2596
   219
!ProjectBuilder class methodsFor:'documentation'!
cg@2596
   220
cg@2596
   221
version_CVS
cg@2596
   222
    ^ '$Header$'
cg@2596
   223
! !