Support Jar manifest files and the -C option. Tool/ms*.py fixes for pre-Python 2...
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Wed, 17 Sep 2003 12:01:39 +0000 (12:01 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Wed, 17 Sep 2003 12:01:39 +0000 (12:01 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@798 fdb21ef1-2011-0410-befe-b5e4ea1792b1

doc/man/scons.1
src/CHANGES.txt
src/engine/SCons/SConf.py
src/engine/SCons/Tool/jar.py
src/engine/SCons/Tool/mslib.py
src/engine/SCons/Tool/mslink.py
src/engine/SCons/Tool/msvc.py
src/engine/SCons/Tool/msvs.py
src/engine/SCons/Tool/msvsTests.py
test/JAR.py

index d4655247abf25f3776c3aec72744de6ac8461f2f..bd35b93d2f6776c4a46be8700ff6ee1784bb2f04 100644 (file)
@@ -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.
 
index a2f94c1574da4fbc6e12fee96fc38975686fd636..fb22efb713ee310c072b99e104c7e1be7699221c 100644 (file)
 
 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.
index 22bcb482de6d43ffd28ea69512146fc583c5bfbc..ee3a6b520e4b2dc9ace6838e87d9ffeb3a92d6b0 100644 (file)
@@ -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):
index fa21f3c9986d5b8dcccb113d060fa9d0b652c93d..5fcb205c5d642382557c301f4bf2bf50f87cccf7 100644 (file)
@@ -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 <dir>' 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):
index 6d0b70b69694edc2e60c6529de291eccddf2662b..646cbdecd78b01fa3efd67a858c2ff42675ec695 100644 (file)
@@ -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
index ccd89329fd1bbd294d9ba9a2c0502f8a2082a624..282fb22d6f64a9e3dd9b4e50533f281b9f1d7140 100644 (file)
@@ -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
index 907078454ae0ef0b65fcb124f8edab3cda78c747..db434c495e54d5500f96f8d9cb8928b831cdca2b 100644 (file)
@@ -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
index 40361a17ab9defc23384d0ed7422f8c70f2b6606..d4c32ba109dece3491d335f0061485853dc36076 100644 (file)
@@ -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('</VisualStudioProject>\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('<!-- SCons Data:\n' + pdata + '\n')
-        pdata = pickle.dumps(self.sources,True)
+        pdata = pickle.dumps(self.sources,1)
         pdata = base64.encodestring(pdata)
         self.file.write(pdata + '-->\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
 
index bd221773b1add07b663c19c3a9d0a220b9f16a02..4343521124fd9a7493edc2469d48856c72cd65e3 100644 (file)
@@ -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):
index 3636735373828efaf5405ebae4d4733262730205..e0634be99320367eee1eea3a4a4cadafdadbfef8 100644 (file)
@@ -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)."