From: stevenknight Date: Wed, 17 Sep 2003 12:01:39 +0000 (+0000) Subject: Support Jar manifest files and the -C option. Tool/ms*.py fixes for pre-Python 2... X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=855acba4ad64b86b8a849ebebc4fb445f5230965;p=scons.git Support Jar manifest files and the -C option. Tool/ms*.py fixes for pre-Python 2.2. (Charles Crain) git-svn-id: http://scons.tigris.org/svn/scons/trunk@798 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/doc/man/scons.1 b/doc/man/scons.1 index d4655247..bd35b93d 100644 --- a/doc/man/scons.1 +++ b/doc/man/scons.1 @@ -1426,6 +1426,19 @@ env.M4(target = 'foo.c', source = 'foo.c.m4') .IP Jar Builds a Java archive (.jar) file from a source tree of .class files. +If the $JAVACHDIR value is set, the +.B jar +command will change to the specified directory using the +.B \-C +option. +If the contents any of the source files begin with the string +.BR Manifest-Version , +the file is assumed to be a manifest +and is passed to the +.B jar +command with the +.B m +option set. .ES env.Jar(target = 'foo.jar', source = 'classes') @@ -3887,6 +3900,12 @@ in force for this file installation. .IP JAR The Java archive tool. +.IP JARCHDIR +The directory to which the Java archive tool should change +(using the +.B \-C +option). + .IP JARCOM The command line used to call the Java archive tool. diff --git a/src/CHANGES.txt b/src/CHANGES.txt index a2f94c15..fb22efb7 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -10,6 +10,16 @@ RELEASE X.XX - XXX + From Charles Crain: + + - Add support for a JARCHDIR variable to control changing to a + directory using the jar -C option. + + - Add support for detecting Java manifest files when using jar, + and specifying them using the jar m flag. + + - Fix some Python 2.2 specific things in various tool modules. + From Christian Engel: - Support more flexible inclusion of separate C and C++ compilers. diff --git a/src/engine/SCons/SConf.py b/src/engine/SCons/SConf.py index 22bcb482..ee3a6b52 100644 --- a/src/engine/SCons/SConf.py +++ b/src/engine/SCons/SConf.py @@ -154,6 +154,7 @@ class SConf: 0 on error. """ + global SCons import SCons.Script # really ugly, but we need BuildTask :-( # Is it better to provide a seperate Task for SConf builds ? class SConfBuildTask(SCons.Script.BuildTask): diff --git a/src/engine/SCons/Tool/jar.py b/src/engine/SCons/Tool/jar.py index fa21f3c9..5fcb205c 100644 --- a/src/engine/SCons/Tool/jar.py +++ b/src/engine/SCons/Tool/jar.py @@ -38,6 +38,47 @@ import os.path import SCons.Builder +def jarSources(target, source, env, for_signature): + """Only include sources that are not a manifest file.""" + ret = [] + for src in source: + contents = src.get_contents() + if contents[:16] != "Manifest-Version": + if env.has_key('JARCHDIR'): + # If we are changing the dir with -C, then sources should + # be relative to that directory. + ret.append(src.get_path(src.fs.Dir(env['JARCHDIR']))) + else: + ret.append(src) + return ret + +def jarManifest(target, source, env, for_signature): + """Look in sources for a manifest file, if any.""" + for src in source: + contents = src.get_contents() + if contents[:16] == "Manifest-Version": + return src + return '' + +def jarFlags(target, source, env, for_signature): + """If we have a manifest, make sure that the 'm' + flag is specified.""" + for src in source: + contents = src.get_contents() + if contents[:16] == "Manifest-Version": + if not 'm' in env['JARFLAGS']: + return env['JARFLAGS'] + 'm' + break + return env['JARFLAGS'] + +def jarChdir(target, source, env, for_signature): + """If we have an Environment variable by the name + of JARCHDIR, then supply the command line option + '-C ' to Jar.""" + if env.has_key('JARCHDIR'): + return [ '-C', '$JARCHDIR' ] + return '' + JarBuilder = SCons.Builder.Builder(action = '$JARCOM', source_factory = SCons.Node.FS.default_fs.Entry, suffix = '$JARSUFFIX') @@ -51,7 +92,11 @@ def generate(env): env['JAR'] = 'jar' env['JARFLAGS'] = 'cf' - env['JARCOM'] = '$JAR $JARFLAGS $TARGET $SOURCE' + env['_JARFLAGS'] = jarFlags + env['_JARMANIFEST'] = jarManifest + env['_JARSOURCES'] = jarSources + env['_JARCHDIR'] = jarChdir + env['JARCOM'] = '$JAR $_JARFLAGS $TARGET $_JARMANIFEST $_JARCHDIR $_JARSOURCES' env['JARSUFFIX'] = '.jar' def exists(env): diff --git a/src/engine/SCons/Tool/mslib.py b/src/engine/SCons/Tool/mslib.py index 6d0b70b6..646cbdec 100644 --- a/src/engine/SCons/Tool/mslib.py +++ b/src/engine/SCons/Tool/mslib.py @@ -70,4 +70,4 @@ def exists(env): return env.Detect('lib') else: # there's at least one version of MSVS installed. - return True + return 1 diff --git a/src/engine/SCons/Tool/mslink.py b/src/engine/SCons/Tool/mslink.py index ccd89329..282fb22d 100644 --- a/src/engine/SCons/Tool/mslink.py +++ b/src/engine/SCons/Tool/mslink.py @@ -190,4 +190,4 @@ def exists(env): return env.Detect('link') else: # there's at least one version of MSVS installed. - return True + return 1 diff --git a/src/engine/SCons/Tool/msvc.py b/src/engine/SCons/Tool/msvc.py index 90707845..db434c49 100644 --- a/src/engine/SCons/Tool/msvc.py +++ b/src/engine/SCons/Tool/msvc.py @@ -434,4 +434,4 @@ def exists(env): return env.Detect('cl') else: # there's at least one version of MSVS installed. - return True + return 1 diff --git a/src/engine/SCons/Tool/msvs.py b/src/engine/SCons/Tool/msvs.py index 40361a17..d4c32ba1 100644 --- a/src/engine/SCons/Tool/msvs.py +++ b/src/engine/SCons/Tool/msvs.py @@ -259,10 +259,10 @@ class _GenerateV6DSP(_DSPGenerator): '# End Project\n') # now we pickle some data and add it to the file -- MSDEV will ignore it. - pdata = pickle.dumps(self.configs,True) + pdata = pickle.dumps(self.configs,1) pdata = base64.encodestring(pdata) self.file.write(pdata + '\n') - pdata = pickle.dumps(self.sources,True) + pdata = pickle.dumps(self.sources,1) pdata = base64.encodestring(pdata) self.file.write(pdata + '\n') @@ -410,10 +410,10 @@ class _GenerateV7DSP(_DSPGenerator): self.file.write('\n') # now we pickle some data and add it to the file -- MSDEV will ignore it. - pdata = pickle.dumps(self.configs,True) + pdata = pickle.dumps(self.configs,1) pdata = base64.encodestring(pdata) self.file.write('\n') @@ -601,7 +601,7 @@ class _GenerateV7DSW(_DSWGenerator): ' GlobalSection(ExtensibilityAddIns) = postSolution\n' ' EndGlobalSection\n' 'EndGlobal\n') - pdata = pickle.dumps(self.configs,True) + pdata = pickle.dumps(self.configs,1) pdata = base64.encodestring(pdata) self.file.write(pdata + '\n') @@ -1035,5 +1035,5 @@ def exists(env): return env.Detect('msdev') else: # there's at least one version of MSVS installed. - return True + return 1 diff --git a/src/engine/SCons/Tool/msvsTests.py b/src/engine/SCons/Tool/msvsTests.py index bd221773..43435211 100644 --- a/src/engine/SCons/Tool/msvsTests.py +++ b/src/engine/SCons/Tool/msvsTests.py @@ -392,7 +392,7 @@ def DummyQueryValue(key, value): return rv def DummyExists(path): - return True + return 1 class msvsTestCase(unittest.TestCase): def test_get_default_visual_studio_version(self): diff --git a/test/JAR.py b/test/JAR.py index 36367353..e0634be9 100644 --- a/test/JAR.py +++ b/test/JAR.py @@ -87,6 +87,35 @@ line 3 test.fail_test(test.read('test2.jar') != "test2.CLASS\nline 3\n") +test.write('myjar2.py', r""" +import sys +import string +f=open(sys.argv[2], 'wb') +f.write(string.join(sys.argv[1:])) +f.write("\n") +f.close() +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(tools = ['jar'], + JAR = r'%s myjar2.py', + JARFLAGS='cvf') +env.Jar(target = 'classes.jar', source = [ 'testdir/bar.class', + 'foo.mf' ], + JARCHDIR='testdir') +""" % (python)) + +test.subdir('testdir') +test.write([ 'testdir', 'bar.class' ], 'foo') +test.write('foo.mf', + """Manifest-Version : 1.0 + blah + blah + blah + """) +test.run(arguments='classes.jar') +test.fail_test(test.read('classes.jar') != 'cvfm classes.jar foo.mf -C testdir bar.class\n') if not os.path.exists('/usr/local/j2sdk1.3.1/bin/javac'): print "Could not find Java, skipping test(s)."