which compiler was used to compile?

R

Roedy Green

Is there a slick way to invent a constant in a program that tells you
which compiler you used. I distribute both JET and JavaC versions of
my code, and it helps to know on any error dump which version they
were using.

Right now I manually change a static final just before compiling. I
thought there ought to be something less error prone.
 
C

Christophe Vanfleteren

Roedy said:
Is there a slick way to invent a constant in a program that tells you
which compiler you used. I distribute both JET and JavaC versions of
my code, and it helps to know on any error dump which version they
were using.

Right now I manually change a static final just before compiling. I
thought there ought to be something less error prone.

Couldn't you just use an Ant task for that?
 
G

Gordon Beaton

Is there a slick way to invent a constant in a program that tells
you which compiler you used. I distribute both JET and JavaC
versions of my code, and it helps to know on any error dump which
version they were using.

Right now I manually change a static final just before compiling. I
thought there ought to be something less error prone.

Would have been a simple task for a preprocessor.

On occasion I miss the ability to define symbols on the command line
at compile time, for little things like that.

/gordon
 
R

Roedy Green

Couldn't you just use an Ant task for that?

I have done something similar with ordinary bat file that copies two
versions of ConfigForCompiler.java into place and recompiles.
 
J

John C. Bollinger

Roedy said:
Is there a slick way to invent a constant in a program that tells you
which compiler you used. I distribute both JET and JavaC versions of
my code, and it helps to know on any error dump which version they
were using.

Right now I manually change a static final just before compiling. I
thought there ought to be something less error prone.

It may be over the top, but I have been looking at Jakarta BCEL lately,
and I'm sure you could use it to programmatically alter the value of
your compiler identification constant after compilation. Wrap that up
in a custom Ant task and you only need to worry about it when working on
your build files. For true slickness, wrap it into a custom compilation
task.


John Bollinger
(e-mail address removed)
 
T

Thomas Schodt

Is there a slick way to invent a constant in a program that tells you
which compiler you used. I distribute both JET and JavaC versions of
my code, and it helps to know on any error dump which version they
were using.

One or the other compiler might generate code that puts something in system
properties?

Is the output of this (to follow) identical the two compilers?

import java.util.Properties;
import java.util.Set;
import java.util.Iterator;

public class Env {
public static void main(String[] argv) {
Properties envpp = System.getProperties();
Set es = envpp.entrySet();
Iterator tb = es.iterator();
while(tb.hasNext()) {
System.out.println("["+tb.next()+"]");
}
}
}
 
C

Chris Smith

John said:
It may be over the top, but I have been looking at Jakarta BCEL lately,
and I'm sure you could use it to programmatically alter the value of
your compiler identification constant after compilation. Wrap that up
in a custom Ant task and you only need to worry about it when working on
your build files. For true slickness, wrap it into a custom compilation
task.

That would probably work, but if you're using Ant, then you can use
tokens (@compiler@) to accomplish the same thing in a much easier way.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
J

John C. Bollinger

Chris said:
That would probably work, but if you're using Ant, then you can use
tokens (@compiler@) to accomplish the same thing in a much easier way.

Good point. The downside of that, though, is that it introduces a
dependency on Ant and the Ant buildfile. The BCEL solution can be
implemented without Ant, and the source can be compiled and used in
another environment in complete ignorance of the existence of a compiler
identification string (or Ant). Which choice is better will depend on
the project requirements, and there might be another approach
preferrable to both.


John Bollinger
(e-mail address removed)
 
C

Chris Uppal

Roedy said:
Is there a slick way to invent a constant in a program that tells you
which compiler you used.

You could wrap your compilers in shellscripts/batch files (or all but one of
them) that prepend a jar/directory to the classpath which contains a special
class with a public static final int or String field. There's be different
versions of the class (in different jars) for each compiler. Each runtime
class could check which compiler *it* was compiled with by accessing the field.

-- chris
 
R

Roedy Green

There's be different
versions of the class (in different jars) for each compiler. Each runtime
class could check which compiler *it* was compiled with by accessing the field.

Don't you have to recompile the universe if you use a public static
final in case it has been inlined?
 
C

Chris Uppal

Roedy said:
Don't you have to recompile the universe if you use a public static
final in case it has been inlined?

There should be no "in case" about it, the values of (arithmetic or String)
final fields are required to be inlined by the Java compiler. Which is what's
wanted in this case. E.g, there is no runtime dependency on the "special"
class.

So any individual .class file will "know" which compiler was used to compile it
since the value of the field will have been hard-wired into the "client" class.
That's what I thought you were trying to achieve.

Of course, if you compile your app with a mix of compilers then you'll also get
a mix of different values for the flag (which may or may not be a useful
situation).

I've just tried it, it seems to work fine.

-- chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top