ProjectBuilder.st
changeset 2596 876679f78999
child 2598 2bb47a698d59
equal deleted inserted replaced
2595:e1eeda9d1639 2596:876679f78999
       
     1 "{ Package: 'stx:libtool2' }"
       
     2 
       
     3 Object subclass:#ProjectBuilder
       
     4 	instanceVariableNames:'package projectDefinitionClass sourceCodeManager buildDirectory
       
     5 		myWorkingDirectory mySTXTopDirectory'
       
     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 self halt.
       
    51     module := package module.
       
    52     directory := package directory.
       
    53 
       
    54     buildDirectory := PreviousBuildDirectory ifNil:[ UserPreferences current buildDirectory ].
       
    55     buildDirectory isNil ifTrue:[
       
    56         buildDirectory := Filename tempDirectory construct:'stx_build'.
       
    57     ].
       
    58     buildDirectory := buildDirectory asFilename.
       
    59 
       
    60     "/ self validateBuildDirectoryIsPresent.
       
    61 
       
    62     PreviousBuildDirectory := buildDirectory.
       
    63 
       
    64     "/ UserPreferences current localBuild:true
       
    65     UserPreferences current localBuild ifFalse:[
       
    66         SourceCodeManager notNil ifTrue:[
       
    67             sourceCodeManager := SourceCodeManagerUtilities sourceCodeManagerFor:projectDefinitionClass.
       
    68         ]
       
    69     ].
       
    70     sourceCodeManager := nil.
       
    71 
       
    72     mySTXTopDirectory := 
       
    73         Smalltalk packagePath 
       
    74             detect:[:aPath |
       
    75                 (aPath asFilename / 'stx' / 'include') exists
       
    76                 and: [ (aPath asFilename / 'stx' / 'rules') exists ]]
       
    77             ifNone:nil.       
       
    78     mySTXTopDirectory isNil ifTrue:[
       
    79         self error:('Cannot figure out my top directory (where include and rules are)')
       
    80     ].
       
    81 
       
    82     self setupBuildDirectory.
       
    83     self generateSourceFiles.
       
    84 
       
    85     OperatingSystem
       
    86         executeCommand:(ParserFlags makeCommand)
       
    87         inputFrom:nil
       
    88         outputTo:Transcript
       
    89         errorTo:Transcript
       
    90         inDirectory:((buildDirectory construct:module) construct:directory)
       
    91         onError:[:status| self error:'make failed'].
       
    92 
       
    93     "Created: / 09-08-2006 / 18:37:19 / fm"
       
    94     "Modified: / 09-08-2006 / 19:55:50 / fm"
       
    95     "Modified: / 22-09-2006 / 17:37:11 / cg"
       
    96 !
       
    97 
       
    98 copyDirectory:relativepath
       
    99     "/ need rules in stx
       
   100     ((Smalltalk projectDirectoryForPackage:'stx') asFilename construct:relativepath)
       
   101         recursiveCopyTo:(buildDirectory construct:'stx').
       
   102 !
       
   103 
       
   104 copyDirectoryForBuild:subdir
       
   105     |targetDir|
       
   106 
       
   107     targetDir := buildDirectory / 'stx' / subdir.
       
   108     targetDir exists ifFalse:[
       
   109         targetDir makeDirectory.
       
   110         (mySTXTopDirectory / subdir) directoryContentsAsFilenamesDo:[:eachFile |
       
   111             eachFile isDirectory ifFalse:[
       
   112                 eachFile copyTo:(targetDir construct:eachFile baseName)
       
   113             ]
       
   114         ].
       
   115     ].
       
   116 !
       
   117 
       
   118 generateSourceFiles
       
   119     sourceCodeManager notNil ifTrue:[
       
   120         "/ check out / generate files there
       
   121         self generateSourceFilesByCheckingOutUsing:sourceCodeManager
       
   122     ] ifFalse:[
       
   123         "/ local build
       
   124         "/ fileout the project
       
   125         self generateSourceFilesByFilingOut
       
   126     ]
       
   127 !
       
   128 
       
   129 generateSourceFilesByCheckingOutUsing:aSourceCodeManager
       
   130     "/ will no longer be needed/supported
       
   131 
       
   132     |repository stxRepository module directory|
       
   133 
       
   134 self halt.
       
   135     "/ check out / generate files there
       
   136     repository := (aSourceCodeManager repositoryNameForModule:module) ifNil:[aSourceCodeManager repositoryName].
       
   137     stxRepository := aSourceCodeManager repositoryName.
       
   138 
       
   139     (buildDirectory construct:'stx') exists ifFalse:[
       
   140         (module ~= 'stx') ifTrue:[
       
   141             OperatingSystem
       
   142                 executeCommand:('cvs -d ',stxRepository,' co stx')
       
   143                 inputFrom:nil
       
   144                 outputTo:Transcript
       
   145                 errorTo:Transcript
       
   146                 inDirectory:buildDirectory
       
   147                 onError:[:status| self error:'cvs update stx failed'].
       
   148         ].
       
   149     ].
       
   150 
       
   151     ((buildDirectory construct:module) construct:'CVS') exists ifFalse:[
       
   152         OperatingSystem
       
   153             executeCommand:('cvs -d ',repository,' co -l ',directory)
       
   154             inputFrom:nil
       
   155             outputTo:Transcript
       
   156             errorTo:Transcript
       
   157             inDirectory:buildDirectory
       
   158             onError:[:status| self error:'cvs update failed'].
       
   159     ].
       
   160     OperatingSystem
       
   161         executeCommand:'cvs upd -d'
       
   162         inputFrom:nil
       
   163         outputTo:Transcript
       
   164         errorTo:Transcript
       
   165         inDirectory:(buildDirectory construct:module)
       
   166         onError:[:status| self error:'cvs update failed'].
       
   167 self halt.
       
   168 !
       
   169 
       
   170 generateSourceFilesByFilingOut
       
   171     |targetDir prerequisitePackages|
       
   172 
       
   173     "/ local build
       
   174     "/ fileout the project
       
   175 
       
   176     (package module ~= 'stx') ifTrue:[
       
   177         (buildDirectory / package module) makeDirectory.
       
   178     ].
       
   179 
       
   180     "/ file out the package(s)
       
   181 
       
   182     ((Array with:package) , (projectDefinitionClass allPreRequisites))
       
   183     do:[:eachPackageToFileout |
       
   184         |packageModule packageDirectory packageTargetDir|
       
   185 
       
   186         packageModule := eachPackageToFileout asPackageId module.
       
   187         packageDirectory := eachPackageToFileout asPackageId directory.
       
   188         packageTargetDir := (buildDirectory / packageModule / packageDirectory) recursiveMakeDirectory.
       
   189 
       
   190         (Smalltalk allClassesInPackage:eachPackageToFileout) do:[:cls |
       
   191             cls isPrivate ifFalse:[
       
   192                 cls isLoaded ifFalse:[
       
   193                     self halt.
       
   194                     cls autoload.
       
   195                 ].
       
   196                 cls fileOutIn:packageTargetDir
       
   197             ]
       
   198         ].
       
   199     ].
       
   200 
       
   201 "/    "/ copy h-files preRequisite packages
       
   202 "/    prerequisitePackages := projectDefinitionClass preRequisitesForBuilding.
       
   203 "/    prerequisitePackages do:[:eachPackage |
       
   204 "/        |relativeDir sourceDir|
       
   205 "/
       
   206 "/        relativeDir := eachPackage asPackageId pathRelativeToTopDirectory.
       
   207 "/        sourceDir := Smalltalk packageDirectoryForPackageId:eachPackage.
       
   208 "/        targetDir := buildDirectory construct:relativeDir.
       
   209 "/        targetDir recursiveMakeDirectory.
       
   210 "/        sourceDir directoryContentsAsFilenamesDo:[:eachSourceFilename |
       
   211 "/            ((eachSourceFilename suffix asLowercase = 'h')
       
   212 "/            or:[ eachSourceFilename suffix asLowercase = 'sth' ]) ifTrue:[
       
   213 "/                eachSourceFilename copyTo:targetDir.    
       
   214 "/            ].
       
   215 "/        ].
       
   216 "/    ].
       
   217 
       
   218 "/    stx_libbasic2 preRequisitesForBuilding#(#'stx:libbasic')
       
   219 "/    "/ generate support files there
       
   220 "/    targetDir := ((buildDirectory construct:module) construct:directory) recursiveMakeDirectory.
       
   221 "/    #('bmake.bat' 'Make.spec' 'Make.proto' 'libInit.cc' 'abbrev.stc'
       
   222 "/      'bc.mak'
       
   223 "/    ) do:[:f |
       
   224 "/        |contents|                          
       
   225 "/
       
   226 "/        contents := projectDefinitionClass generateFile:f.
       
   227 "/        (targetDir construct:f) contents:contents.
       
   228 "/    ].    
       
   229 !
       
   230 
       
   231 setupBuildDirectory
       
   232     buildDirectory exists ifFalse:[
       
   233         buildDirectory recursiveMakeDirectory.
       
   234     ].
       
   235     (buildDirectory / 'stx') exists ifFalse:[
       
   236         (buildDirectory / 'stx') makeDirectory.
       
   237     ].
       
   238 
       
   239     self copyDirectoryForBuild:'include'.
       
   240     self copyDirectoryForBuild:'rules'.
       
   241 !
       
   242 
       
   243 validateBuildDirectoryIsPresent
       
   244 
       
   245     ^ self.
       
   246 
       
   247 "/    [
       
   248 "/        |default directoryIsOKForMe stc |
       
   249 "/
       
   250 "/        default := (buildDirectory ?
       
   251 "/                          PreviousBuildDirectory)
       
   252 "/                          ifNil:[ UserPreferences current buildDirectory].
       
   253 "/
       
   254 "/        buildDirectory := Dialog requestDirectoryName:'Temporary Work-ROOT for build:'
       
   255 "/                                 default:default.
       
   256 "/
       
   257 "/        buildDirectory isEmptyOrNil ifTrue:[^ self].
       
   258 "/        buildDirectory := buildDirectory asFilename.
       
   259 "/        directoryIsOKForMe := true.
       
   260 "/
       
   261 "/        buildDirectory exists ifFalse:[
       
   262 "/            Dialog warn:(self classResources string:'Work directory %1 does not exist.' with:buildDirectory).
       
   263 "/            directoryIsOKForMe := false.
       
   264 "/        ] ifTrue:[
       
   265 "/            (buildDirectory construct:'stx') exists ifFalse:[
       
   266 "/                Dialog warn:(self classResources stringWithCRs:'Work directory must contain an stx subDirectory,\which contains (at least) the stc and include subdirectories.').
       
   267 "/                directoryIsOKForMe := false.
       
   268 "/            ] ifTrue:[
       
   269 "/                stc := (OperatingSystem isMSDOSlike) ifTrue:['stc.exe'] ifFalse:['stc'].
       
   270 "/                (((buildDirectory construct:'stx')construct:'stc')construct:stc) exists ifFalse:[
       
   271 "/                    Dialog warn:(self classResources stringWithCRs:'Work directory must contain an stc compiler in the stx/stc subDirectory.').
       
   272 "/                    directoryIsOKForMe := false.
       
   273 "/                ].
       
   274 "/                ((buildDirectory construct:'stx')construct:'include') exists ifFalse:[
       
   275 "/                    Dialog warn:(self classResources stringWithCRs:'Work directory must have had a make run before (for include files to exists).').
       
   276 "/                    directoryIsOKForMe := false.
       
   277 "/                ].
       
   278 "/            ]
       
   279 "/        ].
       
   280 "/        directoryIsOKForMe
       
   281 "/    ] whileFalse
       
   282 ! !
       
   283 
       
   284 !ProjectBuilder class methodsFor:'documentation'!
       
   285 
       
   286 version_CVS
       
   287     ^ '$Header$'
       
   288 ! !