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:
Jussi Pakkanen 2018-05-17 00:23:43 +03:00 committed by GitHub
commit 4d7ff40460
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 94 additions and 3 deletions

View File

@ -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)

View File

@ -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)

View File

@ -0,0 +1,8 @@
package com.mesonbuild;
class Simple {
public static void main(String [] args) {
TextPrinter t = new TextPrinter("Printing from Java.");
t.print();
}
}

View File

@ -0,0 +1,14 @@
package com.mesonbuild;
class TextPrinter {
private String msg;
TextPrinter(String s) {
msg = s;
}
public void print() {
System.out.println(msg);
}
}

View File

@ -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)

View File

@ -0,0 +1,5 @@
package com.mesonbuild;
public class Config {
public static final boolean FOOBAR = @foobar@;
}

View File

@ -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();
}
}
}

View File

@ -0,0 +1,14 @@
package com.mesonbuild;
class TextPrinter {
private String msg;
TextPrinter(String s) {
msg = s;
}
public void print() {
System.out.println(msg);
}
}

View File

@ -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)

View File

@ -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)