Fix SConstruct to use for build commands. (Terrel Shumway)
[scons.git] / SConstruct
1 #
2 # SConstruct file to build scons packages during development.
3 #
4 # See the README file for an overview of how SCons is built and tested.
5 #
6
7 #
8 # Copyright (c) 2001, 2002 Steven Knight
9 #
10 # Permission is hereby granted, free of charge, to any person obtaining
11 # a copy of this software and associated documentation files (the
12 # "Software"), to deal in the Software without restriction, including
13 # without limitation the rights to use, copy, modify, merge, publish,
14 # distribute, sublicense, and/or sell copies of the Software, and to
15 # permit persons to whom the Software is furnished to do so, subject to
16 # the following conditions:
17 #
18 # The above copyright notice and this permission notice shall be included
19 # in all copies or substantial portions of the Software.
20 #
21 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
22 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
23 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 #
29
30 import distutils.util
31 import os
32 import os.path
33 import socket
34 import stat
35 import string
36 import sys
37 import time
38
39 project = 'scons'
40 default_version = '0.08'
41
42 Default('.')
43
44 #
45 # An internal "whereis" routine to figure out if a given program
46 # is available on this system.
47 #
48 def whereis(file):
49     for dir in string.split(os.environ['PATH'], os.pathsep):
50         f = os.path.join(dir, file)
51         if os.path.isfile(f):
52             try:
53                 st = os.stat(f)
54             except:
55                 continue
56             if stat.S_IMODE(st[stat.ST_MODE]) & 0111:
57                 return f
58     return None
59
60 #
61 # We let the presence or absence of various utilities determine
62 # whether or not we bother to build certain pieces of things.
63 # This should allow people to still do SCons work even if they
64 # don't have Aegis or RPM installed, for example.
65 #
66 aegis = whereis('aegis')
67 aesub = whereis('aesub')
68 dh_builddeb = whereis('dh_builddeb')
69 fakeroot = whereis('fakeroot')
70 gzip = whereis('gzip')
71 rpm = whereis('rpm')
72 unzip = whereis('unzip')
73 zip = whereis('zip')
74
75 #
76 # Now grab the information that we "build" into the files.
77 #
78 try:
79     date = ARGUMENTS['date']
80 except:
81     date = time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(time.time()))
82     
83 if ARGUMENTS.has_key('developer'):
84     developer = ARGUMENTS['developer']
85 elif os.environ.has_key('USERNAME'):
86     developer = os.environ['USERNAME']
87 elif os.environ.has_key('LOGNAME'):
88     developer = os.environ['LOGNAME']
89 elif os.environ.has_key('USER'):
90     developer = os.environ['USER']
91
92 if ARGUMENTS.has_key('build_system'):
93     build_system = ARGUMENTS['build_system']
94 else:
95     build_system = string.split(socket.gethostname(), '.')[0]
96
97 if ARGUMENTS.has_key('version'):
98     revision = ARGUMENTS['version']
99 elif aesub:
100     revision = os.popen(aesub + " \\$version", "r").read()[:-1]
101 else:
102     revision = default_version
103
104 a = string.split(revision, '.')
105 arr = [a[0]]
106 for s in a[1:]:
107     if len(s) == 1:
108         s = '0' + s
109     arr.append(s)
110 revision = string.join(arr, '.')
111
112 # Here's how we'd turn the calculated $revision into our package $version.
113 # This makes it difficult to coordinate with other files (debian/changelog
114 # and rpm/scons.spec) that hard-code the version number, so just go with
115 # the flow for now and hard code it here, too.
116 #if len(arr) >= 2:
117 #    arr = arr[:-1]
118 #def xxx(str):
119 #    if str[0] == 'C' or str[0] == 'D':
120 #        str = str[1:]
121 #    while len(str) > 2 and str[0] == '0':
122 #        str = str[1:]
123 #    return str
124 #arr = map(lambda x, xxx=xxx: xxx(x), arr)
125 #version = string.join(arr, '.')
126 version = default_version
127
128 build_id = string.replace(revision, version + '.', '')
129
130 if ARGUMENTS.has_key('change'):
131     change = ARGUMENTS['change']
132 elif aesub:
133     change = os.popen(aesub + " \\$change", "r").read()[:-1]
134 else:
135     change = default_version
136
137 python_ver = sys.version[0:3]
138
139 platform = distutils.util.get_platform()
140
141 ENV = { 'PATH' : os.environ['PATH'] }
142 for key in ['AEGIS_PROJECT', 'PYTHONPATH']:
143     if os.environ.has_key(key):
144         ENV[key] = os.environ[key]
145
146 lib_project = os.path.join("lib", project)
147
148 cwd_build = os.path.join(os.getcwd(), "build")
149
150 test_deb_dir        = os.path.join(cwd_build, "test-deb")
151 test_rpm_dir        = os.path.join(cwd_build, "test-rpm")
152 test_tar_gz_dir     = os.path.join(cwd_build, "test-tar-gz")
153 test_src_tar_gz_dir = os.path.join(cwd_build, "test-src-tar-gz")
154 test_zip_dir        = os.path.join(cwd_build, "test-zip")
155 test_src_zip_dir    = os.path.join(cwd_build, "test-src-zip")
156
157 unpack_tar_gz_dir   = os.path.join(cwd_build, "unpack-tar-gz")
158 unpack_zip_dir      = os.path.join(cwd_build, "unpack-zip")
159
160 if platform == "win32":
161     tar_hflag = ''
162     python_project_subinst_dir = None
163     project_script_subinst_dir = 'Scripts'
164 else:
165     tar_hflag = 'h'
166     python_project_subinst_dir = lib_project
167     project_script_subinst_dir = 'bin'
168
169
170 zcat = 'gzip -d -c'
171     
172 #
173 # Figure out if we can handle .zip files.
174 #
175 try:
176     import zipfile
177
178     def zipit(env, target, source):
179         print "Zipping %s:" % str(target[0])
180         def visit(arg, dirname, names):
181             for name in names:
182                 path = os.path.join(dirname, name)
183                 if os.path.isfile(path):
184                     arg.write(path)
185         zf = zipfile.ZipFile(str(target[0]), 'w')
186         os.chdir('build')
187         os.path.walk(env['PSV'], visit, zf)
188         os.chdir('..')
189         zf.close()
190
191     def unzipit(env, target, source):
192         print "Unzipping %s:" % str(source[0])
193         zf = zipfile.ZipFile(str(source[0]), 'r')
194         for name in zf.namelist():
195             dest = os.path.join(env['UNPACK_ZIP_DIR'], name)
196             dir = os.path.dirname(dest)
197             try:
198                 os.makedirs(dir)
199             except:
200                 pass
201             print dest,name
202             # if the file exists, then delete it before writing
203             # to it so that we don't end up trying to write to a symlink:
204             if os.path.isfile(dest) or os.path.islink(dest):
205                 os.unlink(dest)
206             if not os.path.isdir(dest):
207                 open(dest, 'w').write(zf.read(name))
208
209 except:
210     if unzip and zip:
211         zipit = "cd build && $ZIP $ZIPFLAGS dist/${TARGET.file} $PSV"
212         unzipit = "$UNZIP $UNZIPFLAGS $SOURCES"
213
214 def SCons_revision(target, source, env):
215     """Interpolate specific values from the environment into a file.
216     
217     This is used to copy files into a tree that gets packaged up
218     into the source file package.
219     """
220     t = str(target[0])
221     s = str(source[0])
222     # Note:  We don't use $VERSION from the environment so that
223     # this routine will change when the version number changes
224     # and things will get rebuilt properly.
225     global version
226     print "SCons_revision() < %s > %s" % (s, t)
227     inf = open(s, 'rb')
228     outf = open(t, 'wb')
229     for line in inf.readlines():
230         # Note:  We construct the __*__ substitution strings here
231         # so that they don't get replaced when this file gets
232         # copied into the tree for packaging.
233         line = string.replace(line, '__BUILD'     + '__', env['BUILD'])
234         line = string.replace(line, '__BUILDSYS'  + '__', env['BUILDSYS'])
235         line = string.replace(line, '__DATE'      + '__', env['DATE'])
236         line = string.replace(line, '__DEVELOPER' + '__', env['DEVELOPER'])
237         line = string.replace(line, '__FILE'      + '__', s)
238         line = string.replace(line, '__REVISION'  + '__', env['REVISION'])
239         line = string.replace(line, '__VERSION'   + '__',  version)
240         outf.write(line)
241     inf.close()
242     outf.close()
243     os.chmod(t, os.stat(s)[0])
244
245 revbuilder = Builder(action = SCons_revision)
246
247 env = Environment(
248                    ENV                 = ENV,
249  
250                    BUILD               = build_id,
251                    BUILDSYS            = build_system,
252                    DATE                = date,
253                    DEVELOPER           = developer,
254                    REVISION            = revision,
255                    VERSION             = version,
256                    DH_COMPAT           = 2,
257
258                    TAR_HFLAG           = tar_hflag,
259
260                    ZIP                 = zip,
261                    ZIPFLAGS            = '-r',
262                    UNZIP               = unzip,
263                    UNZIPFLAGS          = '-o -d $UNPACK_ZIP_DIR',
264
265                    ZCAT                = zcat,
266
267                    TEST_DEB_DIR        = test_deb_dir,
268                    TEST_RPM_DIR        = test_rpm_dir,
269                    TEST_SRC_TAR_GZ_DIR = test_src_tar_gz_dir,
270                    TEST_SRC_ZIP_DIR    = test_src_zip_dir,
271                    TEST_TAR_GZ_DIR     = test_tar_gz_dir,
272                    TEST_ZIP_DIR        = test_zip_dir,
273
274                    UNPACK_TAR_GZ_DIR   = unpack_tar_gz_dir,
275                    UNPACK_ZIP_DIR      = unpack_zip_dir,
276
277                    BUILDERS            = { 'SCons_revision' : revbuilder },
278
279                    PYTHON              = sys.executable
280                  )
281
282 #
283 # Define SCons packages.
284 #
285 # In the original, more complicated packaging scheme, we were going
286 # to have separate packages for:
287 #
288 #       python-scons    only the build engine
289 #       scons-script    only the script
290 #       scons           the script plus the build engine
291 #
292 # We're now only delivering a single "scons" package, but this is still
293 # "built" as two sub-packages (the build engine and the script), so
294 # the definitions remain here, even though we're not using them for
295 # separate packages.
296 #
297
298 python_scons = {
299         'pkg'           : 'python-' + project,
300         'src_subdir'    : 'engine',
301         'inst_subdir'   : os.path.join('lib', 'python1.5', 'site-packages'),
302
303         'debian_deps'   : [
304                             'debian/changelog',
305                             'debian/control',
306                             'debian/copyright',
307                             'debian/dirs',
308                             'debian/docs',
309                             'debian/postinst',
310                             'debian/prerm',
311                             'debian/rules',
312                           ],
313
314         'files'         : [ 'LICENSE.txt',
315                             'README.txt',
316                             'setup.cfg',
317                             'setup.py',
318                           ],
319
320         'filemap'       : {
321                             'LICENSE.txt' : '../LICENSE.txt'
322                           },
323 }
324
325 #
326 # The original packaging scheme would have have required us to push
327 # the Python version number into the package name (python1.5-scons,
328 # python2.0-scons, etc.), which would have required a definition
329 # like the following.  Leave this here in case we ever decide to do
330 # this in the future, but note that this would require some modification
331 # to src/engine/setup.py before it would really work.
332 #
333 #python2_scons = {
334 #        'pkg'          : 'python2-' + project,
335 #        'src_subdir'   : 'engine',
336 #        'inst_subdir'  : os.path.join('lib', 'python2.1', 'site-packages'),
337 #
338 #        'debian_deps'  : [
339 #                            'debian/changelog',
340 #                            'debian/control',
341 #                            'debian/copyright',
342 #                            'debian/dirs',
343 #                            'debian/docs',
344 #                            'debian/postinst',
345 #                            'debian/prerm',
346 #                            'debian/rules',
347 #                          ],
348 #
349 #        'files'        : [
350 #                            'LICENSE.txt',
351 #                            'README.txt',
352 #                            'setup.cfg',
353 #                            'setup.py',
354 #                          ],
355 #        'filemap'      : {
356 #                            'LICENSE.txt' : '../LICENSE.txt',
357 #                          },
358 #}
359 #
360
361 scons_script = {
362         'pkg'           : project + '-script',
363         'src_subdir'    : 'script',
364         'inst_subdir'   : 'bin',
365
366         'debian_deps'   : [
367                             'debian/changelog',
368                             'debian/control',
369                             'debian/copyright',
370                             'debian/dirs',
371                             'debian/docs',
372                             'debian/postinst',
373                             'debian/prerm',
374                             'debian/rules',
375                           ],
376
377         'files'         : [
378                             'LICENSE.txt',
379                             'README.txt',
380                             'setup.cfg',
381                             'setup.py',
382                           ],
383
384         'filemap'       : {
385                             'LICENSE.txt' : '../LICENSE.txt',
386                             'scons'       : 'scons.py',
387                            }
388 }
389
390 scons = {
391         'pkg'           : project,
392
393         'debian_deps'   : [ 
394                             'debian/changelog',
395                             'debian/control',
396                             'debian/copyright',
397                             'debian/dirs',
398                             'debian/docs',
399                             'debian/postinst',
400                             'debian/prerm',
401                             'debian/rules',
402                           ],
403
404         'files'         : [ 
405                             'CHANGES.txt',
406                             'LICENSE.txt',
407                             'README.txt',
408                             'RELEASE.txt',
409                             'os_spawnv_fix.diff',
410                             'scons.1',
411                             'script/scons.bat',
412                             'setup.cfg',
413                             'setup.py',
414                           ],
415
416         'filemap'       : {
417                             'scons.1' : '../doc/man/scons.1',
418                           },
419
420         'subpkgs'       : [ python_scons, scons_script ],
421
422         'subinst_dirs'  : {
423                              'python-' + project : python_project_subinst_dir,
424                              project + '-script' : project_script_subinst_dir,
425                            },
426 }
427
428 src_deps = []
429 src_files = []
430
431 for p in [ scons ]:
432     #
433     # Initialize variables with the right directories for this package.
434     #
435     pkg = p['pkg']
436     pkg_version = "%s-%s" % (pkg, version)
437
438     src = 'src'
439     if p.has_key('src_subdir'):
440         src = os.path.join(src, p['src_subdir'])
441
442     build = os.path.join('build', pkg)
443
444     tar_gz = os.path.join(build, 'dist', "%s.tar.gz" % pkg_version)
445     platform_tar_gz = os.path.join(build,
446                                    'dist',
447                                    "%s.%s.tar.gz" % (pkg_version, platform))
448     zip = os.path.join(build, 'dist', "%s.zip" % pkg_version)
449     platform_zip = os.path.join(build,
450                                 'dist',
451                                 "%s.%s.zip" % (pkg_version, platform))
452     win32_exe = os.path.join(build, 'dist', "%s.win32.exe" % pkg_version)
453
454     #
455     # Update the environment with the relevant information
456     # for this package.
457     #
458     # We can get away with calling setup.py using a directory path
459     # like this because we put a preamble in it that will chdir()
460     # to the directory in which setup.py exists.
461     #
462     env.Update(PKG = pkg,
463                PKG_VERSION = pkg_version,
464                SETUP_PY = os.path.join(build, 'setup.py'))
465
466     #
467     # Read up the list of source files from our MANIFEST.in.
468     # This list should *not* include LICENSE.txt, MANIFEST,
469     # README.txt, or setup.py.  Make a copy of the list for the
470     # destination files.
471     #
472     src_files = map(lambda x: x[:-1],
473                     open(os.path.join(src, 'MANIFEST.in')).readlines())
474     dst_files = src_files[:]
475
476     MANIFEST_in_list = []
477
478     if p.has_key('subpkgs'):
479         #
480         # This package includes some sub-packages.  Read up their
481         # MANIFEST.in files, and add them to our source and destination
482         # file lists, modifying them as appropriate to add the
483         # specified subdirs.
484         #
485         for sp in p['subpkgs']:
486             ssubdir = sp['src_subdir']
487             isubdir = p['subinst_dirs'][sp['pkg']]
488             MANIFEST_in = os.path.join(src, ssubdir, 'MANIFEST.in')
489             MANIFEST_in_list.append(MANIFEST_in)
490             f = map(lambda x: x[:-1], open(MANIFEST_in).readlines())
491             src_files.extend(map(lambda x, s=ssubdir: os.path.join(s, x), f))
492             if isubdir:
493                 f = map(lambda x, i=isubdir: os.path.join(i, x), f)
494             dst_files.extend(f)
495             for k in sp['filemap'].keys():
496                 f = sp['filemap'][k]
497                 if f:
498                     k = os.path.join(sp['src_subdir'], k)
499                     p['filemap'][k] = os.path.join(sp['src_subdir'], f)
500
501     #
502     # Now that we have the "normal" source files, add those files
503     # that are standard for each distribution.  Note that we don't
504     # add these to dst_files, because they don't get installed.
505     # And we still have the MANIFEST to add.
506     #
507     src_files.extend(p['files'])
508
509     #
510     # Now run everything in src_file through the sed command we
511     # concocted to expand __FILE__, __VERSION__, etc.
512     #
513     for b in src_files:
514         s = p['filemap'].get(b, b)
515         env.SCons_revision(os.path.join(build, b), os.path.join(src, s))
516
517     #
518     # NOW, finally, we can create the MANIFEST, which we do
519     # by having Python spit out the contents of the src_files
520     # array we've carefully created.  After we've added
521     # MANIFEST itself to the array, of course.
522     #
523     src_files.append("MANIFEST")
524     MANIFEST_in_list.append(os.path.join(src, 'MANIFEST.in'))
525
526     def copy(target, source, **kw):
527         global src_files
528         src_files.sort()
529         f = open(str(target[0]), 'wb')
530         for file in src_files:
531             f.write(file + "\n")
532         f.close()
533         return 0
534     env.Command(os.path.join(build, 'MANIFEST'), MANIFEST_in_list, copy)
535
536     #
537     # Now go through and arrange to create whatever packages we can.
538     #
539     build_src_files = map(lambda x, b=build: os.path.join(b, x), src_files)
540
541     distutils_formats = []
542
543     distutils_targets = [ win32_exe ]
544
545     install_targets = distutils_targets[:]
546
547     if gzip:
548
549         distutils_formats.append('gztar')
550
551         src_deps.append(tar_gz)
552
553         distutils_targets.extend([ tar_gz, platform_tar_gz ])
554         install_targets.extend([ tar_gz, platform_tar_gz ])
555
556         #
557         # Unpack the tar.gz archive created by the distutils into
558         # build/unpack-tar-gz/scons-{version}.
559         #
560         # We'd like to replace the last three lines with the following:
561         #
562         #       tar zxf $SOURCES -C $UNPACK_TAR_GZ_DIR
563         #
564         # but that gives heartburn to Cygwin's tar, so work around it
565         # with separate zcat-tar-rm commands.
566         #
567         unpack_tar_gz_files = map(lambda x, u=unpack_tar_gz_dir, pv=pkg_version:
568                                          os.path.join(u, pv, x),
569                                   src_files)
570         env.Command(unpack_tar_gz_files, tar_gz, [
571                     "rm -rf %s" % os.path.join(unpack_tar_gz_dir, pkg_version),
572                     "$ZCAT $SOURCES > .temp",
573                     "tar xf .temp -C $UNPACK_TAR_GZ_DIR",
574                     "rm -f .temp",
575         ])
576     
577         #
578         # Run setup.py in the unpacked subdirectory to "install" everything
579         # into our build/test subdirectory.  The runtest.py script will set
580         # PYTHONPATH so that the tests only look under build/test-{package},
581         # and under etc (for the testing modules TestCmd.py, TestSCons.py,
582         # and unittest.py).  This makes sure that our tests pass with what
583         # we really packaged, not because of something hanging around in
584         # the development directory.
585         #
586         # We can get away with calling setup.py using a directory path
587         # like this because we put a preamble in it that will chdir()
588         # to the directory in which setup.py exists.
589         #
590         dfiles = map(lambda x, d=test_tar_gz_dir: os.path.join(d, x), dst_files)
591         env.Command(dfiles, unpack_tar_gz_files, [
592             "rm -rf %s" % os.path.join(unpack_tar_gz_dir, pkg_version, 'build'),
593             "rm -rf $TEST_TAR_GZ_DIR",
594             "$PYTHON %s install --prefix=$TEST_TAR_GZ_DIR" % \
595                 os.path.join(unpack_tar_gz_dir, pkg_version, 'setup.py'),
596         ])
597
598     if zipit:
599
600         distutils_formats.append('zip')
601
602         src_deps.append(zip)
603
604         distutils_targets.extend([ zip, platform_zip ])
605         install_targets.extend([ zip, platform_zip ])
606
607         #
608         # Unpack the zip archive created by the distutils into
609         # build/unpack-zip/scons-{version}.
610         #
611         unpack_zip_files = map(lambda x, u=unpack_zip_dir, pv=pkg_version:
612                                       os.path.join(u, pv, x),
613                                src_files)
614
615         env.Command(unpack_zip_files, zip, unzipit)
616
617         #
618         # Run setup.py in the unpacked subdirectory to "install" everything
619         # into our build/test subdirectory.  The runtest.py script will set
620         # PYTHONPATH so that the tests only look under build/test-{package},
621         # and under etc (for the testing modules TestCmd.py, TestSCons.py,
622         # and unittest.py).  This makes sure that our tests pass with what
623         # we really packaged, not because of something hanging around in
624         # the development directory.
625         #
626         # We can get away with calling setup.py using a directory path
627         # like this because we put a preamble in it that will chdir()
628         # to the directory in which setup.py exists.
629         #
630         dfiles = map(lambda x, d=test_zip_dir: os.path.join(d, x), dst_files)
631         env.Command(dfiles, unpack_zip_files, [
632             "rm -rf %s" % os.path.join(unpack_zip_dir, pkg_version, 'build'),
633             "rm -rf $TEST_ZIP_DIR",
634             "$PYTHON %s install --prefix=$TEST_ZIP_DIR" % \
635                 os.path.join(unpack_zip_dir, pkg_version, 'setup.py'),
636         ])
637
638     if rpm:
639         topdir = os.path.join(os.getcwd(), build, 'build',
640                               'bdist.' + platform, 'rpm')
641
642         BUILDdir = os.path.join(topdir, 'BUILD', pkg + '-' + version)
643         RPMSdir = os.path.join(topdir, 'RPMS', 'noarch')
644         SOURCESdir = os.path.join(topdir, 'SOURCES')
645         SPECSdir = os.path.join(topdir, 'SPECS')
646         SRPMSdir = os.path.join(topdir, 'SRPMS')
647
648         specfile = os.path.join(SPECSdir, "%s-1.spec" % pkg_version)
649         sourcefile = os.path.join(SOURCESdir, "%s.tar.gz" % pkg_version);
650         rpm = os.path.join(RPMSdir, "%s-1.noarch.rpm" % pkg_version)
651         src_rpm = os.path.join(SRPMSdir, "%s-1.src.rpm" % pkg_version)
652
653         env.InstallAs(specfile, os.path.join('rpm', "%s.spec" % pkg))
654         env.InstallAs(sourcefile, tar_gz)
655
656         targets = [ rpm, src_rpm ]
657         cmd = "rpm --define '_topdir $(%s$)' -ba $SOURCES" % topdir
658         if not os.path.isdir(BUILDdir):
659             cmd = ("$( mkdir -p %s; $)" % BUILDdir) + cmd
660         env.Command(targets, specfile, cmd)
661         env.Depends(targets, sourcefile)
662
663         install_targets.extend(targets)
664
665         dfiles = map(lambda x, d=test_rpm_dir: os.path.join(d, 'usr', x),
666                      dst_files)
667         env.Command(dfiles,
668                     rpm,
669                     "rpm2cpio $SOURCES | (cd $TEST_RPM_DIR && cpio -id)")
670
671     if dh_builddeb and fakeroot:
672         # Our Debian packaging builds directly into build/dist,
673         # so we don't need to add the .debs to install_targets.
674         deb = os.path.join('build', 'dist', "%s_%s-1_all.deb" % (pkg, version))
675         for d in p['debian_deps']:
676             b = env.SCons_revision(os.path.join(build, d), d)
677             env.Depends(deb, b)
678         env.Command(deb, build_src_files, [
679             "cd %s && fakeroot make -f debian/rules PYTHON=$PYTHON BUILDDEB_OPTIONS=--destdir=../../build/dist binary" % build,
680                     ])
681
682         old = os.path.join('lib', 'scons', '')
683         new = os.path.join('lib', 'python2.1', 'site-packages', '')
684         def xxx(s, old=old, new=new):
685             if s[:len(old)] == old:
686                 s = new + s[len(old):]
687             return os.path.join('usr', s)
688         dfiles = map(lambda x, t=test_deb_dir: os.path.join(t, x),
689                      map(xxx, dst_files))
690         env.Command(dfiles,
691                     deb,
692                     "dpkg --fsys-tarfile $SOURCES | (cd $TEST_DEB_DIR && tar -xf -)")
693
694     #
695     # Use the Python distutils to generate the appropriate packages.
696     #
697     commands = [
698         "rm -rf %s" % os.path.join(build, 'build', 'lib'),
699         "rm -rf %s" % os.path.join(build, 'build', 'scripts'),
700     ]
701
702     if distutils_formats:
703         commands.append("rm -rf %s" % os.path.join(build,
704                                                    'build',
705                                                    'bdist.' + platform,
706                                                    'dumb'))
707         for format in distutils_formats:
708             commands.append("$PYTHON $SETUP_PY bdist_dumb -f %s" % format)
709
710         commands.append("$PYTHON $SETUP_PY sdist --formats=%s" %  \
711                             string.join(distutils_formats, ','))
712
713     commands.append("$PYTHON $SETUP_PY bdist_wininst")
714
715     env.Command(distutils_targets, build_src_files, commands)
716
717     #
718     # And, lastly, install the appropriate packages in the
719     # appropriate subdirectory.
720     #
721     env.Install(os.path.join('build', 'dist'), install_targets)
722
723 #
724 #
725 #
726 Export('env')
727
728 SConscript('etc/SConscript')
729
730 #
731 # Documentation.
732 #
733 BuildDir('build/doc', 'doc')
734
735 Export('env', 'whereis')
736
737 SConscript('build/doc/SConscript')
738
739 #
740 # If we're running in the actual Aegis project, pack up a complete
741 # source archive from the project files and files in the change,
742 # so we can share it with helpful developers who don't use Aegis.
743 #
744
745 if change:
746     df = []
747     cmd = "aegis -list -unf -c %s cf 2>/dev/null" % change
748     for line in map(lambda x: x[:-1], os.popen(cmd, "r").readlines()):
749         a = string.split(line)
750         if a[1] == "remove":
751             df.append(a[-1])
752
753     cmd = "aegis -list -terse pf 2>/dev/null"
754     pf = map(lambda x: x[:-1], os.popen(cmd, "r").readlines())
755     cmd = "aegis -list -terse cf 2>/dev/null"
756     cf = map(lambda x: x[:-1], os.popen(cmd, "r").readlines())
757     u = {}
758     for f in pf + cf:
759         u[f] = 1
760     for f in df:
761         del u[f]
762     sfiles = filter(lambda x: x[-9:] != '.aeignore' and x[-9:] != '.sconsign',
763                     u.keys())
764
765     if sfiles:
766         ps = "%s-src" % project
767         psv = "%s-%s" % (ps, version)
768         b_ps = os.path.join('build', ps)
769         b_psv = os.path.join('build', psv)
770         b_psv_stamp = b_psv + '-stamp'
771
772         src_tar_gz = os.path.join('build', 'dist', '%s.tar.gz' % psv)
773         src_zip = os.path.join('build', 'dist', '%s.zip' % psv)
774
775         for file in sfiles:
776             env.SCons_revision(os.path.join(b_ps, file), file)
777
778         b_ps_files = map(lambda x, d=b_ps: os.path.join(d, x), sfiles)
779         cmds = [
780             "rm -rf %s" % b_psv,
781             "cp -rp %s %s" % (b_ps, b_psv),
782             "find %s -name .sconsign -exec rm {} \\;" % b_psv,
783             "touch $TARGET",
784         ]
785
786         env.Command(b_psv_stamp, src_deps + b_ps_files, cmds)
787
788         if gzip:
789
790             env.Command(src_tar_gz, b_psv_stamp,
791                         "tar cz${TAR_HFLAG} -f $TARGET -C build %s" % psv)
792     
793             #
794             # Unpack the archive into build/unpack/scons-{version}.
795             #
796             unpack_tar_gz_files = map(lambda x, u=unpack_tar_gz_dir, psv=psv:
797                                              os.path.join(u, psv, x),
798                                       sfiles)
799     
800             #
801             # We'd like to replace the last three lines with the following:
802             #
803             #   tar zxf $SOURCES -C $UNPACK_TAR_GZ_DIR
804             #
805             # but that gives heartburn to Cygwin's tar, so work around it
806             # with separate zcat-tar-rm commands.
807             env.Command(unpack_tar_gz_files, src_tar_gz, [
808                 "rm -rf %s" % os.path.join(unpack_tar_gz_dir, psv),
809                 "$ZCAT $SOURCES > .temp",
810                 "tar xf .temp -C $UNPACK_TAR_GZ_DIR",
811                 "rm -f .temp",
812             ])
813     
814             #
815             # Run setup.py in the unpacked subdirectory to "install" everything
816             # into our build/test subdirectory.  The runtest.py script will set
817             # PYTHONPATH so that the tests only look under build/test-{package},
818             # and under etc (for the testing modules TestCmd.py, TestSCons.py,
819             # and unittest.py).  This makes sure that our tests pass with what
820             # we really packaged, not because of something hanging around in
821             # the development directory.
822             #
823             # We can get away with calling setup.py using a directory path
824             # like this because we put a preamble in it that will chdir()
825             # to the directory in which setup.py exists.
826             #
827             dfiles = map(lambda x, d=test_src_tar_gz_dir: os.path.join(d, x),
828                             dst_files)
829             ENV = env.Dictionary('ENV')
830             ENV['SCONS_LIB_DIR'] = os.path.join(unpack_tar_gz_dir, psv, 'src', 'engine')
831             ENV['USERNAME'] = developer
832             env.Copy(ENV = ENV).Command(dfiles, unpack_tar_gz_files, [
833                 "rm -rf %s" % os.path.join(unpack_tar_gz_dir,
834                                            psv,
835                                            'build',
836                                            'scons',
837                                            'build'),
838                 "rm -rf $TEST_SRC_TAR_GZ_DIR",
839                 "cd %s && $PYTHON %s %s" % \
840                     (os.path.join(unpack_tar_gz_dir, psv),
841                      os.path.join('src', 'script', 'scons.py'),
842                      os.path.join('build', 'scons')),
843                 "$PYTHON %s install --prefix=$TEST_SRC_TAR_GZ_DIR" % \
844                     os.path.join(unpack_tar_gz_dir,
845                                  psv,
846                                  'build',
847                                  'scons',
848                                  'setup.py'),
849             ])
850
851         if zipit:
852
853             env.Copy(PSV = psv).Command(src_zip, b_psv_stamp, zipit)
854     
855             #
856             # Unpack the archive into build/unpack/scons-{version}.
857             #
858             unpack_zip_files = map(lambda x, u=unpack_zip_dir, psv=psv:
859                                              os.path.join(u, psv, x),
860                                       sfiles)
861     
862             env.Command(unpack_zip_files, src_zip, unzipit)
863     
864             #
865             # Run setup.py in the unpacked subdirectory to "install" everything
866             # into our build/test subdirectory.  The runtest.py script will set
867             # PYTHONPATH so that the tests only look under build/test-{package},
868             # and under etc (for the testing modules TestCmd.py, TestSCons.py,
869             # and unittest.py).  This makes sure that our tests pass with what
870             # we really packaged, not because of something hanging around in
871             # the development directory.
872             #
873             # We can get away with calling setup.py using a directory path
874             # like this because we put a preamble in it that will chdir()
875             # to the directory in which setup.py exists.
876             #
877             dfiles = map(lambda x, d=test_src_zip_dir: os.path.join(d, x),
878                             dst_files)
879             ENV = env.Dictionary('ENV')
880             ENV['SCONS_LIB_DIR'] = os.path.join(unpack_zip_dir, psv, 'src', 'engine')
881             ENV['USERNAME'] = developer
882             env.Copy(ENV = ENV).Command(dfiles, unpack_zip_files, [
883                 "rm -rf %s" % os.path.join(unpack_zip_dir,
884                                            psv,
885                                            'build',
886                                            'scons',
887                                            'build'),
888                 "rm -rf $TEST_SRC_ZIP_DIR",
889                 "cd %s && $PYTHON %s %s" % \
890                     (os.path.join(unpack_zip_dir, psv),
891                      os.path.join('src', 'script', 'scons.py'),
892                      os.path.join('build', 'scons')),
893                 "$PYTHON %s install --prefix=$TEST_SRC_ZIP_DIR" % \
894                     os.path.join(unpack_zip_dir,
895                                  psv,
896                                  'build',
897                                  'scons',
898                                  'setup.py'),
899             ])