From 2a411e6f01d415b7df65e61820d8f394e832cbbd Mon Sep 17 00:00:00 2001 From: stevenknight Date: Thu, 29 Sep 2005 07:54:29 +0000 Subject: [PATCH] When building a .jar file and $JARCHDIR is set, prefix each .class file with the -C flag. (Kian Win Ong) git-svn-id: http://scons.tigris.org/svn/scons/trunk@1354 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/CHANGES.txt | 5 +++ src/engine/SCons/Tool/jar.py | 13 ++----- test/Java/JARCHDIR.py | 68 ++++++++++++++++++++++++++++++++++++ test/Java/JAVAH.py | 33 ++++++++--------- 4 files changed, 90 insertions(+), 29 deletions(-) create mode 100644 test/Java/JARCHDIR.py diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 7656c6bd..906f31f0 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -470,6 +470,11 @@ RELEASE 0.97 - XXX - Document the new $FRAMEWORK* variables for Mac OS X. + From Kian Win Ong: + + - When building a .jar file and there is a $JARCHDIR, put the -C + in front of each .class file on the command line. + From Chris Pawling: - Have the linkloc tool use $MSVS_VERSION to select the Microsoft diff --git a/src/engine/SCons/Tool/jar.py b/src/engine/SCons/Tool/jar.py index b0699903..ed934127 100644 --- a/src/engine/SCons/Tool/jar.py +++ b/src/engine/SCons/Tool/jar.py @@ -48,6 +48,8 @@ def jarSources(target, source, env, for_signature): # If we are changing the dir with -C, then sources should # be relative to that directory. src = src.get_path(src.fs.Dir(jarchdir)) + result.append('-C') + result.append(jarchdir) result.append(src) return result @@ -71,14 +73,6 @@ def jarFlags(target, source, env, for_signature): break return 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 [] - JarAction = SCons.Action.Action('$JARCOM', '$JARCOMSTR') JarBuilder = SCons.Builder.Builder(action = JarAction, @@ -97,8 +91,7 @@ def generate(env): env['_JARFLAGS'] = jarFlags env['_JARMANIFEST'] = jarManifest env['_JARSOURCES'] = jarSources - env['_JARCHDIR'] = jarChdir - env['JARCOM'] = '$JAR $_JARFLAGS $TARGET $_JARMANIFEST $_JARCHDIR $_JARSOURCES' + env['JARCOM'] = '$JAR $_JARFLAGS $TARGET $_JARMANIFEST $_JARSOURCES' env['JARSUFFIX'] = '.jar' def exists(env): diff --git a/test/Java/JARCHDIR.py b/test/Java/JARCHDIR.py new file mode 100644 index 00000000..dedcf4a8 --- /dev/null +++ b/test/Java/JARCHDIR.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Test that when JARCHDIR that our command to create .jar files +correctly finds all the .class files (by putting -C in front +of each class file argument). +""" + +import TestSCons + +test = TestSCons.TestSCons() + +ENV = test.java_ENV() + +if test.detect_tool('javac', ENV=ENV): + where_javac = test.detect('JAVAC', 'javac', ENV=ENV) +else: + where_javac = test.where_is('javac') +if not where_javac: + test.skip_test("Could not find Java javac, skipping test(s).\n") + +test.write('SConstruct', """ +dir = 'dist' +env = Environment(tools = ['javac', 'jar'], + JAVAC = '%(where_javac)s', + JARCHDIR = dir) +bin = env.Java(dir, Dir('./')) +jar = env.Jar(File('c.jar', dir), bin) +Default(bin, jar) +""" % locals()) + +test.write('a.java', """\ +package foo.bar; +public class a {} +""") + +test.write('b.java', """\ +package foo.bar; +public class b {} +""") + +test.run(arguments = '.') + +test.pass_test() diff --git a/test/Java/JAVAH.py b/test/Java/JAVAH.py index f9a052eb..d125a063 100644 --- a/test/Java/JAVAH.py +++ b/test/Java/JAVAH.py @@ -94,27 +94,22 @@ line 3 test.must_match('test2.h', "test2.JAVA\nline 3\n") -if test.detect_tool('javac'): - where_javac = test.detect('JAVAC', 'javac') + +ENV = test.java_ENV() + +if test.detect_tool('javac', ENV=ENV): + where_javac = test.detect('JAVAC', 'javac', ENV=ENV) else: - import SCons.Environment - env = SCons.Environment.Environment() - where_javac = env.WhereIs('javac', os.environ['PATH']) - if not where_javac: - where_javac = env.WhereIs('javac', '/usr/local/j2sdk1.3.1/bin') - if not where_javac: - test.skip_test("Could not find Java javac, skipping test(s).\n") - -if test.detect_tool('javah'): - where_javah = test.detect('JAVAH', 'javah') + where_javac = test.where_is('javac') +if not where_javac: + test.skip_test("Could not find Java javac, skipping test(s).\n") + +if test.detect_tool('javah', ENV=ENV): + where_javah = test.detect('JAVAH', 'javah', ENV=ENV) else: - import SCons.Environment - env = SCons.Environment.Environment() - where_javah = env.WhereIs('javah', os.environ['PATH']) - if not where_javah: - where_javah = env.WhereIs('javah', '/usr/local/j2sdk1.3.1/bin') - if not where_javah: - test.skip_test("Could not find Java javah, skipping test(s).\n") + where_javah = test.where_is('javah') +if not where_javah: + test.skip_test("Could not find Java javah, skipping test(s).\n") -- 2.26.2