diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 94eaa4ff8..f0a755c52 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -970,7 +970,7 @@ int dummy; class_list = [] compiler = target.compilers['java'] c = 'c' - m = '' + m = 'm' e = '' f = 'f' main_class = target.get_main_class() @@ -980,11 +980,21 @@ int dummy; plain_class_path = self.generate_single_java_compile(src, target, compiler, outfile) class_list.append(plain_class_path) class_dep_list = [os.path.join(self.get_target_private_dir(target), i) for i in class_list] + manifest_path = os.path.join(self.get_target_private_dir(target), 'Manifest.txt') + os.makedirs(os.path.dirname(os.path.join(self.environment.get_build_dir(), manifest_path)), exist_ok=True) + with open(manifest_path, 'w') as manifest: + if any(target.link_targets): + manifest.write('Class-Path: ') + cp_paths = [os.path.join(self.get_target_dir(l), l.get_filename()) for l in target.link_targets] + manifest.write(' '.join(cp_paths)) + manifest.write('\n') jar_rule = 'java_LINKER' commands = [c + m + e + f] + commands.append(manifest_path) if e != '': commands.append(main_class) commands.append(self.get_target_filename(target)) + commands.append(manifest_path) # Java compilation can produce an arbitrary number of output # class files for a single source file. Thus tell jar to just # grab everything in the final package. @@ -1063,12 +1073,14 @@ int dummy; self.generate_generator_list_rules(target, outfile) def generate_single_java_compile(self, src, target, compiler, outfile): + deps = [os.path.join(self.get_target_dir(l), l.get_filename()) for l in target.link_targets] args = [] args += compiler.get_buildtype_args(self.get_option_for_target('buildtype', target)) args += self.build.get_global_args(compiler) 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)) + args += target.get_classpath_args() curdir = target.get_subdir() sourcepath = os.path.join(self.build_to_src, curdir) + os.pathsep sourcepath += os.path.normpath(curdir) + os.pathsep @@ -1080,6 +1092,7 @@ int dummy; plain_class_path = src.fname[:-4] + 'class' rel_obj = os.path.join(self.get_target_private_dir(target), plain_class_path) element = NinjaBuildElement(self.all_outputs, rel_obj, compiler.get_language() + '_COMPILER', rel_src) + element.add_dep(deps) element.add_item('ARGS', args) element.write(outfile) return plain_class_path diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 7d071e0b9..dc143266c 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -1911,6 +1911,9 @@ class Jar(BuildTarget): for s in self.sources: if not s.endswith('.java'): raise InvalidArguments('Jar source %s is not a java file.' % s) + for t in self.link_targets: + if not isinstance(t, Jar): + raise InvalidArguments('Link target %s is not a jar target.' % t) self.filename = self.name + '.jar' self.outputs = [self.filename] self.java_args = kwargs.get('java_args', []) @@ -1928,6 +1931,13 @@ class Jar(BuildTarget): # All jar targets are installable. pass + def is_linkable_target(self): + return True + + def get_classpath_args(self): + cp_paths = [os.path.join(l.get_subdir(), l.get_filename()) for l in self.link_targets] + return ['-cp', os.pathsep.join(cp_paths)] + class CustomTargetIndex: """A special opaque object returned by indexing a CustomTarget. This object @@ -1950,7 +1960,6 @@ class CustomTargetIndex: def get_subdir(self): return self.target.get_subdir() - class ConfigureFile: def __init__(self, subdir, sourcename, targetname, configuration_data):