From 96d2a1dcd5c9a201ea062783ea79aeb8f2039254 Mon Sep 17 00:00:00 2001 From: anthonyroach Date: Sat, 1 Sep 2001 16:03:31 +0000 Subject: [PATCH] Make the build portable to Windows NT. git-svn-id: http://scons.tigris.org/svn/scons/trunk@29 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- Construct | 124 ++++++++++++++++++++++++++------------ src/scons/BuilderTests.py | 4 +- test/errors.py | 13 ++-- 3 files changed, 97 insertions(+), 44 deletions(-) diff --git a/Construct b/Construct index 559591a1..72db2023 100644 --- a/Construct +++ b/Construct @@ -13,15 +13,49 @@ $env = new cons( ENV => { Default qw( . ); # -# Grab the information that we "build" into the files (using sed). +# An internal "whereis" routine to figure out if we have a +# given program available. +# +use Config; +sub whereis { + my $file = shift; + foreach my $dir (split(/$Config{path_sep}/, $ENV{PATH})) { + $f = File::Spec->catfile($dir, $file); + return $f if -x $f; + } + return undef +} + # -chomp($date = $ARG{date} || `date '+%Y/%m/%d %H:%M:%S'`); +# We let the presence or absence of various utilities determine +# whether or not we bother to build certain pieces of things. +# This will allow people to still do SCons work even if they +# don't have Aegis or RPM installed, for example. +# +$aegis = whereis('aegis'); +$aesub = whereis('aesub'); +$rpm = whereis('rpm'); +$jw = whereis('jw'); -$developer = $ARG{developer} || '???'; +# +# Now grab the information that we "build" into the files (using sed). +# +chomp($date = $ARG{date}); +if (! $date) { + ($sec,$min,$hour,$mday,$mon,$year) = localtime(time); + $year += 1900; + $date = sprintf("%4d/%02d/%02d %02d:%02d:%02d", + $year, $mon, $mday, $hour, $min, $sec); +} + +$developer = $ARG{developer} || $ENV{USERNAME} || $ENV{LOGNAME} || $ENV{USER}; -chomp($revision = $ARG{version} || `aesub '\$version' 2>/dev/null` || '0.01'); +$revision = $ARG{version}; +chomp($revision = `$aesub '\$version' 2>/dev/null`) if $aesub && ! $revision; +$revision = '0.01' if ! $revision; -chomp($change = $ARG{change} || `aesub '\$change' 2>/dev/null`); +$change = $ARG{change}; +chomp($change = `$aesub '\$change' 2>/dev/null`) if $aesub && ! $change; @arr = split(/\./, $revision); @arr = ($arr[0], map {length($_) == 1 ? "0$_" : $_} @arr[1 .. $#arr]); @@ -31,7 +65,7 @@ map {s/^[CD]//, s/^0*(\d\d)$/$1/} @arr; $version = join('.', @arr); # -# We use %(-%) around the date so date changes don't cause rebuilds. +# Use %(-%) around the date so date changes don't cause rebuilds. # $sed_cmd = "sed" . " %( -e 's+__DATE__+$date+' %)" . @@ -54,23 +88,32 @@ foreach $file (@files) { # $tar_gz = "build/dist/$project-$version.tar.gz"; +@setup_args = ('bdist sdist'); + @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", + $tar_gz, ); -@build_files = map("build/$_", @files); +if ($rpm) { + push(@setup_args, 'bdist_rpm'); + + push(@targets, + "build/build/bdist.linux-i686/rpm/SOURCES/$project-$version.tar.gz", + "build/build/bdist.linux-i686/rpm/SPECS/$project.spec", + "build/dist/$project-$version-1.src.rpm", + "build/dist/$project-$version-1.noarch.rpm", + ); +}; -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'; +$env->Command([@targets], + map("build/$_", @files), + qq(rm -rf build/build build/dist/* + cd build && python setup.py @setup_args) + ); + +$env->Depends([@targets], 'build/MANIFEST'); # # Unpack the .tar.gz created by the distutils into build/test, and @@ -95,11 +138,13 @@ Build "etc/Conscript"; # # Documentation. # -Link 'build/doc' => 'doc'; +if ($jw) { + Link 'build/doc' => 'doc'; -Export qw( date env revision version ); + Export qw( date env revision version ); -Build 'build/doc/Conscript'; + Build 'build/doc/Conscript'; +} # # If we're running in the actual Aegis project, pack up a complete @@ -111,29 +156,32 @@ Build 'build/doc/Conscript'; # that goes into the archive. # -foreach (`aegis -list -unf -c $change cf 2>/dev/null`) { - $seen{"$1\n"}++ if /^(?:source|test) remove(?:\s.*)+\s(\S+)$/; -} +if ($change) { + foreach (`aegis -list -unf -c $change cf 2>/dev/null`) { + $seen{"$1\n"}++ if /^(?:source|test) remove(?:\s.*)+\s(\S+)$/; + } -eval '@src_files = grep(! $seen{$_}++, + 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); + @src_files = grep($_ !~ /(\.aeignore|\.consign)$/, @src_files); -if (@src_files) { - chomp(@src_files); + if (@src_files) { + chomp(@src_files); - foreach $file (@src_files) { - Command $env "build/$project-src/$file", $file, $sed_cmd; - } + foreach $file (@src_files) { + $env->Command("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 - ); + $env->Command("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 + )); + } } diff --git a/src/scons/BuilderTests.py b/src/scons/BuilderTests.py index df585df5..1effa895 100644 --- a/src/scons/BuilderTests.py +++ b/src/scons/BuilderTests.py @@ -56,7 +56,7 @@ class BuilderTestCase(unittest.TestCase): cmd = "python %s %s xyzzy" % (act_py, outfile) builder = Builder(action = cmd) builder.execute() - assert test.read(outfile) == "act.py: xyzzy\n" + assert test.read(outfile, 'r') == "act.py: xyzzy\n" def function(kw): import os, string, sys @@ -67,7 +67,7 @@ class BuilderTestCase(unittest.TestCase): builder = Builder(action = function) builder.execute(out = outfile) - assert test.read(outfile) == "function\n" + assert test.read(outfile, 'r') == "function\n" def test_insuffix(self): """Test Builder creation with a specified input suffix diff --git a/test/errors.py b/test/errors.py index d3b7e041..d4b8d65d 100644 --- a/test/errors.py +++ b/test/errors.py @@ -2,11 +2,11 @@ __revision__ = "test/t0003.py __REVISION__ __DATE__ __DEVELOPER__" -from TestCmd import TestCmd +import TestCmd -test = TestCmd(program = 'scons.py', - workdir = '', - interpreter = 'python') +test = TestCmd.TestCmd(program = 'scons.py', + workdir = '', + interpreter = 'python') test.write('SConstruct1', """ a ! int(2.0) @@ -34,8 +34,13 @@ File "SConstruct2", line 2, in ? import os +import string sconspath = os.path.join(os.getcwd(), 'scons.py') +# Since we're using regular expression matches below, escape any +# backslashes that ended up in the path name. (Hello, Windows!) +sconspath = string.replace(sconspath, '\\', '\\\\') + test.write('SConstruct3', """ raise InternalError, 'error inside' """) -- 2.26.2