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