+ #
+ # Run setup.py in the unpacked subdirectory to "install" everything
+ # into our build/test subdirectory. The runtest.py script will set
+ # PYTHONPATH so that the tests only look under build/test-{package},
+ # and under etc (for the testing modules TestCmd.py, TestSCons.py,
+ # and unittest.py). This makes sure that our tests pass with what
+ # we really packaged, not because of something hanging around in
+ # the development directory.
+ #
+ # We can get away with calling setup.py using a directory path
+ # like this because we put a preamble in it that will chdir()
+ # to the directory in which setup.py exists.
+ #
+ dfiles = map(lambda x, d=test_tar_gz_dir: os.path.join(d, x), dst_files)
+ env.Command(dfiles, unpack_tar_gz_files, [
+ Delete(os.path.join(unpack_tar_gz_dir, pkg_version, 'build')),
+ Delete("$TEST_TAR_GZ_DIR"),
+ '$PYTHON $PYTHONFLAGS "%s" install "--prefix=$TEST_TAR_GZ_DIR" --standalone-lib' % \
+ os.path.join(unpack_tar_gz_dir, pkg_version, 'setup.py'),
+ ])
+
+ #
+ # Generate portage files for submission to Gentoo Linux.
+ #
+ gentoo = os.path.join(build, 'gentoo')
+ ebuild = os.path.join(gentoo, 'scons-%s.ebuild' % version)
+ digest = os.path.join(gentoo, 'files', 'digest-scons-%s' % version)
+ env.Command(ebuild, os.path.join('gentoo', 'scons.ebuild.in'), SCons_revision)
+ def Digestify(target, source, env):
+ import md5
+ def hexdigest(s):
+ """Return a signature as a string of hex characters.
+ """
+ # NOTE: This routine is a method in the Python 2.0 interface
+ # of the native md5 module, but we want SCons to operate all
+ # the way back to at least Python 1.5.2, which doesn't have it.
+ h = string.hexdigits
+ r = ''
+ for c in s:
+ i = ord(c)
+ r = r + h[(i >> 4) & 0xF] + h[i & 0xF]
+ return r
+ src = source[0].rfile()
+ contents = open(str(src)).read()
+ sig = hexdigest(md5.new(contents).digest())
+ bytes = os.stat(str(src))[6]
+ open(str(target[0]), 'w').write("MD5 %s %s %d\n" % (sig,
+ src.name,
+ bytes))
+ env.Command(digest, tar_gz, Digestify)
+
+ if not zipit:
+ print "zip not found; skipping .zip package for %s." % pkg
+ else:
+
+ distutils_formats.append('zip')
+
+ src_deps.append(zip)
+
+ distutils_targets.extend([ zip, platform_zip ])
+
+ dist_zip = env.Install('$DISTDIR', zip)
+ dist_platform_zip = env.Install('$DISTDIR', platform_zip)
+ Local(dist_zip, dist_platform_zip)
+ AddPostAction(dist_zip, Chmod(dist_zip, 0644))
+ AddPostAction(dist_platform_zip, Chmod(dist_platform_zip, 0644))
+
+ #
+ # Unpack the zip archive created by the distutils into
+ # build/unpack-zip/scons-{version}.
+ #
+ unpack_zip_files = map(lambda x, u=unpack_zip_dir, pv=pkg_version:
+ os.path.join(u, pv, x),
+ src_files)
+
+ env.Command(unpack_zip_files, dist_zip, [
+ Delete(os.path.join(unpack_zip_dir, pkg_version)),
+ unzipit,
+ ])
+
+ #
+ # Run setup.py in the unpacked subdirectory to "install" everything
+ # into our build/test subdirectory. The runtest.py script will set
+ # PYTHONPATH so that the tests only look under build/test-{package},
+ # and under etc (for the testing modules TestCmd.py, TestSCons.py,
+ # and unittest.py). This makes sure that our tests pass with what
+ # we really packaged, not because of something hanging around in
+ # the development directory.
+ #
+ # We can get away with calling setup.py using a directory path
+ # like this because we put a preamble in it that will chdir()
+ # to the directory in which setup.py exists.
+ #
+ dfiles = map(lambda x, d=test_zip_dir: os.path.join(d, x), dst_files)
+ env.Command(dfiles, unpack_zip_files, [
+ Delete(os.path.join(unpack_zip_dir, pkg_version, 'build')),
+ Delete("$TEST_ZIP_DIR"),
+ '$PYTHON $PYTHONFLAGS "%s" install "--prefix=$TEST_ZIP_DIR" --standalone-lib' % \
+ os.path.join(unpack_zip_dir, pkg_version, 'setup.py'),
+ ])
+
+ if not rpmbuild:
+ msg = "@echo \"Warning: Can not build 'rpm': no rpmbuild utility found\""
+ AlwaysBuild(Alias('rpm', [], msg))
+ else:
+ topdir = os.path.join(build, 'build',
+ 'bdist.' + platform, 'rpm')
+
+ buildroot = os.path.join(build_dir, 'rpm-buildroot')
+
+ BUILDdir = os.path.join(topdir, 'BUILD', pkg + '-' + version)
+ RPMSdir = os.path.join(topdir, 'RPMS', 'noarch')
+ SOURCESdir = os.path.join(topdir, 'SOURCES')
+ SPECSdir = os.path.join(topdir, 'SPECS')
+ SRPMSdir = os.path.join(topdir, 'SRPMS')
+
+ specfile_in = os.path.join('rpm', "%s.spec.in" % pkg)
+ specfile = os.path.join(SPECSdir, "%s-1.spec" % pkg_version)
+ sourcefile = os.path.join(SOURCESdir, "%s.tar.gz" % pkg_version);
+ noarch_rpm = os.path.join(RPMSdir, "%s-1.noarch.rpm" % pkg_version)
+ src_rpm = os.path.join(SRPMSdir, "%s-1.src.rpm" % pkg_version)
+
+ def spec_function(target, source, env):
+ """Generate the RPM .spec file from the template file.
+
+ This fills in the %files portion of the .spec file with a
+ list generated from our MANIFEST(s), so we don't have to
+ maintain multiple lists.
+ """
+ c = open(str(source[0]), 'rb').read()
+ c = string.replace(c, '__VERSION' + '__', env['VERSION'])
+ c = string.replace(c, '__RPM_FILES' + '__', env['RPM_FILES'])
+ open(str(target[0]), 'wb').write(c)
+
+ rpm_files.sort()
+ rpm_files_str = string.join(rpm_files, "\n") + "\n"
+ rpm_spec_env = env.Clone(RPM_FILES = rpm_files_str)
+ rpm_spec_action = Action(spec_function, varlist=['RPM_FILES'])
+ rpm_spec_env.Command(specfile, specfile_in, rpm_spec_action)
+
+ env.InstallAs(sourcefile, tar_gz)
+ Local(sourcefile)
+
+ targets = [ noarch_rpm, src_rpm ]
+ cmd = "$RPMBUILD --define '_topdir $(%s$)' --buildroot %s -ba $SOURCES" % (topdir, buildroot)
+ if not os.path.isdir(BUILDdir):
+ cmd = ("$( mkdir -p %s; $)" % BUILDdir) + cmd
+ t = env.Command(targets, specfile, cmd)
+ env.Depends(t, sourcefile)
+
+ dist_noarch_rpm = env.Install('$DISTDIR', noarch_rpm)
+ dist_src_rpm = env.Install('$DISTDIR', src_rpm)
+ Local(dist_noarch_rpm, dist_src_rpm)
+ AddPostAction(dist_noarch_rpm, Chmod(dist_noarch_rpm, 0644))
+ AddPostAction(dist_src_rpm, Chmod(dist_src_rpm, 0644))
+
+ dfiles = map(lambda x, d=test_rpm_dir: os.path.join(d, 'usr', x),
+ dst_files)
+ env.Command(dfiles,
+ dist_noarch_rpm,
+ "$RPM2CPIO $SOURCES | (cd $TEST_RPM_DIR && cpio -id)")