From 37a36eabf209577ca2cb36aa47377143a4592dcd Mon Sep 17 00:00:00 2001 From: fedepell Date: Wed, 12 Dec 2018 07:07:17 +0100 Subject: [PATCH] javaw: add recursive use processing if recurse_use=True --- .../java_recursive_use/a/src/JavaTestA.java | 2 + playground/java_recursive_use/a/wscript | 7 ++++ .../java_recursive_use/b/src/JavaTestB.java | 2 + playground/java_recursive_use/b/wscript | 8 ++++ .../java_recursive_use/c/src/JavaTestC.java | 2 + playground/java_recursive_use/c/wscript | 9 +++++ .../java_recursive_use/d/src/JavaTestD.java | 2 + playground/java_recursive_use/d/wscript | 9 +++++ playground/java_recursive_use/wscript | 22 ++++++++++ waflib/Tools/javaw.py | 40 +++++++++++++++++-- 10 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 playground/java_recursive_use/a/src/JavaTestA.java create mode 100644 playground/java_recursive_use/a/wscript create mode 100644 playground/java_recursive_use/b/src/JavaTestB.java create mode 100644 playground/java_recursive_use/b/wscript create mode 100644 playground/java_recursive_use/c/src/JavaTestC.java create mode 100644 playground/java_recursive_use/c/wscript create mode 100644 playground/java_recursive_use/d/src/JavaTestD.java create mode 100644 playground/java_recursive_use/d/wscript create mode 100644 playground/java_recursive_use/wscript diff --git a/playground/java_recursive_use/a/src/JavaTestA.java b/playground/java_recursive_use/a/src/JavaTestA.java new file mode 100644 index 00000000..cce730e7 --- /dev/null +++ b/playground/java_recursive_use/a/src/JavaTestA.java @@ -0,0 +1,2 @@ +public class JavaTestA { +} diff --git a/playground/java_recursive_use/a/wscript b/playground/java_recursive_use/a/wscript new file mode 100644 index 00000000..26064a6a --- /dev/null +++ b/playground/java_recursive_use/a/wscript @@ -0,0 +1,7 @@ + +def build(bld): + bld(features='javac jar', + srcdir='src', + name='a', + basedir='.' + ) diff --git a/playground/java_recursive_use/b/src/JavaTestB.java b/playground/java_recursive_use/b/src/JavaTestB.java new file mode 100644 index 00000000..b2067ec4 --- /dev/null +++ b/playground/java_recursive_use/b/src/JavaTestB.java @@ -0,0 +1,2 @@ +public class JavaTestB extends JavaTestA { +} diff --git a/playground/java_recursive_use/b/wscript b/playground/java_recursive_use/b/wscript new file mode 100644 index 00000000..a5e67853 --- /dev/null +++ b/playground/java_recursive_use/b/wscript @@ -0,0 +1,8 @@ + +def build(bld): + bld(features='javac jar', + srcdir='src', + name='b', + basedir='.', + use='a' + ) diff --git a/playground/java_recursive_use/c/src/JavaTestC.java b/playground/java_recursive_use/c/src/JavaTestC.java new file mode 100644 index 00000000..1f42f48b --- /dev/null +++ b/playground/java_recursive_use/c/src/JavaTestC.java @@ -0,0 +1,2 @@ +public class JavaTestC extends JavaTestB { +} diff --git a/playground/java_recursive_use/c/wscript b/playground/java_recursive_use/c/wscript new file mode 100644 index 00000000..3cc393f8 --- /dev/null +++ b/playground/java_recursive_use/c/wscript @@ -0,0 +1,9 @@ + +def build(bld): + bld(features='javac jar', + srcdir='src', + name='c', + basedir='.', + use='b', + recurse_use = True + ) diff --git a/playground/java_recursive_use/d/src/JavaTestD.java b/playground/java_recursive_use/d/src/JavaTestD.java new file mode 100644 index 00000000..308c741b --- /dev/null +++ b/playground/java_recursive_use/d/src/JavaTestD.java @@ -0,0 +1,2 @@ +public class JavaTestD extends JavaTestC { +} diff --git a/playground/java_recursive_use/d/wscript b/playground/java_recursive_use/d/wscript new file mode 100644 index 00000000..82580c45 --- /dev/null +++ b/playground/java_recursive_use/d/wscript @@ -0,0 +1,9 @@ + +def build(bld): + bld(features='javac jar', + srcdir='src', + name='d', + basedir='.', + use='b c', + recurse_use = True + ) diff --git a/playground/java_recursive_use/wscript b/playground/java_recursive_use/wscript new file mode 100644 index 00000000..5211a6b1 --- /dev/null +++ b/playground/java_recursive_use/wscript @@ -0,0 +1,22 @@ +#! /usr/bin/env python +# encoding: utf-8# +# Federico Pellegrin, 2018 (fedepell) + +# Simple example testing usage of the recursive use processing for Java +# In the example b uses a, c uses b and d uses c. Therefore transitively +# for example c uses also a, but this by default is not enabled as it +# really depends on the code if the dependency is build or run time and +# so enabling by default may lead to unneeded work. On the other side for +# a project with many java artifacts and complex dependencies a manual +# management may be expensive. +# +# By setting recurse_use to True the recursive behaviour is enabled. +# +# Directory d tests the case when recursion stops earlier since +# a dependency is already explicitly defined + +def configure(conf): + conf.load('java') + +def build(bld): + bld.recurse('a b c d') diff --git a/waflib/Tools/javaw.py b/waflib/Tools/javaw.py index f6fd20cc..2e332d73 100644 --- a/waflib/Tools/javaw.py +++ b/waflib/Tools/javaw.py @@ -29,7 +29,7 @@ You would have to run:: import os, shutil from waflib import Task, Utils, Errors, Node from waflib.Configure import conf -from waflib.TaskGen import feature, before_method, after_method +from waflib.TaskGen import feature, before_method, after_method, taskgen_method from waflib.Tools import ccroot ccroot.USELIB_VARS['javac'] = set(['CLASSPATH', 'JAVACFLAGS']) @@ -107,6 +107,32 @@ def apply_java(self): if names: tsk.env.append_value('JAVACFLAGS', ['-sourcepath', names]) + +@taskgen_method +def java_use_rec(self, name, **kw): + """ + Processes recursively the *use* attribute for each referred java compilation + """ + if name in self.tmp_use_seen: + return + + self.tmp_use_seen.append(name) + + try: + y = self.bld.get_tgen_by_name(name) + except Errors.WafError: + self.uselib.append(name) + return + else: + y.post() + # Add generated JAR name for CLASSPATH. Task ordering (set_run_after) + # is already guaranted by ordering done between the single tasks + if hasattr(y, 'jar_task'): + self.use_lst.append(y.jar_task.outputs[0].abspath()) + + for x in self.to_list(getattr(y, 'use', [])): + self.java_use_rec(x) + @feature('javac') @before_method('propagate_uselib_vars') @after_method('apply_java') @@ -114,7 +140,8 @@ def use_javac_files(self): """ Processes the *use* attribute referring to other java compilations """ - lst = [] + self.use_lst = [] + self.tmp_use_seen = [] self.uselib = self.to_list(getattr(self, 'uselib', [])) names = self.to_list(getattr(self, 'use', [])) get = self.bld.get_tgen_by_name @@ -126,12 +153,17 @@ def use_javac_files(self): else: y.post() if hasattr(y, 'jar_task'): - lst.append(y.jar_task.outputs[0].abspath()) + self.use_lst.append(y.jar_task.outputs[0].abspath()) self.javac_task.set_run_after(y.jar_task) else: for tsk in y.tasks: self.javac_task.set_run_after(tsk) - self.env.append_value('CLASSPATH', lst) + + # If recurse_use then recursively add use attribute for each used one + if getattr(self, 'recurse_use', False): + self.java_use_rec(x) + + self.env.append_value('CLASSPATH', self.use_lst) @feature('javac') @after_method('apply_java', 'propagate_uselib_vars', 'use_javac_files')