Boost logo

Boost-Build :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2006-09-25 13:56:04


On Monday 25 September 2006 20:45, Phillip Seaver wrote:
> Vladimir Prus wrote, on 9/22/2006 1:50 AM:
> > On Friday 22 September 2006 01:05, Phillip Seaver wrote:
> >> Has anyone used boost-build to create jar files? One of my co-workers
> >> is compiling .java files into .class files and then making a .jar file
> >> out of the .class files. The problem is the paths in the class files.
> >> He basically needs to strip off everything but the original relative
> >> path. E.g., for apago/foo.java, he gets
> >> ....../link-static/threading-multi/apago/foo.class and he needs to pass
> >> just apago/foo.class to the jar creation program.
> >
> > Isn't this the matter for passing right -C options to jar? Of course,
> > computing the right options might not be straight-forward. Or maybe not
> > -- would
> >
> > jar
> > -C ..../link-static/threading-multi
> > <all .class file>
> >
> > work?
> >
> > - Volodya
>
> Not quite. javac creates filenames relative to the source directory, so
> for ./apago/foo.java, "javac -d {build-dir}" creates
> {build-dir}/apago/foo.class.

Ah, I read your original email as saying you've some problem with jar, like
having extra directories in path.

> So, I think I need my own javac generator
> that "knows" where the output files end up.

So, you want to give javac a directory full of java files, have it
create .class files in builddir.

> As I understand it, I'll
> need to override the "run" method to accomplish this. I'll then need to
> make the .class filenames I pass to the jar command relative to the .jar
> file.
>
> Here's what I have in my class's run method:
>
> rule run ( project name ? : property-set : sources * )
> {
> local s = $(sources[1]) ;
> local a = [ new action $(s) : java.javac :
> $(property-set) ] ;
> name ?= [ $(s).name ] ;
> local sp = [ $(s).project ] ;
> local source-root = [ $(sp).get source-location ] ;
> source-root = [ path.root $(source-root) [ path.pwd ] ] ;
> local d = $(s).path ;
> d = [ path.root $(name:D) $(d) ] ;
> d = [ path.root $(d) [ path.pwd ] ] ;
> local relative = [ path.relative-to $(source-root) $(d) ] ;
> local targets = [ new file-target $(name:D=$(relative))
>
> : CLASS : $(project) : $(a) ] ;
>
> return $(targets) ;
> }
>
>
> Am I on the right track? Or do I need to go somewhere else and start
> again? :-)

I'm afraid so. A single .java file can result in multiple .class files being
produced. One language feature that I know does this is 'anonymous classes'.
I think the if you have several classes in one .java file you'll get
several .class files too, but this case might be handled by regexp, while
detecting anonymous classes is harder.

SCons is supposed to have a parser that works, which I attach. It seems to be
standlone, so you probably can call it when using Python-enabled bjam.

Even then, I think the right interface would be to specify a source directory,
not a single .java file. I think that compiling a single .java file might not
work, since other classes the compiled file depends on might not be compiled
yet. I'm not sure about this though.

- Volodya

-- 
Vladimir Prus
http://vladimir_prus.blogspot.com
Boost.Build V2: http://boost.org/boost-build2

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