SCons / Construct

#
# Construct file to build scons during development.
# (Kind of ironic that we're using the classic Perl Cons
# to build its Python child...)
#
$project = 'scons';

$env = new cons( ENV => {
			  AEGIS_PROJECT => $ENV{AEGIS_PROJECT},
			  PATH => $ENV{PATH},
			} );

Default qw( . );

#
# Grab the information that we "build" into the files (using sed).
#
chomp($date = $ARG{date} || `date '+%Y/%m/%d %H:%M:%S'`);

$developer = $ARG{developer} || '???';

chomp($revision = $ARG{version} || `aesub '\$version' 2>/dev/null` || '0.01');

@arr = split(/\./, $revision);
@arr = ($arr[0], map {length($_) == 1 ? "0$_" : $_} @arr[1 .. $#arr]);
$revision = join('.', @arr);
pop @arr if $#arr >= 2;
map {s/^[CD]//, s/^0*(\d\d)$/$1/} @arr;
$version = join('.', @arr);

#
# We use %(-%) around the date so date changes don't cause rebuilds.
#
$sed_cmd = "sed" .
       " %( -e 's+__DATE__+$date+' %)" .
       " -e 's+__DEVELOPER__+$developer+'" .
       " -e 's+__REVISION__+$revision+'" .
       " -e 's+__VERSION__+$version+'" .
       " %< > %>";

#
# Run everything in the MANIFEST through the sed command we concocted.
#
chomp(@files = `cat src/MANIFEST`);

foreach $file (@files) {
    Command $env "build/$file", "src/$file", $sed_cmd;
}

#
# Use the Python distutils to generate the packages.
#
$tar_gz = "build/dist/$project-$version.tar.gz";

@targets = (
    "build/build/bdist.linux-i686/rpm/SOURCES/$project-$version.tar.gz",
    "build/build/bdist.linux-i686/rpm/SPECS/$project.spec",
    $tar_gz,
    "build/dist/$project-$version-1.src.rpm",
    "build/dist/$project-$version.linux-i686.tar.gz",
    "build/dist/$project-$version-1.noarch.rpm",
);

@build_files = map("build/$_", @files);

Command $env [@targets], @build_files, qq(
    rm -rf build/build build/dist/*
    cd build && python setup.py bdist bdist_rpm
);

Depends $env [@targets], 'build/MANIFEST';

#
# Unpack the .tar.gz created by the distutils into build/test, and
# add the TestCmd.py module.  The runtest.py script will set PYTHONPATH
# so that the tests only look under build/test.  This makes sure that
# our tests pass with what we really packaged, not because of something
# hanging around in the development directory.
#
$test_dir = "build/test";

@test_files = map("$test_dir/$project-$version/$_", @files);

Command $env [@test_files], $tar_gz, qq(
    rm -rf $test_dir/$project-$version
    tar zxf %< -C $test_dir
);

Export qw( env test_dir );

Build "aux/Conscript";

#
# If we're running in the actual Aegis project, pack up a complete
# source .tar.gz from the project files and files in the change,
# so we can share it with helpful developers who don't use Aegis.
#
# First, lie and say that we've seen any files removed by this
# change, so they don't get added to the source files list
# that goes into the archive.
#

foreach (`aegis -list cf 2>/dev/null`) {
    $seen{"$1\n"}++ if /^source\s+remove\s.*\s(\S+)$/;
}

eval '@src_files = grep(! $seen{$_}++,
		    `aegis -list -terse pf 2>/dev/null`,
		    `aegis -list -terse cf 2>/dev/null`)';

@src_files = grep($_ !~ /(\.aeignore|\.consign)$/, @src_files);

if (@src_files) {
    chomp(@src_files);

    foreach $file (@src_files) {
	Command $env "build/$project-src/$file", $file, $sed_cmd;
    }

    Command $env "build/dist/$project-src-$version.tar.gz",
    		$tar_gz,
		map("build/$project-src/$_", @src_files), qq(
	rm -rf build/$project-src-$version
	cp -r build/$project-src build/$project-src-$version
	find build/$project-src-$version -name .consign -exec rm {} \\;
	cd build && tar zcf dist/%>:f $project-src-$version
    );
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.