Boost logo

Boost-Build :

From: elesende (elesende_at_[hidden])
Date: 2004-06-17 22:48:25


Hello! I've been trying to extend Boost.Build v2 system so it will
be able to compile java files and generate jars. Ive created a base
system mainly from builtin.jam called java.jam that added a few type-
declarations and basic-targets and rules. I also added a register-
java-compiler.

Then I cloned gcc.jam into jdk.jam as a toolset definition for Sun's
JSDK.

So far I managed to get somewhere :). It compiles the target
dependencies the problem I'm facing is the the Java stupid directory
structure rule.

So currently I get X.java compiled into com/yyy/X.class. But the
system is expecting something <build-dir>\bin\jdk\debug\X.class. Is
there anyway to override this into "<build-
dir>\bin\jdk\debug\com/yyy/X.class"? (I'm willing to regex source
file for package definition).

------------------- START CODE PASTE HERE - java.jam ----------------

----
# Copyright (C) Emiliano Lesende 2004. Permission to copy, use, 
modify, sell and
# distribute this software is granted provided this copyright 
notice appears in
# all copies. This software is provided "as is" without express or 
implied
# warranty, and with no claim as to its suitability for any purpose.
# Based on builtin.jam by Vladimir Prus.
# Defines standard features and rules.
import "class" : new ;
import feature : feature compose ;
import toolset : flags ;
import errors : error ;
import type ;
import scanner ;
import generators ;
import regex ;
import virtual-target ;
import os ;
import prebuilt ;
import symlink ;
import alias ;
import property ;
import print ;
import utility ;
import builtin ;
import stage ;
feature classpath : : free path ;
type.register JAR_LIB : jar : : main ;
type.register JAVA : java ;
type.register CLASS : class ;
class jar-target-class : basic-target
{
import generators : construct : generators.construct ; 
import type ;
import path ;
rule __init__ ( name : project 
: sources * : requirements * : default-build * : usage-
requirements * )
{ 
basic-target.__init__ $(name) : $(project) 
: $(sources) : $(requirements) : $(default-build) : 
$(usage-requirements) ; 
}
rule construct ( source-targets * : property-set )
{ 
local properties = [ $(property-set).raw ] ;
# Determine the needed target type
local actual-type ;
actual-type = JAR_LIB ;
property-set = [ $(property-set).add-raw <main-target-
type>LIB ] ;
# Construct the target.
return [ generators.construct $(self.project) $(self.name) : 
$(actual-type) 
: $(property-set) : $(source-targets) : 
LIB ] ; 
} 
}
rule jar ( name : sources * : requirements * : default-build * 
: usage-requirements * )
{
local project = [ CALLER_MODULE ] ;
# This is a circular module dependency, so it must be imported 
here
import targets ;
targets.main-target-alternative
[ new jar-target-class $(name) : $(project) 
: [ targets.main-target-sources $(sources) : $(name) ] 
: [ targets.main-target-requirements $(requirements) : 
$(project) ] 
: [ targets.main-target-default-build $(default-build) : 
$(project) ]
: [ targets.main-target-usage-requirements $(usage-
requirements) : $(project) ]
] ;
}
IMPORT $(__name__) : jar : : jar ;
class java-compile-action : action 
{
import sequence ;
rule __init__ ( targets + : sources * : action-name : properties 
* )
{
action.__init__ $(targets) : $(sources) : $(action-name) : 
$(properties) ;
}
# For all virtual targets for the same dependency graph as self, 
# i.e. which belong to the same main target, add their 
directories
# to include path.
rule adjust-properties ( properties * )
{ 
local s = [ $(self.targets[1]).creating-subvariant ] ;
return $(properties) [ $(s).implicit-includes "include" ] ;
} 
}
class java-compiling-generator : generator
{
rule __init__ ( id : source-types + : target-types + :
requirements * )
{
generator.__init__ $(id) : $(source-types) : $(target-
types) :
$(requirements) ;
}
rule action-class ( )
{
return java-compile-action ;
}
}
rule register-java-compiler ( id : source-types + : target-types + :
requirements * )
{
local g = [ new java-compiling-generator $(id) : $(source-types) 
: $(target-types) : $(requirements) ] ;
generators.register $(g) ;
}
# FIXME: this is ugly, should find a better way (we'd want client 
code to
# register all generators as "generator.some-rule", not with "some-
module.some-rule".)
IMPORT $(__name__) : register-java-compiler : : generators.register-
java-compiler ;
----------------- END CODE PASTE HERE - java.jam --------------------
----------------- START CODE PASTE HERE - jdk.jam ----------------
# Copyright (C) Emiliano Lesende 2004. Permission to copy, use, 
modify, sell and
# distribute this software is granted provided this copyright 
notice appears in
# all copies. This software is provided "as is" without express or 
implied
# warranty, and with no claim as to its suitability for any purpose.
# Based on gcc.jam by Vladimir Prus.
import toolset : flags ;
import property ;
import generators ;
import os ;
import type ;
import feature ;
feature.extend toolset : jdk ;
feature.subfeature toolset jdk : version : : optional propagated 
link-incompatible ;
# Initializes the java software development kit (jsdk) toolset
# Each argument has the form:
# version binary-name [path]
# And specifies the name / path that should be used to invoke
# the specified jsdk version. The default version will be always 
called
# with 'javac'.
rule init ( a1 * : a2 * : a3 * )
{
if $(a1)
{
local version = $(a1[1]) ;
local name = $(a1[2]) ;
local path = $(a1[3]) ;
feature.extend-subfeature toolset jdk : version : 
$(version) ;
flags jdk NAME <toolset>jdk-$(version) : $(name) ;
# TODO: set path accordingly.
} 
}
if [ os.name ] = NT
{
# This causes single-line command invocation to not go through
# .bat files, thus avoiding command-line length limitations
JAMSHELL = % ; 
}
# Declare generators
generators.register-composing jdk.archive : CLASS : JAR_LIB : 
<toolset>jdk ;
generators.register-java-compiler jdk.compile : JAVA : CLASS : 
<toolset>jdk ;
# Declare flags and action for compilation
actions compile
{
$(NAME:E=javac) $(OPTIONS) "$(>)"
}
# Declare action for creating static libraries
actions piecemeal archive 
{
jar -cf "$(<)" "$(>)"
}
----------------- END CODE PASTE HERE - jdk.jam --------------------
If you have any other comments/suggestions on the code I'm will be 
more than happy to hear them. 
Regards,
Emiliano
 

Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk