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.
|
2599
|
84 |
self halt.
|
|
85 |
self copySTCDirectoryForBuild.
|
2596
|
86 |
self generateSourceFiles.
|
2599
|
87 |
self generateDLLsForLinkage.
|
2598
|
88 |
self halt.
|
2596
|
89 |
|
|
90 |
OperatingSystem
|
2599
|
91 |
executeCommand:(ParserFlags makeCommand,' exe')
|
2596
|
92 |
inputFrom:nil
|
|
93 |
outputTo:Transcript
|
|
94 |
errorTo:Transcript
|
2599
|
95 |
inDirectory:(buildDirectory / module / directory)
|
2596
|
96 |
onError:[:status| self error:'make failed'].
|
|
97 |
|
|
98 |
"Created: / 09-08-2006 / 18:37:19 / fm"
|
|
99 |
"Modified: / 09-08-2006 / 19:55:50 / fm"
|
|
100 |
"Modified: / 22-09-2006 / 17:37:11 / cg"
|
|
101 |
!
|
|
102 |
|
|
103 |
copyDirectory:relativepath
|
|
104 |
"/ need rules in stx
|
|
105 |
((Smalltalk projectDirectoryForPackage:'stx') asFilename construct:relativepath)
|
|
106 |
recursiveCopyTo:(buildDirectory construct:'stx').
|
|
107 |
!
|
|
108 |
|
|
109 |
copyDirectoryForBuild:subdir
|
2598
|
110 |
|targetDir targetFile|
|
2596
|
111 |
|
|
112 |
targetDir := buildDirectory / 'stx' / subdir.
|
|
113 |
targetDir exists ifFalse:[
|
|
114 |
targetDir makeDirectory.
|
2598
|
115 |
].
|
|
116 |
(mySTXTopDirectory / subdir) directoryContentsAsFilenamesDo:[:eachFile |
|
|
117 |
eachFile isDirectory ifFalse:[
|
|
118 |
targetFile := targetDir / eachFile baseName.
|
|
119 |
(targetFile exists not
|
|
120 |
or:[ targetFile modificationTime < eachFile modificationTime ]) ifTrue:[
|
|
121 |
self activityNotification:'copying ',eachFile pathName,'...'.
|
2596
|
122 |
eachFile copyTo:(targetDir construct:eachFile baseName)
|
|
123 |
]
|
|
124 |
].
|
|
125 |
].
|
2598
|
126 |
self activityNotification:nil
|
|
127 |
!
|
|
128 |
|
2599
|
129 |
copySTCDirectoryForBuild
|
|
130 |
|targetDir stc files|
|
|
131 |
|
|
132 |
targetDir := buildDirectory / 'stx' / 'stc'.
|
|
133 |
targetDir exists ifFalse:[ targetDir makeDirectory ].
|
|
134 |
|
|
135 |
stc := OperatingSystem isMSWINDOWSlike
|
|
136 |
ifTrue:[ 'stc.exe' ]
|
|
137 |
ifFalse:[ 'stc' ].
|
|
138 |
|
|
139 |
files := #( ) copyWith:stc.
|
|
140 |
|
|
141 |
files do:[:eachFile |
|
|
142 |
|sourceFile targetFile|
|
|
143 |
|
|
144 |
sourceFile := mySTXTopDirectory / 'stc' / eachFile.
|
|
145 |
targetFile := targetDir / eachFile.
|
|
146 |
(targetFile exists not
|
|
147 |
or:[ targetFile modificationTime < sourceFile modificationTime ]) ifTrue:[
|
|
148 |
self activityNotification:'copying ',sourceFile pathName,'...'.
|
|
149 |
sourceFile copyTo:targetFile
|
|
150 |
].
|
|
151 |
].
|
|
152 |
self activityNotification:nil
|
|
153 |
!
|
|
154 |
|
2598
|
155 |
createHeaderFileFor:aClass in:packageTargetDir
|
|
156 |
|instVarList classInstVarList classVarList bindings superclassFilename
|
|
157 |
template file newContents oldContents|
|
|
158 |
|
|
159 |
instVarList := StringCollection new.
|
|
160 |
aClass instVarNames do:[:v |
|
|
161 |
instVarList add:('OBJ %1;' bindWith:v)
|
|
162 |
].
|
|
163 |
classInstVarList := StringCollection new.
|
|
164 |
aClass class instVarNames do:[:v |
|
|
165 |
(v includes:$_) ifTrue:[self halt].
|
|
166 |
classInstVarList add:('OBJ %1;' bindWith:v)
|
|
167 |
].
|
|
168 |
classVarList := StringCollection new.
|
|
169 |
aClass classVarNames do:[:v |
|
|
170 |
classVarList add:('extern OBJ %1_%2;' bindWith:aClass name with:v)
|
|
171 |
].
|
|
172 |
|
|
173 |
bindings := Dictionary new.
|
|
174 |
bindings at:'ClassName' put:aClass name.
|
|
175 |
aClass superclass isNil ifTrue:[
|
|
176 |
bindings at:'SuperclassName' put:'-'.
|
|
177 |
bindings at:'SuperclassFileInclude' put:nil.
|
|
178 |
] ifFalse:[
|
|
179 |
bindings at:'SuperclassName' put:aClass superclass name.
|
|
180 |
bindings at:'SuperclassFileName' put:(superclassFilename := Smalltalk fileNameForClass:aClass superclass).
|
|
181 |
bindings at:'SuperclassFileInclude' put:('#include "%1.STH"' bindWith:superclassFilename).
|
|
182 |
].
|
|
183 |
bindings at:'InstVarList' put:instVarList asString.
|
|
184 |
bindings at:'ClassVarList' put:classVarList asString.
|
|
185 |
bindings at:'ClassInstVarList' put:classInstVarList asString.
|
|
186 |
|
|
187 |
template :=
|
|
188 |
'/* This file was generated by ProjectBuilder. */
|
|
189 |
/* !!!!!!!! Do not change by hand !!!!!!!! */
|
|
190 |
|
|
191 |
/* Class: %(ClassName) */
|
|
192 |
/* Superclass: %(SuperclassName) */
|
|
193 |
|
|
194 |
%(SuperclassFileInclude)
|
|
195 |
|
|
196 |
/* INDIRECTGLOBALS */
|
|
197 |
#ifdef _HEADER_INST_
|
|
198 |
%(InstVarList)
|
|
199 |
#endif /* _HEADER_INST_ */
|
|
200 |
|
|
201 |
#ifdef _HEADER_CLASS_
|
|
202 |
%(ClassVarList)
|
|
203 |
#endif /* _HEADER_CLASS_ */
|
|
204 |
|
|
205 |
#ifdef _HEADER_CLASSINST_
|
|
206 |
%(ClassInstVarList)
|
|
207 |
#endif /* _HEADER_CLASSINST_ */
|
|
208 |
'.
|
|
209 |
newContents := template bindWithArguments:bindings.
|
|
210 |
file := packageTargetDir asFilename / ((Smalltalk fileNameForClass:aClass),'.STH').
|
|
211 |
(file exists not
|
|
212 |
or:[ (oldContents := file contents) ~= newContents ]) ifTrue:[
|
|
213 |
file contents: newContents.
|
|
214 |
].
|
2596
|
215 |
!
|
|
216 |
|
2599
|
217 |
generateDLLsForLinkage
|
|
218 |
|targetBuildDir|
|
|
219 |
|
|
220 |
targetBuildDir := buildDirectory / package module / package directory.
|
|
221 |
|
|
222 |
"/ generate header files...
|
|
223 |
(projectDefinitionClass allPreRequisites)
|
|
224 |
do:[:eachPackageToFileout |
|
|
225 |
|packageId packageDef packageModule packageDirectory packageTargetDir
|
|
226 |
dllSource dllSourceDir libraryName dllRelativePath|
|
|
227 |
|
|
228 |
packageId := eachPackageToFileout asPackageId.
|
|
229 |
packageModule := packageId module.
|
|
230 |
packageDirectory := packageId directory.
|
|
231 |
packageTargetDir := (buildDirectory / packageModule / packageDirectory) recursiveMakeDirectory.
|
|
232 |
|
|
233 |
packageDef := packageId projectDefinitionClass.
|
|
234 |
libraryName := packageDef libraryName.
|
|
235 |
|
|
236 |
"/ mhmh - take them from my tree or from the projects/smalltalk execution directory ??
|
|
237 |
dllSourceDir := myTopDirectory / packageModule / packageDirectory.
|
|
238 |
OperatingSystem isMSWINDOWSlike ifTrue:[
|
|
239 |
"/ dllRelativePath := 'objvc','/',(libraryName,'.dll').
|
|
240 |
"/ (dllSourceDir / dllRelativePath) exists
|
|
241 |
false ifFalse:[
|
|
242 |
dllRelativePath := 'objbc','/',(libraryName,'.dll').
|
|
243 |
]
|
|
244 |
] ifFalse:[
|
|
245 |
dllRelativePath := libraryName,'.so'.
|
|
246 |
].
|
|
247 |
((dllSourceDir / dllRelativePath) exists
|
|
248 |
and:[ (dllSourceDir / dllRelativePath) fileSize = (packageTargetDir / dllRelativePath) fileSize
|
|
249 |
and:[ (dllSourceDir / dllRelativePath) modificationTime < (packageTargetDir / dllRelativePath) modificationTime
|
|
250 |
"/ and:[ (dllSourceDir / dllRelativePath) sameContentsAs:(packageTargetDir / dllRelativePath) ]
|
|
251 |
]]) ifFalse:[
|
|
252 |
(packageTargetDir / dllRelativePath) directory recursiveMakeDirectory.
|
|
253 |
(dllSourceDir / dllRelativePath) copyTo:(packageTargetDir / dllRelativePath).
|
|
254 |
]
|
|
255 |
].
|
|
256 |
!
|
|
257 |
|
2596
|
258 |
generateSourceFiles
|
|
259 |
sourceCodeManager notNil ifTrue:[
|
|
260 |
"/ check out / generate files there
|
|
261 |
self generateSourceFilesByCheckingOutUsing:sourceCodeManager
|
|
262 |
] ifFalse:[
|
|
263 |
"/ local build
|
|
264 |
"/ fileout the project
|
|
265 |
self generateSourceFilesByFilingOut
|
|
266 |
]
|
|
267 |
!
|
|
268 |
|
|
269 |
generateSourceFilesByCheckingOutUsing:aSourceCodeManager
|
|
270 |
"/ will no longer be needed/supported
|
|
271 |
|
|
272 |
|repository stxRepository module directory|
|
|
273 |
|
|
274 |
self halt.
|
|
275 |
"/ check out / generate files there
|
|
276 |
repository := (aSourceCodeManager repositoryNameForModule:module) ifNil:[aSourceCodeManager repositoryName].
|
|
277 |
stxRepository := aSourceCodeManager repositoryName.
|
|
278 |
|
|
279 |
(buildDirectory construct:'stx') exists ifFalse:[
|
|
280 |
(module ~= 'stx') ifTrue:[
|
|
281 |
OperatingSystem
|
|
282 |
executeCommand:('cvs -d ',stxRepository,' co stx')
|
|
283 |
inputFrom:nil
|
|
284 |
outputTo:Transcript
|
|
285 |
errorTo:Transcript
|
|
286 |
inDirectory:buildDirectory
|
|
287 |
onError:[:status| self error:'cvs update stx failed'].
|
|
288 |
].
|
|
289 |
].
|
|
290 |
|
|
291 |
((buildDirectory construct:module) construct:'CVS') exists ifFalse:[
|
|
292 |
OperatingSystem
|
|
293 |
executeCommand:('cvs -d ',repository,' co -l ',directory)
|
|
294 |
inputFrom:nil
|
|
295 |
outputTo:Transcript
|
|
296 |
errorTo:Transcript
|
|
297 |
inDirectory:buildDirectory
|
|
298 |
onError:[:status| self error:'cvs update failed'].
|
|
299 |
].
|
|
300 |
OperatingSystem
|
|
301 |
executeCommand:'cvs upd -d'
|
|
302 |
inputFrom:nil
|
|
303 |
outputTo:Transcript
|
|
304 |
errorTo:Transcript
|
|
305 |
inDirectory:(buildDirectory construct:module)
|
|
306 |
onError:[:status| self error:'cvs update failed'].
|
|
307 |
self halt.
|
|
308 |
!
|
|
309 |
|
|
310 |
generateSourceFilesByFilingOut
|
|
311 |
"/ local build
|
|
312 |
"/ fileout the project
|
|
313 |
|
|
314 |
(package module ~= 'stx') ifTrue:[
|
|
315 |
(buildDirectory / package module) makeDirectory.
|
|
316 |
].
|
|
317 |
|
2599
|
318 |
"/ file out the package(s) which are to be built
|
2598
|
319 |
((Array with:package))
|
2596
|
320 |
do:[:eachPackageToFileout |
|
2598
|
321 |
|packageId packageModule packageDirectory packageTargetDir packageDef|
|
2596
|
322 |
|
2598
|
323 |
packageId := eachPackageToFileout asPackageId.
|
|
324 |
packageModule := packageId module.
|
|
325 |
packageDirectory := packageId directory.
|
2596
|
326 |
packageTargetDir := (buildDirectory / packageModule / packageDirectory) recursiveMakeDirectory.
|
|
327 |
|
2598
|
328 |
packageDef := packageId projectDefinitionClass.
|
|
329 |
(packageDef compiled_classNames_common ,
|
|
330 |
packageDef compiled_classNamesForPlatform) do:[:eachClassName |
|
|
331 |
|cls|
|
|
332 |
|
|
333 |
cls := Smalltalk classNamed:eachClassName.
|
|
334 |
self assert:cls isLoaded.
|
|
335 |
cls fileOutIn:packageTargetDir
|
2596
|
336 |
].
|
2598
|
337 |
|
|
338 |
"/ (Smalltalk allClassesInPackage:eachPackageToFileout) do:[:cls |
|
|
339 |
"/ cls isPrivate ifFalse:[
|
|
340 |
"/ cls isLoaded ifFalse:[
|
|
341 |
"/ self halt.
|
|
342 |
"/ cls autoload.
|
|
343 |
"/ ].
|
|
344 |
"/ cls fileOutIn:packageTargetDir
|
|
345 |
"/ ]
|
|
346 |
"/ ].
|
2599
|
347 |
|
|
348 |
projectDefinitionClass forEachFileNameAndGeneratedContentsDo:[:fileName :fileContents |
|
|
349 |
((packageTargetDir / fileName) exists
|
|
350 |
and:[ (packageTargetDir / fileName) contents = fileContents ]) ifFalse:[
|
|
351 |
(packageTargetDir / fileName) contents:fileContents.
|
|
352 |
].
|
|
353 |
].
|
|
354 |
self halt.
|
2598
|
355 |
].
|
2599
|
356 |
|
|
357 |
"/ generate header files in prerequisite packages...
|
2598
|
358 |
(projectDefinitionClass allPreRequisites)
|
|
359 |
do:[:eachPackageToFileout |
|
|
360 |
|packageId packageDef packageModule packageDirectory packageTargetDir|
|
|
361 |
|
|
362 |
packageId := eachPackageToFileout asPackageId.
|
|
363 |
packageModule := packageId module.
|
|
364 |
packageDirectory := packageId directory.
|
|
365 |
packageTargetDir := (buildDirectory / packageModule / packageDirectory) recursiveMakeDirectory.
|
|
366 |
|
|
367 |
packageDef := packageId projectDefinitionClass.
|
|
368 |
(packageDef compiled_classNames_common ,
|
|
369 |
packageDef compiled_classNamesForPlatform) do:[:eachClassName |
|
|
370 |
|cls|
|
|
371 |
|
|
372 |
cls := Smalltalk classNamed:eachClassName.
|
|
373 |
self assert:cls isLoaded.
|
|
374 |
cls isLoaded ifTrue:[
|
|
375 |
self createHeaderFileFor:cls in:packageTargetDir
|
|
376 |
].
|
|
377 |
].
|
2596
|
378 |
].
|
|
379 |
|
|
380 |
"/ stx_libbasic2 preRequisitesForBuilding#(#'stx:libbasic')
|
|
381 |
!
|
|
382 |
|
|
383 |
setupBuildDirectory
|
|
384 |
buildDirectory exists ifFalse:[
|
|
385 |
buildDirectory recursiveMakeDirectory.
|
|
386 |
].
|
|
387 |
(buildDirectory / 'stx') exists ifFalse:[
|
|
388 |
(buildDirectory / 'stx') makeDirectory.
|
|
389 |
].
|
|
390 |
|
|
391 |
self copyDirectoryForBuild:'include'.
|
|
392 |
self copyDirectoryForBuild:'rules'.
|
|
393 |
!
|
|
394 |
|
|
395 |
validateBuildDirectoryIsPresent
|
|
396 |
|
|
397 |
^ self.
|
|
398 |
|
|
399 |
"/ [
|
|
400 |
"/ |default directoryIsOKForMe stc |
|
|
401 |
"/
|
|
402 |
"/ default := (buildDirectory ?
|
|
403 |
"/ PreviousBuildDirectory)
|
|
404 |
"/ ifNil:[ UserPreferences current buildDirectory].
|
|
405 |
"/
|
|
406 |
"/ buildDirectory := Dialog requestDirectoryName:'Temporary Work-ROOT for build:'
|
|
407 |
"/ default:default.
|
|
408 |
"/
|
|
409 |
"/ buildDirectory isEmptyOrNil ifTrue:[^ self].
|
|
410 |
"/ buildDirectory := buildDirectory asFilename.
|
|
411 |
"/ directoryIsOKForMe := true.
|
|
412 |
"/
|
|
413 |
"/ buildDirectory exists ifFalse:[
|
|
414 |
"/ Dialog warn:(self classResources string:'Work directory %1 does not exist.' with:buildDirectory).
|
|
415 |
"/ directoryIsOKForMe := false.
|
|
416 |
"/ ] ifTrue:[
|
|
417 |
"/ (buildDirectory construct:'stx') exists ifFalse:[
|
|
418 |
"/ Dialog warn:(self classResources stringWithCRs:'Work directory must contain an stx subDirectory,\which contains (at least) the stc and include subdirectories.').
|
|
419 |
"/ directoryIsOKForMe := false.
|
|
420 |
"/ ] ifTrue:[
|
|
421 |
"/ stc := (OperatingSystem isMSDOSlike) ifTrue:['stc.exe'] ifFalse:['stc'].
|
|
422 |
"/ (((buildDirectory construct:'stx')construct:'stc')construct:stc) exists ifFalse:[
|
|
423 |
"/ Dialog warn:(self classResources stringWithCRs:'Work directory must contain an stc compiler in the stx/stc subDirectory.').
|
|
424 |
"/ directoryIsOKForMe := false.
|
|
425 |
"/ ].
|
|
426 |
"/ ((buildDirectory construct:'stx')construct:'include') exists ifFalse:[
|
|
427 |
"/ Dialog warn:(self classResources stringWithCRs:'Work directory must have had a make run before (for include files to exists).').
|
|
428 |
"/ directoryIsOKForMe := false.
|
|
429 |
"/ ].
|
|
430 |
"/ ]
|
|
431 |
"/ ].
|
|
432 |
"/ directoryIsOKForMe
|
|
433 |
"/ ] whileFalse
|
|
434 |
! !
|
|
435 |
|
|
436 |
!ProjectBuilder class methodsFor:'documentation'!
|
|
437 |
|
|
438 |
version_CVS
|
|
439 |
^ '$Header$'
|
|
440 |
! !
|