mirror of
https://gitlab.com/ita1024/waf.git
synced 2024-11-22 01:46:15 +01:00
javaw: add recursive use processing if recurse_use=True
This commit is contained in:
parent
ee719f1912
commit
37a36eabf2
2
playground/java_recursive_use/a/src/JavaTestA.java
Normal file
2
playground/java_recursive_use/a/src/JavaTestA.java
Normal file
@ -0,0 +1,2 @@
|
||||
public class JavaTestA {
|
||||
}
|
7
playground/java_recursive_use/a/wscript
Normal file
7
playground/java_recursive_use/a/wscript
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
def build(bld):
|
||||
bld(features='javac jar',
|
||||
srcdir='src',
|
||||
name='a',
|
||||
basedir='.'
|
||||
)
|
2
playground/java_recursive_use/b/src/JavaTestB.java
Normal file
2
playground/java_recursive_use/b/src/JavaTestB.java
Normal file
@ -0,0 +1,2 @@
|
||||
public class JavaTestB extends JavaTestA {
|
||||
}
|
8
playground/java_recursive_use/b/wscript
Normal file
8
playground/java_recursive_use/b/wscript
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
def build(bld):
|
||||
bld(features='javac jar',
|
||||
srcdir='src',
|
||||
name='b',
|
||||
basedir='.',
|
||||
use='a'
|
||||
)
|
2
playground/java_recursive_use/c/src/JavaTestC.java
Normal file
2
playground/java_recursive_use/c/src/JavaTestC.java
Normal file
@ -0,0 +1,2 @@
|
||||
public class JavaTestC extends JavaTestB {
|
||||
}
|
9
playground/java_recursive_use/c/wscript
Normal file
9
playground/java_recursive_use/c/wscript
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
def build(bld):
|
||||
bld(features='javac jar',
|
||||
srcdir='src',
|
||||
name='c',
|
||||
basedir='.',
|
||||
use='b',
|
||||
recurse_use = True
|
||||
)
|
2
playground/java_recursive_use/d/src/JavaTestD.java
Normal file
2
playground/java_recursive_use/d/src/JavaTestD.java
Normal file
@ -0,0 +1,2 @@
|
||||
public class JavaTestD extends JavaTestC {
|
||||
}
|
9
playground/java_recursive_use/d/wscript
Normal file
9
playground/java_recursive_use/d/wscript
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
def build(bld):
|
||||
bld(features='javac jar',
|
||||
srcdir='src',
|
||||
name='d',
|
||||
basedir='.',
|
||||
use='b c',
|
||||
recurse_use = True
|
||||
)
|
22
playground/java_recursive_use/wscript
Normal file
22
playground/java_recursive_use/wscript
Normal file
@ -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')
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user