2
0
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:
fedepell 2018-12-12 07:07:17 +01:00
parent ee719f1912
commit 37a36eabf2
10 changed files with 99 additions and 4 deletions

View File

@ -0,0 +1,2 @@
public class JavaTestA {
}

View File

@ -0,0 +1,7 @@
def build(bld):
bld(features='javac jar',
srcdir='src',
name='a',
basedir='.'
)

View File

@ -0,0 +1,2 @@
public class JavaTestB extends JavaTestA {
}

View File

@ -0,0 +1,8 @@
def build(bld):
bld(features='javac jar',
srcdir='src',
name='b',
basedir='.',
use='a'
)

View File

@ -0,0 +1,2 @@
public class JavaTestC extends JavaTestB {
}

View File

@ -0,0 +1,9 @@
def build(bld):
bld(features='javac jar',
srcdir='src',
name='c',
basedir='.',
use='b',
recurse_use = True
)

View File

@ -0,0 +1,2 @@
public class JavaTestD extends JavaTestC {
}

View File

@ -0,0 +1,9 @@
def build(bld):
bld(features='javac jar',
srcdir='src',
name='d',
basedir='.',
use='b c',
recurse_use = True
)

View 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')

View File

@ -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')