Repository navigation
Description
This issue was originally created at: 2007-02-25 06:29:58.
This issue was reported by: stevenknight.
stevenknight said at 2007-02-25 06:29:58
Capturing two patches sent to the scons-dev list by Greg Ward back in February
2005. Need tests and documentation. Email description to be added to the
comments and patches to be attached after this initial issue creation.
stevenknight said at 2007-02-25 06:31:00
From [email protected] Sun Feb 20 10:52:33 2005
Date: Sun, 20 Feb 2005 10:44:51 -0500
From: Greg Ward [email protected]
Reply-To: [email protected]
To: [email protected]
Subject: [scons-dev] Preliminary patches to Java supportThis is a heads-up to let the SCons developers know that I'm working on
some changes to the Java support -- specifically to javac.py, for
compiling .java files to .class files. Let me first explain why SCons'
current Java support is unsuitable at my workplace.First, our source tree bears only a passing resemblance to a Java
package tree. Our source tree is partitioned into about 200 projects,
any of which can contain Java applications, Java libraries, C++ apps,
C++ libraries, Perl libraries, or Perl scripts. (Yes, I've snuck a few
Python libraries and scripts in here and there. ;-) So we can't just
layout our whole CVS tree to follow a Java package hierarchy -- for one
thing, the source tree layout predates the use of Java in our company.Second, we have many occurences of widely-separated Java source files
living in the same Java package. Eg. many of our core libraries live in
a package "RuntimeTool", so four or five different projects all have
.java files with "package RuntimeTool;" in them. (Yes, I would
like to see this change, but I don't want to have to change that in
order to change our build system.)As a result of the above two constraints, we always compile Java code in
two steps:
build a symlink tree that does map directories 1-to-1 to Java
packages (Java compilers really don't work very well otherwise)compile it
Finally, we often build multiple jar files from the same symlink tree --
eg. if two different apps live in the same project (that is, in the same
source dir), we do this:
- build the symlink tree
- compile "seed files" for app1 -- the Java compiler then follows
dependencies to build just as many .class files as are needed
for app1- build app1.jar from the resulting .class files
- blow away all *.class files
- compile "seed files" for app2
- build app2.jar from the resulting .class files
This means that the SCons way of specifying a whole source directory is
inappropriate for us: we need to specify individual source files, and
then let the compiler chase down depdencies and compile just what's
needed. So my first patch addresses this problem by modifying the Java
builder's emitter to accept either source files or source directories.Once this patch is in place, a minor annoyance in javac.py -- the
hardcoded setting of the -sourcepath option -- becomes fatal. In a
nutshell, the current use of -sourcepath in javac.py is unnecessary and
redundant: this option tells the compiler where to look for source files
not specified on the command line. Since SCons currently specifies
all source files on the command line, using -sourcepath is pointless.But with my patch to accept source files, the -sourcepath setting makes
it impossible for the compiler to chase down implicit dependencies. So
javac.py really should not set -sourcepath at all, unless the user
explicitly requests it.My solution for -sourcepath extends to the other javac path options very
easily, so my second patch adds the construction variables I mentioned
yesterday: JAVABOOTCLASSPATH, JAVACLASSPATH, and JAVASOURCEPATH. It
seems to work fine in a trivial test.I'm going to attach my current patches for your review and amusement.
These are not ready for prime time, since I haven't even tried them on
ou real-life code yet. Nor have I spent any time digging into SCons'
regression test suite to see what I've broken, how to fix that, and how
to add tests for what I've just written.Also, I'll keep my latest patches online here:
Greg--
Greg Ward [email protected] http://www.gerg.ca/
Money is truthful. If a man speaks of his honor, make him pay cash.
stevenknight said at 2007-02-25 06:31:57
From [email protected] Sun Feb 20 22:24:14 2005
Date: Sun, 20 Feb 2005 22:18:35 -0500
From: Greg Ward [email protected]
Reply-To: [email protected]
To: [email protected]
Subject: Re: [scons-dev] Preliminary patches to Java supportOn 20 February 2005, I said:
This is a heads-up to let the SCons developers know that I'm working on
some changes to the Java support -- specifically to javac.py, for
compiling .java files to .class files.
[...]Surprise surprise, I've uncovered the first fly in my ointment:
dependencies. With my patches, SCons accepts individual .java source
files and allows users to specify JAVASOURCEPATH. That means SCons has
an incomplete picture of what files the Java compiler will be
processing. Eg. if X.java depends on Y.java, but only X.java is
included in the source list, SCons (with my changes) will take no action
if Y.java changes. Bad.(I think the current javac.py dodges this by always setting -sourcepath,
which means users cannot tell the compiler to look anywhere else for
source files.)The only solution I can see is to bite the bullet and do full Java
dependency analysis. (I was under the impression that SCons already did
this, but --debug=tree shows that it does not. I need to read the code
scanner in JavaCommon.py more closely to see what it's really doing!)Here's an algorithm that should only depend on lexically scanning each
source file (ie. no need for a full Java parser):def find_deps(builddir, source):
source is the complete path to some Java source file
package = get_package(source) # read file for "package" line
for token in tokenize(source):
# token is any name seen in the source file, eg. "x",
# "java.sql.ResultSet", "SomeClass", "com.foo.OtherClass",
# "localvar", ...
names = split(token, ".")# Determine candidate filenames: # sourcefile is relative to some dir in JAVASOURCEPATH # classfile is fixed (relative to the SConstruct dir) if len(names) == 1: # 'token' is unqualfied name: could be a local variable # or method name, or the name of a class in the current package sourcefile = os.path.join(package, names[0]) + ".java" classfile = os.path.join(builddir, names[0]) + ".class" else: # 'token' is a fully-qualified name, eg. "com.foo.Foo" sourcefile = os.path.join(*names) + ".java" classfile = os.path.join(builddir, *names) + ".class" # Try to find sourcefile. If we find it, then source depends on # classfile. If not, then 'token' is either not a classname, or # it's a bad classname -- in which case the compiler will # complain. for sdir in JAVASOURCEPATH: sfile = os.path.join(sdir, sourcefile) if os.path.isfile(sfile): source depends on classfile classfile depends on sfile find_deps(sfile) # XXX circular dependencies are valid # in Java -- need a way to stop recursing!Please pick holes in this algorithm! I'm going to sleep on it, then
hopefully tomorrow I can take a good close look at the scanner in
JavaCommon.py and see if it will do what I need.The above algorithm should do for Java code what scanning for #include
lines does for C/C++ code -- is there any documentation on how to
interact with the various machinery for tracking implicit dependencies?
(How to write to .sconsign, how to respect --implicit-cache, and so
forth.) Or should I just consult the fine source code?Greg--
Greg Ward [email protected] http://www.gerg.ca/
Question authority!
stevenknight said at 2007-02-25 06:32:22
From [email protected] Mon Feb 21 10:20:06 2005
Date: Mon, 21 Feb 2005 10:04:39 -0500
From: Greg Ward [email protected]
Reply-To: [email protected]
To: [email protected]
Subject: Re: [scons-dev] Preliminary patches to Java supportOn 20 February 2005, I said:
Eg. if X.java depends on Y.java, but only X.java is
included in the source list, SCons (with my changes) will take no action
if Y.java changes. Bad.
[...]
The only solution I can see is to bite the bullet and do full Java
dependency analysis.Wait, maybe there is a simpler short-term hack: make every .class file
in the build directory depend on every .java file in all source
directories. Obviously, that way overestimates dependencies and would
cause unnecessary rebuilds, but I'd rather have unnecessary rebuilds
(false positives) than miss necessary rebuilds! It will also make the
dependency graph much larger, which could affect memory consumption.
But it's simpler to code and quite likely to be faster to run.The trick is determining the list of source directories: if
JAVASOURCEPATH is [], interpret it as ["."]. Otherwise obey it
literally. That seems to be how javac and jikes work.I'll try to code this up some evening this week, and think about full
dependency analysis in a background thread.Greg
stevenknight said at 2007-02-25 06:38:54
Created an attachment (id=135)
patch for compiling lists of .java source files
stevenknight said at 2007-02-25 06:39:34
Created an attachment (id=136)
pathopt class for common -classpath / -sourcepath manipulation
stevenknight said at 2007-08-30 08:24:28
Integrated for next release:
http://scons.tigris.org/servlets/ReadMsg?list=dev&msgNo=4215
http://scons.tigris.org/servlets/ReadMsg?list=commits&msgNo=966
stevenknight attached 01.java-files.patch at 2008-03-25 11:08:15.
patch for compiling lists of .java source files
stevenknight attached 02.java-pathopts.patch at 2008-03-25 11:08:15.
pathopt class for common -classpath / -sourcepath manipulation
stevenknight said this issue blocks #1664 at 2007-08-30 08:24:28.
Activity