2596
|
1 |
"{ Package: 'stx:libtool2' }"
|
|
2 |
|
|
3 |
Object subclass:#ProjectBuilder
|
|
4 |
instanceVariableNames:'package projectDefinitionClass sourceCodeManager buildDirectory
|
2598
|
5 |
myWorkingDirectory mySTXTopDirectory myTopDirectory'
|
2596
|
6 |
classVariableNames:'PreviousBuildDirectory'
|
|
7 |
poolDictionaries:''
|
|
8 |
category:'System-Support-Projects'
|
|
9 |
!
|
|
10 |
|
|
11 |
|
|
12 |
!ProjectBuilder class methodsFor:'examples'!
|
|
13 |
|
|
14 |
example1
|
|
15 |
Smalltalk loadPackage:'stx:projects/helloWorldApp' asAutoloaded:true.
|
|
16 |
|
|
17 |
self new
|
|
18 |
package:'stx:projects/helloWorldApp';
|
|
19 |
build
|
|
20 |
! !
|
|
21 |
|
|
22 |
!ProjectBuilder methodsFor:'accessing'!
|
|
23 |
|
|
24 |
package:aPackageIDOrSymbol
|
|
25 |
package := aPackageIDOrSymbol asPackageId.
|
|
26 |
!
|
|
27 |
|
|
28 |
projectDefinitionClass:something
|
|
29 |
projectDefinitionClass := something.
|
|
30 |
! !
|
|
31 |
|
|
32 |
!ProjectBuilder methodsFor:'building'!
|
|
33 |
|
|
34 |
build
|
|
35 |
"/ intermediate - this will move into a commonly used utility class
|
|
36 |
"/ (where all the project code support will be collected).
|
|
37 |
|
|
38 |
|module directory|
|
|
39 |
|
|
40 |
projectDefinitionClass := ProjectDefinition definitionClassForPackage:package.
|
|
41 |
projectDefinitionClass isNil ifTrue:[
|
|
42 |
self error:('Missing ProjectDefinition class for "',package asString,'"')
|
|
43 |
].
|
|
44 |
|
|
45 |
"/ ensure that everything is loaded...
|
|
46 |
projectDefinitionClass loadAsAutoloaded:false.
|
|
47 |
projectDefinitionClass loadExtensions.
|
|
48 |
projectDefinitionClass loadAllClassesAsAutoloaded:false.
|
|
49 |
|
|
50 |
module := package module.
|
|
51 |
directory := package directory.
|
|
52 |
|
|
53 |
buildDirectory := PreviousBuildDirectory ifNil:[ UserPreferences current buildDirectory ].
|
|
54 |
buildDirectory isNil ifTrue:[
|
|
55 |
buildDirectory := Filename tempDirectory construct:'stx_build'.
|
|
56 |
].
|
|
57 |
buildDirectory := buildDirectory asFilename.
|
|
58 |
|
|
59 |
"/ self validateBuildDirectoryIsPresent.
|
|
60 |
|
|
61 |
PreviousBuildDirectory := buildDirectory.
|
|
62 |
|
|
63 |
"/ UserPreferences current localBuild:true
|
|
64 |
UserPreferences current localBuild ifFalse:[
|
|
65 |
SourceCodeManager notNil ifTrue:[
|
|
66 |
sourceCodeManager := SourceCodeManagerUtilities sourceCodeManagerFor:projectDefinitionClass.
|
|
67 |
]
|
|
68 |
].
|
|
69 |
sourceCodeManager := nil.
|
|
70 |
|
2598
|
71 |
myTopDirectory :=
|
2596
|
72 |
Smalltalk packagePath
|
|
73 |
detect:[:aPath |
|
|
74 |
(aPath asFilename / 'stx' / 'include') exists
|
|
75 |
and: [ (aPath asFilename / 'stx' / 'rules') exists ]]
|
|
76 |
ifNone:nil.
|
2598
|
77 |
myTopDirectory isNil ifTrue:[
|
|
78 |
self error:('Cannot figure out my top directory (where stx/include and stx/rules are)')
|
2596
|
79 |
].
|
2598
|
80 |
myTopDirectory := myTopDirectory asFilename.
|
|
81 |
mySTXTopDirectory := myTopDirectory / 'stx'.
|
2596
|
82 |
|
|
83 |
self setupBuildDirectory.
|
|
84 |
self generateSourceFiles.
|
2598
|
85 |
self halt.
|
2596
|
86 |
|
|
87 |
OperatingSystem
|
|
88 |
executeCommand:(ParserFlags makeCommand)
|
|
89 |
inputFrom:nil
|
|
90 |
outputTo:Transcript
|
|
91 |
errorTo:Transcript
|
|
92 |
inDirectory:((buildDirectory construct:module) construct:directory)
|
|
93 |
onError:[:status| self error:'make failed'].
|
|
94 |
|
|
95 |
"Created: / 09-08-2006 / 18:37:19 / fm"
|
|
96 |
"Modified: / 09-08-2006 / 19:55:50 / fm"
|
|
97 |
"Modified: / 22-09-2006 / 17:37:11 / cg"
|
|
98 |
!
|
|
99 |
|
|
100 |
copyDirectory:relativepath
|
|
101 |
"/ need rules in stx
|
|
102 |
((Smalltalk projectDirectoryForPackage:'stx') asFilename construct:relativepath)
|
|
103 |
recursiveCopyTo:(buildDirectory construct:'stx').
|
|
104 |
!
|
|
105 |
|
|
106 |
copyDirectoryForBuild:subdir
|
2598
|
107 |
|targetDir targetFile|
|
2596
|
108 |
|
|
109 |
targetDir := buildDirectory / 'stx' / subdir.
|
|
110 |
targetDir exists ifFalse:[
|
|
111 |
targetDir makeDirectory.
|
2598
|
112 |
].
|
|
113 |
(mySTXTopDirectory / subdir) directoryContentsAsFilenamesDo:[:eachFile |
|
|
114 |
eachFile isDirectory ifFalse:[
|
|
115 |
targetFile := targetDir / eachFile baseName.
|
|
116 |
(targetFile exists not
|
|
117 |
or:[ targetFile modificationTime < eachFile modificationTime ]) ifTrue:[
|
|
118 |
self activityNotification:'copying ',eachFile pathName,'...'.
|
2596
|
119 |
eachFile copyTo:(targetDir construct:eachFile baseName)
|
|
120 |
]
|
|
121 |
].
|
|
122 |
].
|
2598
|
123 |
self activityNotification:nil
|
|
124 |
!
|
|
125 |
|
|
126 |
createHeaderFileFor:aClass in:packageTargetDir
|
|
127 |
|instVarList classInstVarList classVarList bindings superclassFilename
|
|
128 |
template file newContents oldContents|
|
|
129 |
|
|
130 |
instVarList := StringCollection new.
|
|
131 |
aClass instVarNames do:[:v |
|
|
132 |
instVarList add:('OBJ %1;' bindWith:v)
|
|
133 |
].
|
|
134 |
classInstVarList := StringCollection new.
|
|
135 |
aClass class instVarNames do:[:v |
|
|
136 |
(v includes:$_) ifTrue:[self halt].
|
|
137 |
classInstVarList add:('OBJ %1;' bindWith:v)
|
|
138 |
].
|
|
139 |
classVarList := StringCollection new.
|
|
140 |
aClass classVarNames do:[:v |
|
|
141 |
classVarList add:('extern OBJ %1_%2;' bindWith:aClass name with:v)
|
|
142 |
].
|
|
143 |
|
|
144 |
bindings := Dictionary new.
|
|
145 |
bindings at:'ClassName' put:aClass name.
|
|
146 |
aClass superclass isNil ifTrue:[
|
|
147 |
bindings at:'SuperclassName' put:'-'.
|
|
148 |
bindings at:'SuperclassFileInclude' put:nil.
|
|
149 |
] ifFalse:[
|
|
150 |
bindings at:'SuperclassName' put:aClass superclass name.
|
|
151 |
bindings at:'SuperclassFileName' put:(superclassFilename := Smalltalk fileNameForClass:aClass superclass).
|
|
152 |
bindings at:'SuperclassFileInclude' put:('#include "%1.STH"' bindWith:superclassFilename).
|
|
153 |
].
|
|
154 |
bindings at:'InstVarList' put:instVarList asString.
|
|
155 |
bindings at:'ClassVarList' put:classVarList asString.
|
|
156 |
bindings at:'ClassInstVarList' put:classInstVarList asString.
|
|
157 |
|
|
158 |
template :=
|
|
159 |
'/* This file was generated by ProjectBuilder. */
|
|
160 |
/* !!!!!!!! Do not change by hand !!!!!!!! */
|
|
161 |
|
|
162 |
/* Class: %(ClassName) */
|
|
163 |
/* Superclass: %(SuperclassName) */
|
|
164 |
|
|
165 |
%(SuperclassFileInclude)
|
|
166 |
|
|
167 |
/* INDIRECTGLOBALS */
|
|
168 |
#ifdef _HEADER_INST_
|
|
169 |
%(InstVarList)
|
|
170 |
#endif /* _HEADER_INST_ */
|
|
171 |
|
|
172 |
#ifdef _HEADER_CLASS_
|
|
173 |
%(ClassVarList)
|
|
174 |
#endif /* _HEADER_CLASS_ */
|
|
175 |
|
|
176 |
#ifdef _HEADER_CLASSINST_
|
|
177 |
%(ClassInstVarList)
|
|
178 |
#endif /* _HEADER_CLASSINST_ */
|
|
179 |
'.
|
|
180 |
newContents := template bindWithArguments:bindings.
|
|
181 |
file := packageTargetDir asFilename / ((Smalltalk fileNameForClass:aClass),'.STH').
|
|
182 |
(file exists not
|
|
183 |
or:[ (oldContents := file contents) ~= newContents ]) ifTrue:[
|
|
184 |
file contents: newContents.
|
|
185 |
].
|
2596
|
186 |
!
|
|
187 |
|
|
188 |
generateSourceFiles
|
|
189 |
sourceCodeManager notNil ifTrue:[
|
|
190 |
"/ check out / generate files there
|
|
191 |
self generateSourceFilesByCheckingOutUsing:sourceCodeManager
|
|
192 |
] ifFalse:[
|
|
193 |
"/ local build
|
|
194 |
"/ fileout the project
|
|
195 |
self generateSourceFilesByFilingOut
|
|
196 |
]
|
|
197 |
!
|
|
198 |
|
|
199 |
generateSourceFilesByCheckingOutUsing:aSourceCodeManager
|
|
200 |
"/ will no longer be needed/supported
|
|
201 |
|
|
202 |
|repository stxRepository module directory|
|
|
203 |
|
|
204 |
self halt.
|
|
205 |
"/ check out / generate files there
|
|
206 |
repository := (aSourceCodeManager repositoryNameForModule:module) ifNil:[aSourceCodeManager repositoryName].
|
|
207 |
stxRepository := aSourceCodeManager repositoryName.
|
|
208 |
|
|
209 |
(buildDirectory construct:'stx') exists ifFalse:[
|
|
210 |
(module ~= 'stx') ifTrue:[
|
|
211 |
OperatingSystem
|
|
212 |
executeCommand:('cvs -d ',stxRepository,' co stx')
|
|
213 |
inputFrom:nil
|
|
214 |
outputTo:Transcript
|
|
215 |
errorTo:Transcript
|
|
216 |
inDirectory:buildDirectory
|
|
217 |
onError:[:status| self error:'cvs update stx failed'].
|
|
218 |
].
|
|
219 |
].
|
|
220 |
|
|
221 |
((buildDirectory construct:module) construct:'CVS') exists ifFalse:[
|
|
222 |
OperatingSystem
|
|
223 |
executeCommand:('cvs -d ',repository,' co -l ',directory)
|
|
224 |
inputFrom:nil
|
|
225 |
outputTo:Transcript
|
|
226 |
errorTo:Transcript
|
|
227 |
inDirectory:buildDirectory
|
|
228 |
onError:[:status| self error:'cvs update failed'].
|
|
229 |
].
|
|
230 |
OperatingSystem
|
|
231 |
executeCommand:'cvs upd -d'
|
|
232 |
inputFrom:nil
|
|
233 |
outputTo:Transcript
|
|
234 |
errorTo:Transcript
|
|
235 |
inDirectory:(buildDirectory construct:module)
|
|
236 |
onError:[:status| self error:'cvs update failed'].
|
|
237 |
self halt.
|
|
238 |
!
|
|
239 |
|
|
240 |
generateSourceFilesByFilingOut
|
|
241 |
|targetDir prerequisitePackages|
|
|
242 |
|
|
243 |
"/ local build
|
|
244 |
"/ fileout the project
|
|
245 |
|
|
246 |
(package module ~= 'stx') ifTrue:[
|
|
247 |
(buildDirectory / package module) makeDirectory.
|
|
248 |
].
|
|
249 |
|
|
250 |
"/ file out the package(s)
|
2598
|
251 |
((Array with:package))
|
2596
|
252 |
do:[:eachPackageToFileout |
|
2598
|
253 |
|packageId packageModule packageDirectory packageTargetDir packageDef|
|
2596
|
254 |
|
2598
|
255 |
packageId := eachPackageToFileout asPackageId.
|
|
256 |
packageModule := packageId module.
|
|
257 |
packageDirectory := packageId directory.
|
2596
|
258 |
packageTargetDir := (buildDirectory / packageModule / packageDirectory) recursiveMakeDirectory.
|
|
259 |
|
2598
|
260 |
packageDef := packageId projectDefinitionClass.
|
|
261 |
(packageDef compiled_classNames_common ,
|
|
262 |
packageDef compiled_classNamesForPlatform) do:[:eachClassName |
|
|
263 |
|cls|
|
|
264 |
|
|
265 |
cls := Smalltalk classNamed:eachClassName.
|
|
266 |
self assert:cls isLoaded.
|
|
267 |
cls fileOutIn:packageTargetDir
|
2596
|
268 |
].
|
2598
|
269 |
|
|
270 |
"/ (Smalltalk allClassesInPackage:eachPackageToFileout) do:[:cls |
|
|
271 |
"/ cls isPrivate ifFalse:[
|
|
272 |
"/ cls isLoaded ifFalse:[
|
|
273 |
"/ self halt.
|
|
274 |
"/ cls autoload.
|
|
275 |
"/ ].
|
|
276 |
"/ cls fileOutIn:packageTargetDir
|
|
277 |
"/ ]
|
|
278 |
"/ ].
|
|
279 |
].
|
|
280 |
"/ generate header files...
|
|
281 |
(projectDefinitionClass allPreRequisites)
|
|
282 |
do:[:eachPackageToFileout |
|
|
283 |
|packageId packageDef packageModule packageDirectory packageTargetDir|
|
|
284 |
|
|
285 |
packageId := eachPackageToFileout asPackageId.
|
|
286 |
packageModule := packageId module.
|
|
287 |
packageDirectory := packageId directory.
|
|
288 |
packageTargetDir := (buildDirectory / packageModule / packageDirectory) recursiveMakeDirectory.
|
|
289 |
|
|
290 |
packageDef := packageId projectDefinitionClass.
|
|
291 |
(packageDef compiled_classNames_common ,
|
|
292 |
packageDef compiled_classNamesForPlatform) do:[:eachClassName |
|
|
293 |
|cls|
|
|
294 |
|
|
295 |
cls := Smalltalk classNamed:eachClassName.
|
|
296 |
self assert:cls isLoaded.
|
|
297 |
cls isLoaded ifTrue:[
|
|
298 |
self createHeaderFileFor:cls in:packageTargetDir
|
|
299 |
].
|
|
300 |
].
|
|
301 |
|
|
302 |
"/ (Smalltalk allClassesInPackage:eachPackageToFileout) do:[:cls |
|
|
303 |
"/ cls isPrivate ifFalse:[
|
|
304 |
"/ cls isLoaded ifTrue:[
|
|
305 |
"/ self createHeaderFileFor:cls in:packageTargetDir
|
|
306 |
"/ ]
|
|
307 |
"/ ]
|
|
308 |
"/ ].
|
2596
|
309 |
].
|
|
310 |
|
|
311 |
"/ "/ copy h-files preRequisite packages
|
|
312 |
"/ prerequisitePackages := projectDefinitionClass preRequisitesForBuilding.
|
|
313 |
"/ prerequisitePackages do:[:eachPackage |
|
|
314 |
"/ |relativeDir sourceDir|
|
|
315 |
"/
|
|
316 |
"/ relativeDir := eachPackage asPackageId pathRelativeToTopDirectory.
|
|
317 |
"/ sourceDir := Smalltalk packageDirectoryForPackageId:eachPackage.
|
|
318 |
"/ targetDir := buildDirectory construct:relativeDir.
|
|
319 |
"/ targetDir recursiveMakeDirectory.
|
|
320 |
"/ sourceDir directoryContentsAsFilenamesDo:[:eachSourceFilename |
|
|
321 |
"/ ((eachSourceFilename suffix asLowercase = 'h')
|
|
322 |
"/ or:[ eachSourceFilename suffix asLowercase = 'sth' ]) ifTrue:[
|
|
323 |
"/ eachSourceFilename copyTo:targetDir.
|
|
324 |
"/ ].
|
|
325 |
"/ ].
|
|
326 |
"/ ].
|
|
327 |
|
|
328 |
"/ stx_libbasic2 preRequisitesForBuilding#(#'stx:libbasic')
|
|
329 |
"/ "/ generate support files there
|
|
330 |
"/ targetDir := ((buildDirectory construct:module) construct:directory) recursiveMakeDirectory.
|
|
331 |
"/ #('bmake.bat' 'Make.spec' 'Make.proto' 'libInit.cc' 'abbrev.stc'
|
|
332 |
"/ 'bc.mak'
|
|
333 |
"/ ) do:[:f |
|
|
334 |
"/ |contents|
|
|
335 |
"/
|
|
336 |
"/ contents := projectDefinitionClass generateFile:f.
|
|
337 |
"/ (targetDir construct:f) contents:contents.
|
|
338 |
"/ ].
|
|
339 |
!
|
|
340 |
|
|
341 |
setupBuildDirectory
|
|
342 |
buildDirectory exists ifFalse:[
|
|
343 |
buildDirectory recursiveMakeDirectory.
|
|
344 |
].
|
|
345 |
(buildDirectory / 'stx') exists ifFalse:[
|
|
346 |
(buildDirectory / 'stx') makeDirectory.
|
|
347 |
].
|
|
348 |
|
|
349 |
self copyDirectoryForBuild:'include'.
|
|
350 |
self copyDirectoryForBuild:'rules'.
|
|
351 |
!
|
|
352 |
|
|
353 |
validateBuildDirectoryIsPresent
|
|
354 |
|
|
355 |
^ self.
|
|
356 |
|
|
357 |
"/ [
|
|
358 |
"/ |default directoryIsOKForMe stc |
|
|
359 |
"/
|
|
360 |
"/ default := (buildDirectory ?
|
|
361 |
"/ PreviousBuildDirectory)
|
|
362 |
"/ ifNil:[ UserPreferences current buildDirectory].
|
|
363 |
"/
|
|
364 |
"/ buildDirectory := Dialog requestDirectoryName:'Temporary Work-ROOT for build:'
|
|
365 |
"/ default:default.
|
|
366 |
"/
|
|
367 |
"/ buildDirectory isEmptyOrNil ifTrue:[^ self].
|
|
368 |
"/ buildDirectory := buildDirectory asFilename.
|
|
369 |
"/ directoryIsOKForMe := true.
|
|
370 |
"/
|
|
371 |
"/ buildDirectory exists ifFalse:[
|
|
372 |
"/ Dialog warn:(self classResources string:'Work directory %1 does not exist.' with:buildDirectory).
|
|
373 |
"/ directoryIsOKForMe := false.
|
|
374 |
"/ ] ifTrue:[
|
|
375 |
"/ (buildDirectory construct:'stx') exists ifFalse:[
|
|
376 |
"/ Dialog warn:(self classResources stringWithCRs:'Work directory must contain an stx subDirectory,\which contains (at least) the stc and include subdirectories.').
|
|
377 |
"/ directoryIsOKForMe := false.
|
|
378 |
"/ ] ifTrue:[
|
|
379 |
"/ stc := (OperatingSystem isMSDOSlike) ifTrue:['stc.exe'] ifFalse:['stc'].
|
|
380 |
"/ (((buildDirectory construct:'stx')construct:'stc')construct:stc) exists ifFalse:[
|
|
381 |
"/ Dialog warn:(self classResources stringWithCRs:'Work directory must contain an stc compiler in the stx/stc subDirectory.').
|
|
382 |
"/ directoryIsOKForMe := false.
|
|
383 |
"/ ].
|
|
384 |
"/ ((buildDirectory construct:'stx')construct:'include') exists ifFalse:[
|
|
385 |
"/ Dialog warn:(self classResources stringWithCRs:'Work directory must have had a make run before (for include files to exists).').
|
|
386 |
"/ directoryIsOKForMe := false.
|
|
387 |
"/ ].
|
|
388 |
"/ ]
|
|
389 |
"/ ].
|
|
390 |
"/ directoryIsOKForMe
|
|
391 |
"/ ] whileFalse
|
|
392 |
! !
|
|
393 |
|
|
394 |
!ProjectBuilder class methodsFor:'documentation'!
|
|
395 |
|
|
396 |
version_CVS
|
|
397 |
^ '$Header$'
|
|
398 |
! !
|