From 60b9c8300c7cb8f3b5afe1e01967f59420f23fb3 Mon Sep 17 00:00:00 2001 From: Niclas Moeslund Overby Date: Tue, 19 Jun 2018 17:24:57 +0200 Subject: java: implement java linking --- mesonbuild/backend/ninjabackend.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'mesonbuild/backend') diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 94eaa4f..f0a755c 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 -- cgit v1.1 From bc8239ded025d05d924e0e09b359941505e729b5 Mon Sep 17 00:00:00 2001 From: Niclas Moeslund Overby Date: Tue, 12 Jun 2018 13:43:25 +0200 Subject: java: add jar linking test --- mesonbuild/backend/ninjabackend.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'mesonbuild/backend') diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index f0a755c..88415e8 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -981,8 +981,9 @@ int dummy; 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: + manifest_fullpath = os.path.join(self.environment.get_build_dir(), manifest_path) + os.makedirs(os.path.dirname(manifest_fullpath), exist_ok=True) + with open(manifest_fullpath, '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] @@ -994,7 +995,6 @@ int dummy; 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. -- cgit v1.1 From 62a46a9b6ec042ab624dc3563b3c777371bb3ab6 Mon Sep 17 00:00:00 2001 From: Niclas Moeslund Overby Date: Tue, 3 Jul 2018 17:50:42 +0200 Subject: java: prevent creation of manifest duplicate in jar --- mesonbuild/backend/ninjabackend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mesonbuild/backend') diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 88415e8..3ee543d 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -980,7 +980,7 @@ 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') + manifest_path = os.path.join(self.get_target_private_dir(target), 'META-INF', 'MANIFEST.MF') manifest_fullpath = os.path.join(self.environment.get_build_dir(), manifest_path) os.makedirs(os.path.dirname(manifest_fullpath), exist_ok=True) with open(manifest_fullpath, 'w') as manifest: -- cgit v1.1