diff options
author | William Deegan <bill@baddogconsulting.com> | 2017-12-10 03:43:21 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-10 03:43:21 (GMT) |
commit | 0dffe542497a1936f96251ad2954d5d5b6ce75b5 (patch) | |
tree | 494e4f983a12caf60b865d9bf56e420b2aea5ab0 | |
parent | 65c0142aca5fe9986e4d0aba8e400f0b5bea8991 (diff) | |
parent | a510d6604b958e21d25fedcad6b8684786402a19 (diff) | |
download | SCons-0dffe542497a1936f96251ad2954d5d5b6ce75b5.zip SCons-0dffe542497a1936f96251ad2954d5d5b6ce75b5.tar.gz SCons-0dffe542497a1936f96251ad2954d5d5b6ce75b5.tar.bz2 |
Merge pull request #19 from dmoody256/JarFlattenSource
Jar regression fixes
-rw-r--r-- | src/CHANGES.txt | 2 | ||||
-rw-r--r-- | src/engine/SCons/Tool/jar.py | 50 | ||||
-rw-r--r-- | test/Java/JAR.py | 233 |
3 files changed, 268 insertions, 17 deletions
diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 40e1307..003c2d9 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -8,6 +8,8 @@ RELEASE 3.1.0.alpha.yyyymmdd - NEW DATE WILL BE INSERTED HERE From Daniel Moody: + - Updated Jar builder to handle nodes and directories better + - Updated Jar builder to flatten source list which could contain embedded lists - Removed some magic numbers from jar.py on behalf of Mats Wichmann (mats@linux.com) From Daniel Moody: diff --git a/src/engine/SCons/Tool/jar.py b/src/engine/SCons/Tool/jar.py index f833ba2..b31ccb9 100644 --- a/src/engine/SCons/Tool/jar.py +++ b/src/engine/SCons/Tool/jar.py @@ -133,7 +133,7 @@ def Jar(env, target = None, source = [], *args, **kw): # setup for checking through all the sources and handle accordingly java_class_suffix = env.subst('$JAVACLASSSUFFIX') java_suffix = env.subst('$JAVASUFFIX') - target_classes = [] + target_nodes = [] # function for determining what to do with a file and not a directory # if its already a class file then it can be used as a @@ -145,6 +145,24 @@ def Jar(env, target = None, source = [], *args, **kw): else: return [env.fs.File(s)] + # function for calling the JavaClassDir builder if a directory is + # passed as a source to Jar builder. The JavaClassDir builder will + # return an empty list if there were not target classes built from + # the directory, in this case assume the user wanted the directory + # copied into the jar as is (it contains other files such as + # resources or class files compiled from proir commands) + # TODO: investigate the expexcted behavior for directories that + # have mixed content, such as Java files along side other files + # files. + def dir_to_class(s): + dir_targets = env.JavaClassDir(source = s, *args, **kw) + if(dir_targets == []): + # no classes files could be built from the source dir + # so pass the dir as is. + return [env.fs.Dir(s)] + else: + return dir_targets + # In the case that we are passed just string to a node which is directory # but does not exist, we need to check all the current targets to see if # that directory is going to exist so we can add it as a source to Jar builder @@ -161,40 +179,40 @@ def Jar(env, target = None, source = [], *args, **kw): # loop through the sources and handle each accordingly # the goal here is to get all the source files into a class # file or a directory that contains class files - for s in source: + for s in SCons.Util.flatten(source): s = env.subst(s) if isinstance(s, SCons.Node.FS.Base): if isinstance(s, SCons.Node.FS.File): # found a file so make sure its a class file - target_classes.extend(file_to_class(s)) + target_nodes.extend(file_to_class(s)) else: - # found a dir so make sure its a dir of class files - target_classes.extend(env.JavaClassDir(source = env.fs.Dir(s), *args, **kw)) + # found a dir so get the class files out of it + target_nodes.extend(dir_to_class(s)) else: if os.path.isfile(s): # found a file that exists on the FS, make sure its a class file - target_classes.extend(file_to_class(s)) + target_nodes.extend(file_to_class(s)) elif os.path.isdir(s): - # found a dir on the FS, add it as a dir of class files - target_classes.append(env.fs.Dir(s)) + # found a dir so get the class files out of it + target_nodes.extend(dir_to_class(s)) elif s[-len(java_suffix):] == java_suffix or s[-len(java_class_suffix):] == java_class_suffix: # found a file that may not exists and is only a string # so add it after converting it to a class file - target_classes.extend(file_to_class(s)) + target_nodes.extend(file_to_class(s)) else: # found a swig file so add it after converting it to class files if(os.path.splitext(str(s))[1] == ".i"): - target_classes.extend(env.JavaClassFile(source = s, *args, **kw)) + target_nodes.extend(env.JavaClassFile(source = s, *args, **kw)) else: - # found a directory that does not yet exist, but can exist as a node - # check the target nodes to make sure it will be built, then add - # it as a source + # The final else case handles anything not caught above and makes + # sure other nodes that are sources for this jar get add as + # a source to the JarFile builder for node in get_all_targets(env): - if(s in str(node) and os.path.splitext(str(node))[1] == ""): - target_classes.append(node) + if(s == str(node)): + target_nodes.append(node) # at this point all our sources have been converted to classes or directories of class # so pass it to the Jar builder - return env.JarFile(target = target, source = target_classes, *args, **kw) + return env.JarFile(target = target, source = target_nodes, *args, **kw) def generate(env): """Add Builders and construction variables for jar to an Environment.""" diff --git a/test/Java/JAR.py b/test/Java/JAR.py index b9a5191..da2e72e 100644 --- a/test/Java/JAR.py +++ b/test/Java/JAR.py @@ -134,7 +134,7 @@ bar = foo.Clone(JAR = r'%(_python_)s wrapper_with_args.py ' + jar) foo.Java(target = 'classes', source = 'com/sub/foo') bar.Java(target = 'classes', source = 'com/sub/bar') foo.Jar(target = 'foo', source = 'classes/com/sub/foo') -bar.Jar(target = 'bar', source = 'classes/com/sub/bar') +bar.Jar(target = 'bar', source = Dir('classes/com/sub/bar')) """ % locals()) test.subdir('com', @@ -330,6 +330,237 @@ test.must_exist(['testdir2','bar.jar']) test.must_exist(['testdir2', 'barTest', 'com', 'javasource', 'JavaFile1.class']) test.must_exist(['testdir2', 'barTest', 'com', 'javasource', 'JavaFile2.class']) test.must_exist(['testdir2', 'barTest', 'com', 'javasource', 'JavaFile3.class']) + + +####### +# test list of lists + +# make some directories to test in +test.subdir('listOfLists', + ['listOfLists', 'src'], + ['listOfLists', 'src', 'com'], + ['listOfLists', 'src', 'com', 'javasource'], + ['listOfLists', 'src', 'com', 'resource']) + +# test varient dir and lists of lists +test.write(['listOfLists', 'SConstruct'], """ +foo = Environment() +foo.VariantDir('build', 'src', duplicate=0) +sourceFiles = ["src/com/javasource/JavaFile1.java", "src/com/javasource/JavaFile2.java", "src/com/javasource/JavaFile3.java",] +list_of_class_files = foo.Java('build', source=sourceFiles) +resources = ['build/com/resource/resource1.txt', 'build/com/resource/resource2.txt'] +for resource in resources: + foo.Command(resource, list_of_class_files, Copy(resource, resource.replace('build','src'))) +foo.Command('build/MANIFEST.mf', list_of_class_files, Copy('build/MANIFEST.mf', 'MANIFEST.mf')) +contents = [list_of_class_files, resources] +foo.Jar(target = 'lists', source = contents + ['build/MANIFEST.mf'], JARCHDIR='build') +foo.Command("listsTest", [], Mkdir("listsTest") ) +foo.Command('listsTest/src/com/javasource/JavaFile3.java', 'lists.jar', foo['JAR'] + ' xvf ../lists.jar', chdir='listsTest') +""") + +test.write(['listOfLists', 'src', 'com', 'javasource', 'JavaFile1.java'], """\ +package com.javasource; + +public class JavaFile1 +{ + public static void main(String[] args) + { + + } +} +""") + +test.write(['listOfLists', 'src', 'com', 'javasource', 'JavaFile2.java'], """\ +package com.javasource; + +public class JavaFile2 +{ + public static void main(String[] args) + { + + } +} +""") + +test.write(['listOfLists', 'src', 'com', 'javasource', 'JavaFile3.java'], """\ +package com.javasource; + +public class JavaFile3 +{ + public static void main(String[] args) + { + + } +} +""") + +test.write(['listOfLists', 'MANIFEST.mf'], +"""Manifest-Version: 1.0 +MyManifestTest: Test +""") + +test.write(['listOfLists', 'src', 'com', 'resource', 'resource1.txt'], """\ +this is a resource file +""") + +test.write(['listOfLists', 'src', 'com', 'resource', 'resource2.txt'], """\ +this is another resource file +""") + + +test.run(chdir='listOfLists') + +#test single target jar +test.must_exist(['listOfLists','lists.jar']) + +# make sure there are class in the jar +test.must_exist(['listOfLists', 'listsTest', 'com', 'javasource', 'JavaFile1.class']) +test.must_exist(['listOfLists', 'listsTest', 'com', 'javasource', 'JavaFile2.class']) +test.must_exist(['listOfLists', 'listsTest', 'com', 'javasource', 'JavaFile3.class']) +test.must_exist(['listOfLists', 'listsTest', 'com', 'resource', 'resource1.txt']) +test.must_exist(['listOfLists', 'listsTest', 'com', 'resource', 'resource2.txt']) +test.must_exist(['listOfLists', 'listsTest', 'META-INF', 'MANIFEST.MF']) +test.must_contain(['listOfLists', 'listsTest', 'META-INF', 'MANIFEST.MF'], b"MyManifestTest: Test" ) + +####### +# test different style of passing in dirs + +# make some directories to test in +test.subdir('testdir3', + ['testdir3', 'com'], + ['testdir3', 'com', 'sub'], + ['testdir3', 'com', 'sub', 'foo'], + ['testdir3', 'com', 'sub', 'bar']) + +# Create the jars then extract them back to check contents +test.write(['testdir3', 'SConstruct'], """ +foo = Environment() +bar = foo.Clone() +foo.Java(target = 'classes', source = 'com/sub/foo') +bar.Java(target = 'classes', source = 'com/sub/bar') +foo.Jar(target = 'foo', source = 'classes/com/sub/foo', JARCHDIR='classes') +bar.Jar(target = 'bar', source = Dir('classes/com/sub/bar'), JARCHDIR='classes') +foo.Command("fooTest", 'foo.jar', Mkdir("fooTest") ) +foo.Command('doesnt_exist1', "fooTest", foo['JAR'] + ' xvf ../foo.jar', chdir='fooTest') +bar.Command("barTest", 'bar.jar', Mkdir("barTest") ) +bar.Command('doesnt_exist2', 'barTest', bar['JAR'] + ' xvf ../bar.jar', chdir='barTest') +""") + +test.write(['testdir3', 'com', 'sub', 'foo', 'Example1.java'], """\ +package com.sub.foo; + +public class Example1 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['testdir3', 'com', 'sub', 'foo', 'Example2.java'], """\ +package com.sub.foo; + +public class Example2 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['testdir3', 'com', 'sub', 'foo', 'Example3.java'], """\ +package com.sub.foo; + +public class Example3 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['testdir3', 'com', 'sub', 'foo', 'NonJava.txt'], """\ +testfile +""") + +test.write(['testdir3', 'com', 'sub', 'bar', 'Example4.java'], """\ +package com.sub.bar; + +public class Example4 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['testdir3', 'com', 'sub', 'bar', 'Example5.java'], """\ +package com.sub.bar; + +public class Example5 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['testdir3', 'com', 'sub', 'bar', 'Example6.java'], """\ +package com.sub.bar; + +public class Example6 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['testdir3', 'com', 'sub', 'bar', 'NonJava.txt'], """\ +testfile +""") + +test.run(chdir='testdir3') + +# check the output and make sure the java files got converted to classes + + +# make sure there are class in the jar +test.must_exist(['testdir3','foo.jar']) +test.must_exist(['testdir3', 'fooTest', 'com', 'sub', 'foo', 'Example1.class']) +test.must_exist(['testdir3', 'fooTest', 'com', 'sub', 'foo', 'Example2.class']) +test.must_exist(['testdir3', 'fooTest', 'com', 'sub', 'foo', 'Example3.class']) +# TODO: determine expected behavior with resource files, should they be +# automatically copied in or specified in seperate commands +#test.must_exist(['testdir3', 'fooTest', 'com', 'sub', 'foo', 'NonJava.txt']) + +# make sure both jars got createds +test.must_exist(['testdir3','bar.jar']) +test.must_exist(['testdir3', 'barTest', 'com', 'sub', 'bar', 'Example4.class']) +test.must_exist(['testdir3', 'barTest', 'com', 'sub', 'bar', 'Example5.class']) +test.must_exist(['testdir3', 'barTest', 'com', 'sub', 'bar', 'Example6.class']) +# TODO: determine expected behavior with resource files, should they be +# automatically copied in or specified in seperate commands +#test.must_exist(['testdir3', 'fooTest', 'com', 'sub', 'bar', 'NonJava.txt']) + test.pass_test() |