From: stevenknight Date: Fri, 2 Apr 2004 04:48:40 +0000 (+0000) Subject: Support multiple source paths in Java. (Tom Epperly) X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=149484a772934b0648162f655e3460cd1271bed1;p=scons.git Support multiple source paths in Java. (Tom Epperly) git-svn-id: http://scons.tigris.org/svn/scons/trunk@938 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/doc/man/scons.1 b/doc/man/scons.1 index 3f8b2820..82878cb2 100644 --- a/doc/man/scons.1 +++ b/doc/man/scons.1 @@ -1281,7 +1281,7 @@ env.Jar(target = 'foo.jar', source = 'classes') .IP Java() .IP env.Java() Builds one or more Java class files -from a source tree of .java files. +from one or more source trees of .java files. The class files will be placed underneath the specified target directory. SCons will parse each source .java file @@ -1315,6 +1315,7 @@ Example: .ES env.Java(target = 'classes', source = 'src') +env.Java(target = 'classes', source = ['src1', 'src2']) .EE '\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 16f76ba4..b323e08e 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -14,6 +14,10 @@ RELEASE 0.96 - XXX - Make the CacheDir() directory if it doesn't already exist. + From Tom Epperly: + + - Allow the Java() Builder to take more than one source directory. + From Bob Halley: - Make the new *FLAGS variable type work with copied Environments. diff --git a/src/engine/SCons/Tool/javac.py b/src/engine/SCons/Tool/javac.py index b56a1189..b4a5ce9b 100644 --- a/src/engine/SCons/Tool/javac.py +++ b/src/engine/SCons/Tool/javac.py @@ -56,14 +56,15 @@ def emit_java_classes(target, source, env): slist = [] js = _my_normcase(java_suffix) - def visit(arg, dirname, names, js=js, dirnode=source[0].rdir()): - java_files = filter(lambda n, js=js: - _my_normcase(n[-len(js):]) == js, - names) - mydir = dirnode.Dir(dirname) - java_paths = map(lambda f, d=mydir: d.File(f), java_files) - arg.extend(java_paths) - os.path.walk(source[0].rdir().get_abspath(), visit, slist) + for sdir in source: + def visit(arg, dirname, names, js=js, dirnode=sdir.rdir()): + java_files = filter(lambda n, js=js: + _my_normcase(n[-len(js):]) == js, + names) + mydir = dirnode.Dir(dirname) + java_paths = map(lambda f, d=mydir: d.File(f), java_files) + arg.extend(java_paths) + os.path.walk(sdir.rdir().get_abspath(), visit, slist) tlist = [] for file in slist: diff --git a/test/JAVAC.py b/test/JAVAC.py index 13d46703..fafe3a9a 100644 --- a/test/JAVAC.py +++ b/test/JAVAC.py @@ -111,14 +111,15 @@ javac = foo.Dictionary('JAVAC') bar = foo.Copy(JAVAC = r'%s wrapper.py ' + javac) foo.Java(target = 'class1', source = 'com/sub/foo') bar.Java(target = 'class2', source = 'com/sub/bar') -foo.Java(target = 'class3', source = 'src') +foo.Java(target = 'class3', source = ['src1', 'src2']) """ % python) test.subdir('com', ['com', 'sub'], ['com', 'sub', 'foo'], ['com', 'sub', 'bar'], - 'src') + 'src1', + 'src2') test.write(['com', 'sub', 'foo', 'Example1.java'], """\ package com.sub.foo; @@ -204,8 +205,20 @@ public class Example6 } """) +test.write(['src1', 'Example7.java'], """\ +public class Example7 +{ + + public static void main(String[] args) + { + + } + +} +""") + # Acid-test file for parsing inner Java classes, courtesy Chad Austin. -test.write(['src', 'Test.java'], """\ +test.write(['src2', 'Test.java'], """\ class Empty { } @@ -265,25 +278,27 @@ class Private { test.run(arguments = '.') -test.fail_test(test.read('wrapper.out') != "wrapper.py /usr/local/j2sdk1.3.1/bin/javac -d class2 -sourcepath com/sub/bar com/sub/bar/Example4.java com/sub/bar/Example5.java com/sub/bar/Example6.java\n") - -test.fail_test(not os.path.exists(test.workpath('class1', 'com', 'sub', 'foo', 'Example1.class'))) -test.fail_test(not os.path.exists(test.workpath('class1', 'com', 'other', 'Example2.class'))) -test.fail_test(not os.path.exists(test.workpath('class1', 'com', 'sub', 'foo', 'Example3.class'))) - -test.fail_test(not os.path.exists(test.workpath('class2', 'com', 'sub', 'bar', 'Example4.class'))) -test.fail_test(not os.path.exists(test.workpath('class2', 'com', 'other', 'Example5.class'))) -test.fail_test(not os.path.exists(test.workpath('class2', 'com', 'sub', 'bar', 'Example6.class'))) - -test.fail_test(not os.path.exists(test.workpath('class3', 'Empty.class'))) -test.fail_test(not os.path.exists(test.workpath('class3', 'Listener.class'))) -test.fail_test(not os.path.exists(test.workpath('class3', 'Private.class'))) -test.fail_test(not os.path.exists(test.workpath('class3', 'Private$1.class'))) -test.fail_test(not os.path.exists(test.workpath('class3', 'Test.class'))) -test.fail_test(not os.path.exists(test.workpath('class3', 'Test$1.class'))) -test.fail_test(not os.path.exists(test.workpath('class3', 'Test$2.class'))) -test.fail_test(not os.path.exists(test.workpath('class3', 'Test$3.class'))) -test.fail_test(not os.path.exists(test.workpath('class3', 'Test$Inner.class'))) +test.must_match('wrapper.out', "wrapper.py /usr/local/j2sdk1.3.1/bin/javac -d class2 -sourcepath com/sub/bar com/sub/bar/Example4.java com/sub/bar/Example5.java com/sub/bar/Example6.java\n") + +test.must_exist(test.workpath('class1', 'com', 'sub', 'foo', 'Example1.class')) +test.must_exist(test.workpath('class1', 'com', 'other', 'Example2.class')) +test.must_exist(test.workpath('class1', 'com', 'sub', 'foo', 'Example3.class')) + +test.must_exist(test.workpath('class2', 'com', 'sub', 'bar', 'Example4.class')) +test.must_exist(test.workpath('class2', 'com', 'other', 'Example5.class')) +test.must_exist(test.workpath('class2', 'com', 'sub', 'bar', 'Example6.class')) + +test.must_exist(test.workpath('class3', 'Example7.class')) + +test.must_exist(test.workpath('class3', 'Empty.class')) +test.must_exist(test.workpath('class3', 'Listener.class')) +test.must_exist(test.workpath('class3', 'Private.class')) +test.must_exist(test.workpath('class3', 'Private$1.class')) +test.must_exist(test.workpath('class3', 'Test.class')) +test.must_exist(test.workpath('class3', 'Test$1.class')) +test.must_exist(test.workpath('class3', 'Test$2.class')) +test.must_exist(test.workpath('class3', 'Test$3.class')) +test.must_exist(test.workpath('class3', 'Test$Inner.class')) test.up_to_date(arguments = '.')