89
|
1 |
"
|
236
|
2 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
203
|
3 |
All Rights Reserved
|
89
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
1
|
12 |
|
236
|
13 |
'From Smalltalk/X, Version:2.10.4 on 5-feb-1995 at 11:58:37 pm'!
|
|
14 |
|
1
|
15 |
Object subclass:#Project
|
315
|
16 |
instanceVariableNames:'name changeSet views directoryName properties packageName'
|
|
17 |
classVariableNames:'CurrentProject SystemProject NextSequential'
|
203
|
18 |
poolDictionaries:''
|
|
19 |
category:'System-Support'
|
1
|
20 |
!
|
|
21 |
|
89
|
22 |
Project comment:'
|
|
23 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
203
|
24 |
All Rights Reserved
|
97
|
25 |
|
338
|
26 |
$Header: /cvs/stx/stx/libbasic/Project.st,v 1.19 1995-05-06 04:26:35 claus Exp $
|
89
|
27 |
'!
|
|
28 |
|
|
29 |
!Project class methodsFor:'documentation'!
|
|
30 |
|
|
31 |
copyright
|
|
32 |
"
|
|
33 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
203
|
34 |
All Rights Reserved
|
89
|
35 |
|
|
36 |
This software is furnished under a license and may be used
|
|
37 |
only in accordance with the terms of that license and with the
|
|
38 |
inclusion of the above copyright notice. This software may not
|
|
39 |
be provided or otherwise made available to, or used by, any
|
|
40 |
other person. No title to or ownership of the software is
|
|
41 |
hereby transferred.
|
|
42 |
"
|
|
43 |
!
|
|
44 |
|
|
45 |
version
|
|
46 |
"
|
338
|
47 |
$Header: /cvs/stx/stx/libbasic/Project.st,v 1.19 1995-05-06 04:26:35 claus Exp $
|
89
|
48 |
"
|
|
49 |
!
|
|
50 |
|
|
51 |
documentation
|
|
52 |
"
|
338
|
53 |
this class is still under construction (especially the build features are unfinished).
|
235
|
54 |
Currently, all it does is keep track of per-project views
|
|
55 |
(to hide or show them), define the directory when filing-out,
|
|
56 |
and define packageName for new classes and methods.
|
|
57 |
|
|
58 |
Future:
|
|
59 |
- keep track of per-project changes
|
|
60 |
- allow speficiation of the type of the project (application, library, etc)
|
|
61 |
- allow building of whatever the target (as defined by the type) is
|
|
62 |
(this will allow build of class libs and apps by clicking a button)
|
|
63 |
- allow removal of project specific classes, methods etc.
|
89
|
64 |
"
|
|
65 |
! !
|
|
66 |
|
236
|
67 |
!Project class methodsFor:'initialization'!
|
|
68 |
|
|
69 |
initialize
|
338
|
70 |
SystemProject isNil ifTrue:[
|
315
|
71 |
NextSequential := 1.
|
338
|
72 |
SystemProject := self new name:'default'.
|
|
73 |
SystemProject packageName:'private'.
|
236
|
74 |
"
|
|
75 |
the SystemProject does not keep a record if changes,
|
|
76 |
but instead depends on the changes file - recording anything there.
|
|
77 |
"
|
|
78 |
SystemProject changeSet:nil.
|
338
|
79 |
].
|
|
80 |
|
|
81 |
CurrentProject := SystemProject.
|
236
|
82 |
|
315
|
83 |
"
|
|
84 |
Project initialize
|
|
85 |
"
|
236
|
86 |
! !
|
|
87 |
|
|
88 |
!Project class methodsFor:'instance creation'!
|
|
89 |
|
|
90 |
new
|
|
91 |
^ self basicNew initialize
|
|
92 |
! !
|
|
93 |
|
1
|
94 |
!Project class methodsFor:'accessing'!
|
|
95 |
|
|
96 |
current
|
10
|
97 |
"return the currently active project"
|
|
98 |
|
1
|
99 |
^ CurrentProject
|
|
100 |
|
|
101 |
"Project current"
|
|
102 |
!
|
|
103 |
|
|
104 |
current:aProject
|
10
|
105 |
"set the currently active project"
|
|
106 |
|
315
|
107 |
CurrentProject := aProject.
|
|
108 |
self changed:#currentProject
|
334
|
109 |
!
|
|
110 |
|
336
|
111 |
defaultProject
|
|
112 |
"return the SystemDefault project"
|
|
113 |
|
|
114 |
^ SystemProject.
|
|
115 |
!
|
|
116 |
|
334
|
117 |
setDefaultProject
|
|
118 |
"set the currently active project to be the SystemDEfault project"
|
|
119 |
|
|
120 |
self current:SystemProject.
|
1
|
121 |
! !
|
|
122 |
|
149
|
123 |
!Project class methodsFor:'changes management'!
|
|
124 |
|
|
125 |
addMethodChange:aMethod in:aClass
|
|
126 |
"add a change for a method to the current project"
|
|
127 |
|
235
|
128 |
|p c|
|
149
|
129 |
|
|
130 |
p := CurrentProject.
|
|
131 |
(p notNil
|
235
|
132 |
and:[(c := p changeSet) notNil]) ifTrue:[
|
|
133 |
c addMethodChange:aMethod in:aClass
|
203
|
134 |
]
|
|
135 |
!
|
|
136 |
|
149
|
137 |
currentProjectDirectory
|
|
138 |
"return the name of the directory to use for fileOut.
|
235
|
139 |
The returned name already includes a file-separator at the end,
|
|
140 |
so the filename can be concatenated to it."
|
149
|
141 |
|
|
142 |
|p dirName|
|
|
143 |
|
|
144 |
p := CurrentProject.
|
|
145 |
p notNil ifTrue:[
|
203
|
146 |
dirName := p directory
|
149
|
147 |
] ifFalse:[
|
203
|
148 |
dirName := '.'
|
149
|
149 |
].
|
|
150 |
^ dirName , Filename separator asString
|
236
|
151 |
!
|
149
|
152 |
|
236
|
153 |
addMethodCategoryChange:aMethod category:newCategory in:aClass
|
|
154 |
|p c|
|
13
|
155 |
|
236
|
156 |
p := CurrentProject.
|
|
157 |
(p notNil
|
|
158 |
and:[(c := p changeSet) notNil]) ifTrue:[
|
|
159 |
c addMethodCategoryChange:aMethod category:newCategory in:aClass
|
|
160 |
]
|
13
|
161 |
! !
|
|
162 |
|
1
|
163 |
!Project methodsFor:'accessing'!
|
|
164 |
|
236
|
165 |
packageName
|
|
166 |
^ packageName
|
1
|
167 |
!
|
|
168 |
|
|
169 |
changeSet
|
|
170 |
^ changeSet
|
|
171 |
!
|
|
172 |
|
|
173 |
name
|
|
174 |
^ name
|
|
175 |
!
|
|
176 |
|
236
|
177 |
views
|
330
|
178 |
^ views asArray
|
235
|
179 |
!
|
|
180 |
|
|
181 |
classes
|
|
182 |
"return a collection of classes belonging to that project"
|
|
183 |
|
|
184 |
|classes|
|
|
185 |
|
315
|
186 |
properties notNil ifTrue:[classes := properties at:#classes ifAbsent:nil].
|
235
|
187 |
classes isNil ifTrue:[
|
|
188 |
classes := OrderedCollection new.
|
|
189 |
Smalltalk allClassesDo:[:aClass | aClass package = packageName ifTrue:[classes add:aClass]].
|
|
190 |
classes isEmpty ifTrue:[^ nil].
|
|
191 |
].
|
|
192 |
^ classes
|
|
193 |
|
73
|
194 |
!
|
|
195 |
|
236
|
196 |
name:aString
|
315
|
197 |
name := aString.
|
|
198 |
self == CurrentProject ifTrue:[
|
|
199 |
Project changed:#name
|
|
200 |
]
|
2
|
201 |
!
|
|
202 |
|
236
|
203 |
views:aSetOfViews
|
330
|
204 |
views := WeakIdentitySet withAll:aSetOfViews
|
73
|
205 |
!
|
|
206 |
|
236
|
207 |
changeSet:aChangeSet
|
|
208 |
changeSet := aChangeSet
|
73
|
209 |
!
|
|
210 |
|
236
|
211 |
packageName:aStringOrSymbol
|
315
|
212 |
packageName := aStringOrSymbol asSymbol.
|
|
213 |
self == CurrentProject ifTrue:[
|
|
214 |
Project changed:#package
|
|
215 |
]
|
|
216 |
!
|
|
217 |
|
|
218 |
directory
|
|
219 |
directoryName isNil ifTrue:[^ '.'].
|
|
220 |
^ directoryName
|
|
221 |
!
|
|
222 |
|
|
223 |
directory:aDirectoryName
|
|
224 |
directoryName := aDirectoryName.
|
|
225 |
self == CurrentProject ifTrue:[
|
|
226 |
Project changed:#directory
|
|
227 |
]
|
1
|
228 |
! !
|
|
229 |
|
10
|
230 |
!Project methodsFor:'views'!
|
|
231 |
|
|
232 |
addView:aView
|
235
|
233 |
views notNil ifTrue:[views add:aView]
|
10
|
234 |
!
|
|
235 |
|
|
236 |
removeView:aView
|
235
|
237 |
views notNil ifTrue:[views remove:aView ifAbsent:[]]
|
10
|
238 |
!
|
|
239 |
|
|
240 |
showViews
|
235
|
241 |
views notNil ifTrue:[
|
|
242 |
views do:[:aView |
|
|
243 |
aView notNil ifTrue:[aView rerealize]
|
203
|
244 |
]
|
10
|
245 |
].
|
|
246 |
!
|
|
247 |
|
|
248 |
hideViews
|
235
|
249 |
"hide all views of this project"
|
|
250 |
|
|
251 |
views notNil ifTrue:[
|
|
252 |
views do:[:aView |
|
|
253 |
aView notNil ifTrue:[aView unrealize]
|
203
|
254 |
]
|
10
|
255 |
].
|
338
|
256 |
!
|
|
257 |
|
|
258 |
destroyViews
|
|
259 |
"destroy all views of this project"
|
|
260 |
|
|
261 |
views notNil ifTrue:[
|
|
262 |
views do:[:aView |
|
|
263 |
aView notNil ifTrue:[aView destroy]
|
|
264 |
]
|
|
265 |
].
|
10
|
266 |
! !
|
|
267 |
|
236
|
268 |
!Project methodsFor:'initialization'!
|
|
269 |
|
|
270 |
initialize
|
338
|
271 |
|numString|
|
|
272 |
|
330
|
273 |
views := WeakIdentitySet new.
|
338
|
274 |
numString := NextSequential printString.
|
315
|
275 |
NextSequential := NextSequential + 1.
|
338
|
276 |
|
|
277 |
name := 'new Project-' , numString.
|
|
278 |
packageName := 'private-' , numString.
|
236
|
279 |
changeSet := ChangeSet new.
|
|
280 |
self directory:'.'
|
|
281 |
! !
|
|
282 |
|
|
283 |
!Project methodsFor:'properties'!
|
|
284 |
|
|
285 |
properties
|
|
286 |
^ properties
|
|
287 |
!
|
|
288 |
|
|
289 |
properties:p
|
|
290 |
properties := p
|
|
291 |
!
|
|
292 |
|
|
293 |
type
|
|
294 |
"return the type of project"
|
|
295 |
|
|
296 |
^ properties at:#type ifAbsent:[#application]
|
|
297 |
!
|
|
298 |
|
|
299 |
type:aSymbol
|
|
300 |
"set the projects type"
|
|
301 |
|
|
302 |
(#(application library smalltalk) includes:aSymbol) ifFalse:[
|
|
303 |
self warn:'invalid project type'.
|
|
304 |
^ self
|
|
305 |
].
|
|
306 |
properties at:#type put:aSymbol
|
|
307 |
! !
|
|
308 |
|
2
|
309 |
!Project methodsFor:'maintenance'!
|
|
310 |
|
13
|
311 |
buildProject
|
|
312 |
OperatingSystem executeCommand:('cd ' , self directory , ' ; make')
|
|
313 |
!
|
|
314 |
|
2
|
315 |
createProjectFiles
|
|
316 |
"actually, creates all files to do a make in the project directory"
|
|
317 |
|
13
|
318 |
|dirName|
|
|
319 |
|
|
320 |
dirName := properties at:#directoryName.
|
|
321 |
dirName asFilename exists ifFalse:[
|
203
|
322 |
(self confirm:'create new projectDirectory: ' , dirName) ifFalse:[^ self].
|
|
323 |
OperatingSystem recursiveCreateDirectory:dirName.
|
13
|
324 |
].
|
2
|
325 |
self createMakefile.
|
|
326 |
self createSourcefiles.
|
13
|
327 |
self createProtoMakefile.
|
2
|
328 |
!
|
|
329 |
|
|
330 |
createSourcefiles
|
235
|
331 |
"creates all Smalltalk-source files in the project directory"
|
2
|
332 |
|
236
|
333 |
|classes dir|
|
2
|
334 |
|
236
|
335 |
dir := FileDirectory directoryNamed:self directory.
|
|
336 |
Transcript showCr:'creating sources in ' , dir pathName , ' ...'; endEntry.
|
13
|
337 |
|
235
|
338 |
classes := self classes.
|
|
339 |
classes notNil ifTrue:[
|
315
|
340 |
classes do:[:aClass |
|
|
341 |
aClass isLoaded ifFalse:[
|
|
342 |
aClass autoload.
|
|
343 |
].
|
|
344 |
Transcript show:' ... '; showCr:aClass name; endEntry.
|
|
345 |
aClass fileOutIn:dir
|
|
346 |
]
|
2
|
347 |
].
|
|
348 |
!
|
|
349 |
|
|
350 |
createMakefile
|
|
351 |
"creates an initial makefile, which will recreate a correct
|
|
352 |
Makefile, then compile all"
|
|
353 |
|
|
354 |
|d f out in|
|
|
355 |
|
13
|
356 |
Transcript showCr:'creating Makefile'.
|
|
357 |
|
2
|
358 |
d := (properties at:#directoryName) asFilename.
|
|
359 |
f := d construct:'Makefile'.
|
13
|
360 |
f exists ifTrue:[
|
203
|
361 |
f renameTo:(d construct:'Makefile.bak')
|
13
|
362 |
].
|
2
|
363 |
out := f writeStream.
|
13
|
364 |
out isNil ifTrue:[
|
203
|
365 |
self warn:'cannot create Makefile'.
|
|
366 |
^ self
|
13
|
367 |
].
|
|
368 |
in := Smalltalk systemFileStreamFor:'rules/stdHeader'.
|
2
|
369 |
out nextPutAll:in contents asString.
|
|
370 |
in close.
|
13
|
371 |
out nextPutAll:'#TOP=/usr/local/lib/smalltalk'; cr.
|
|
372 |
out nextPutAll:'TOP=../..'; cr.
|
2
|
373 |
out nextPutAll:'target:'; cr.
|
|
374 |
out tab; nextPutAll:'touch Make.proto'; cr.
|
|
375 |
out tab; nextPutAll:'$(MAKE) Makefile'; cr.
|
|
376 |
out tab; nextPutAll:'make'; cr; cr.
|
|
377 |
|
13
|
378 |
in := Smalltalk systemFileStreamFor:'configurations/myConf'.
|
2
|
379 |
out nextPutAll:in contents asString.
|
|
380 |
in close.
|
13
|
381 |
in := Smalltalk systemFileStreamFor:'rules/stdRules'.
|
2
|
382 |
out nextPutAll:in contents asString.
|
|
383 |
in close.
|
|
384 |
out close
|
|
385 |
!
|
|
386 |
|
|
387 |
createProtoMakefile
|
|
388 |
"creates a Make.proto file"
|
|
389 |
|
13
|
390 |
|d f s type appName|
|
2
|
391 |
|
|
392 |
|
13
|
393 |
Transcript showCr:'creating Make.proto'.
|
|
394 |
|
2
|
395 |
d := (properties at:#directoryName) asFilename.
|
|
396 |
f := d construct:'Make.proto'.
|
|
397 |
f exists ifTrue:[
|
203
|
398 |
f renameTo:(d construct:'Make.proto.bak')
|
2
|
399 |
].
|
|
400 |
s := f writeStream.
|
13
|
401 |
s isNil ifTrue:[
|
203
|
402 |
self warn:'cannot create prototype Makefile'.
|
|
403 |
^ self
|
13
|
404 |
].
|
2
|
405 |
s nextPutAll:'#
|
235
|
406 |
# created by Smalltalks Project support
|
2
|
407 |
#
|
|
408 |
SHELL=/bin/sh
|
|
409 |
|
|
410 |
SUBDIRS=
|
13
|
411 |
#TOP=/usr/local/lib/smalltalk
|
|
412 |
TOP=../..
|
2
|
413 |
|
|
414 |
'.
|
|
415 |
|
|
416 |
type := properties at:#projectType ifAbsent:[#executable].
|
13
|
417 |
|
|
418 |
appName := properties at:#applicationName ifAbsent:['app'].
|
|
419 |
s nextPutAll:'LIBNAME=lib' , appName; cr.
|
2
|
420 |
|
|
421 |
type == #executable ifTrue:[
|
203
|
422 |
s nextPutAll:'PROGS = ' , appName; cr
|
2
|
423 |
].
|
13
|
424 |
s nextPutAll:'STARTUP_CLASS=' , (properties at:#startupClass ifAbsent:['Smalltalk']).
|
|
425 |
s cr.
|
|
426 |
s nextPutAll:'STARTUP_SELECTOR="' , (properties at:#startupSelector ifAbsent:['start']).
|
|
427 |
s nextPutAll:'"'; cr.
|
2
|
428 |
|
|
429 |
s nextPutAll:'OBJS='.
|
13
|
430 |
(properties at:#classes ifAbsent:[#()]) do:[:aClassName |
|
203
|
431 |
|abbrev|
|
2
|
432 |
|
203
|
433 |
s nextPutAll:' \'. s cr.
|
|
434 |
abbrev := Smalltalk fileNameForClass:aClassName.
|
|
435 |
s nextPutAll:' '; nextPutAll:abbrev; nextPutAll:'.o'.
|
2
|
436 |
].
|
|
437 |
s cr; cr.
|
|
438 |
|
|
439 |
|
|
440 |
type == #executable ifTrue:[
|
203
|
441 |
s nextPutAll:'all:: $(PROGS)'; cr.
|
2
|
442 |
|
203
|
443 |
s nextPutAll:appName.
|
|
444 |
s nextPutAll:':: main.o classList.o $(OBJS)'; cr.
|
|
445 |
s tab; nextPutAll:'$(LD) $(ST_LDFLAG) $(LDFLAGS) -o ';
|
|
446 |
nextPutAll:appName;
|
|
447 |
nextPutAll:' \'; cr.
|
|
448 |
s tab; tab; nextPutAll:'$(CRT0) main.$(O) classList.$(O) $(OBJS) $(EXTRA_OBJ) $(LIBOBJS) \'; cr.
|
|
449 |
s tab; tab; nextPutAll:'$(LIBRUNDIR)/hidata.o $(LIBRUN) \'; cr.
|
|
450 |
s tab; tab; nextPutAll:'$(MATHLIB) $(EXTRALIBS) -lXext $(SYSLIBS) $(OTHERLIBS) $(CRTN)'; cr.
|
2
|
451 |
].
|
|
452 |
|
|
453 |
s close
|
|
454 |
! !
|
|
455 |
|
|
456 |
!Project methodsFor:'specifications'!
|
|
457 |
|
|
458 |
readSpec
|
|
459 |
|s chunk fileName|
|
|
460 |
|
|
461 |
fileName := (properties at:#directoryName) asFilename construct:'.project'.
|
|
462 |
s := fileName readStream.
|
|
463 |
s isNil ifTrue:[^ self].
|
|
464 |
[s atEnd] whileFalse:[
|
203
|
465 |
chunk := s nextChunk.
|
|
466 |
Compiler evaluate:chunk receiver:properties notifying:nil
|
2
|
467 |
].
|
|
468 |
s close.
|
|
469 |
|
|
470 |
"(Project new directory:'../projects/Clock') readSpec"
|
|
471 |
!
|
|
472 |
|
|
473 |
saveSpec
|
|
474 |
|f d s|
|
|
475 |
|
|
476 |
d := (properties at:#directoryName) asFilename.
|
|
477 |
d exists ifFalse:[
|
203
|
478 |
self error:'directory does not exist'.
|
|
479 |
^ self
|
2
|
480 |
].
|
|
481 |
f := d construct:'.project'.
|
|
482 |
s := f writeStream.
|
|
483 |
s isNil ifTrue:[^ self].
|
|
484 |
properties associationsDo:[:aProp |
|
203
|
485 |
(aProp == #directoryName) ifFalse:[
|
|
486 |
s nextChunkPut:('self at:' , aProp key storeString,
|
|
487 |
' put:' , aProp value storeString).
|
|
488 |
s cr
|
|
489 |
]
|
2
|
490 |
].
|
|
491 |
s close
|
|
492 |
|
|
493 |
"((Project new directory:'../projects/Clock') readSpec
|
203
|
494 |
directory:'../projects/xxx') saveSpec"
|
2
|
495 |
! !
|
|
496 |
|
1
|
497 |
Project initialize!
|