Merge pull request #3577 from noverby/wip/rib/java-codegen
Include target build directory while compiling Java, for generated code dependencies (Polished)
This commit is contained in:
commit
4d7ff40460
|
@ -1029,9 +1029,13 @@ int dummy;
|
|||
args += self.build.get_project_args(compiler, target.subproject)
|
||||
args += target.get_java_args()
|
||||
args += compiler.get_output_args(self.get_target_private_dir(target))
|
||||
curdir = target.get_subdir()
|
||||
sourcepath = os.path.join(self.build_to_src, curdir) + os.pathsep
|
||||
sourcepath += os.path.normpath(curdir) + os.pathsep
|
||||
for i in target.include_dirs:
|
||||
for idir in i.get_incdirs():
|
||||
args += ['-sourcepath', os.path.join(self.build_to_src, i.curdir, idir)]
|
||||
sourcepath += os.path.join(self.build_to_src, i.curdir, idir) + os.pathsep
|
||||
args += ['-sourcepath', sourcepath]
|
||||
rel_src = src.rel_to_builddir(self.build_to_src)
|
||||
plain_class_path = src.fname[:-4] + 'class'
|
||||
rel_obj = os.path.join(self.get_target_private_dir(target), plain_class_path)
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
javaprog = jar('myprog',
|
||||
'com/mesonbuild/Simple.java',
|
||||
'com/mesonbuild/TextPrinter.java',
|
||||
main_class : 'com.mesonbuild.Simple',
|
||||
include_directories : include_directories('.'))
|
||||
main_class : 'com.mesonbuild.Simple')
|
||||
test('subdirtest', javaprog)
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package com.mesonbuild;
|
||||
|
||||
class Simple {
|
||||
public static void main(String [] args) {
|
||||
TextPrinter t = new TextPrinter("Printing from Java.");
|
||||
t.print();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.mesonbuild;
|
||||
|
||||
class TextPrinter {
|
||||
|
||||
private String msg;
|
||||
|
||||
TextPrinter(String s) {
|
||||
msg = s;
|
||||
}
|
||||
|
||||
public void print() {
|
||||
System.out.println(msg);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
# The Ninja backend used to try and pass -sourcepath repeatedly for
|
||||
# multiple includes which would discard prior includes. Since this
|
||||
# won't compile without the '.' include, this ensures that multiple
|
||||
# paths are passed in a [semi-]colon separated list instead...
|
||||
|
||||
project('includedirsjava', 'java')
|
||||
|
||||
javaprog = jar('myprog',
|
||||
'com/mesonbuild/Simple.java',
|
||||
'com/mesonbuild/TextPrinter.java',
|
||||
main_class : 'com.mesonbuild.Simple',
|
||||
include_directories : [ include_directories('com'),
|
||||
include_directories('com/mesonbuild') ])
|
||||
test('subdirtest', javaprog)
|
|
@ -0,0 +1,5 @@
|
|||
package com.mesonbuild;
|
||||
|
||||
public class Config {
|
||||
public static final boolean FOOBAR = @foobar@;
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.mesonbuild;
|
||||
|
||||
import com.mesonbuild.Config;
|
||||
|
||||
class Simple {
|
||||
public static void main(String [] args) {
|
||||
if (Config.FOOBAR) {
|
||||
TextPrinter t = new TextPrinter("Printing from Java.");
|
||||
t.print();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.mesonbuild;
|
||||
|
||||
class TextPrinter {
|
||||
|
||||
private String msg;
|
||||
|
||||
TextPrinter(String s) {
|
||||
msg = s;
|
||||
}
|
||||
|
||||
public void print() {
|
||||
System.out.println(msg);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
conf_data = configuration_data()
|
||||
conf_data.set('foobar', 'true')
|
||||
config_file = configure_file(input : 'Config.java.in',
|
||||
output : 'Config.java',
|
||||
configuration : conf_data)
|
|
@ -0,0 +1,15 @@
|
|||
# If we generate code under the build directory then the backend needs to add
|
||||
# the build directory to the -sourcepath passed to javac otherwise the compiler
|
||||
# won't be able to handle the -implicit:class behaviour of automatically
|
||||
# compiling dependency classes.
|
||||
|
||||
project('codegenjava', 'java')
|
||||
|
||||
subdir('com/mesonbuild')
|
||||
|
||||
javaprog = jar('myprog',
|
||||
config_file,
|
||||
'com/mesonbuild/Simple.java',
|
||||
'com/mesonbuild/TextPrinter.java',
|
||||
main_class : 'com.mesonbuild.Simple')
|
||||
test('subdirtest', javaprog)
|
Loading…
Reference in New Issue