diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index 4139aceba..8c0e7a815 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -238,27 +238,6 @@ class Backend(): self.write_benchmark_file(datafile) return (test_data, benchmark_data) - def has_source_suffix(self, target, suffix): - for s in target.get_sources(): - if s.endswith(suffix): - return True - return False - - def has_vala(self, target): - return self.has_source_suffix(target, '.vala') - - def has_rust(self, target): - return self.has_source_suffix(target, '.rs') - - def has_cs(self, target): - return self.has_source_suffix(target, '.cs') - - def has_swift(self, target): - return self.has_source_suffix(target, '.swift') - - def has_d(self, target): - return self.has_source_suffix(target, '.d') - def determine_linker(self, target, src): if isinstance(target, build.StaticLibrary): if self.build.static_cross_linker is not None: diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 1ef4effea..dd6ead23f 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -233,18 +233,18 @@ int dummy; if isinstance(target, build.Jar): self.generate_jar_target(target, outfile) return - if 'rust' in self.environment.coredata.compilers.keys() and self.has_rust(target): + if 'rust' in target.compilers: self.generate_rust_target(target, outfile) return - if 'cs' in self.environment.coredata.compilers.keys() and self.has_cs(target): + if 'cs' in target.compilers: self.generate_cs_target(target, outfile) return - if 'vala' in self.environment.coredata.compilers.keys() and self.has_vala(target): - vala_output_files = self.generate_vala_compile(target, outfile) - gen_src_deps += vala_output_files - if 'swift' in self.environment.coredata.compilers.keys() and self.has_swift(target): + if 'swift' in target.compilers: self.generate_swift_target(target, outfile) return + if 'vala' in target.compilers: + vala_output_files = self.generate_vala_compile(target, outfile) + gen_src_deps += vala_output_files self.scan_fortran_module_outputs(target) # The following deals with C/C++ compilation. (gen_src, gen_other_deps) = self.process_dep_gens(outfile, target) @@ -717,8 +717,7 @@ int dummy; outname_rel = os.path.join(self.get_target_dir(target), fname) src_list = target.get_sources() class_list = [] - compiler = self.get_compiler_for_source(src_list[0], False) - assert(compiler.get_language() == 'java') + compiler = target.compilers['java'] c = 'c' m = '' e = '' @@ -768,8 +767,7 @@ int dummy; fname = target.get_filename() outname_rel = os.path.join(self.get_target_dir(target), fname) src_list = target.get_sources() - compiler = self.get_compiler_for_source(src_list[0], False) - assert(compiler.get_language() == 'cs') + compiler = target.compilers['cs'] rel_srcs = [s.rel_to_builddir(self.build_to_src) for s in src_list] deps = [] commands = target.extra_args.get('cs', []) @@ -846,7 +844,7 @@ int dummy; def generate_vala_compile(self, target, outfile): """Vala is compiled into C. Set up all necessary build steps here.""" - valac = self.environment.coredata.compilers['vala'] + valac = target.compilers['vala'] (src, vapi_src) = self.split_vala_sources(target.get_sources()) vapi_src = [x.rel_to_builddir(self.build_to_src) for x in vapi_src] extra_dep_files = [] @@ -909,7 +907,7 @@ int dummy; return generated_c_files def generate_rust_target(self, target, outfile): - rustc = self.environment.coredata.compilers['rust'] + rustc = target.compilers['rust'] relsrc = [] for i in target.get_sources(): if not rustc.can_compile(i): @@ -1000,7 +998,7 @@ int dummy; def generate_swift_target(self, target, outfile): module_name = self.target_swift_modulename(target) - swiftc = self.environment.coredata.compilers['swift'] + swiftc = target.compilers['swift'] abssrc = [] abs_headers = [] header_imports = [] diff --git a/mesonbuild/build.py b/mesonbuild/build.py index b30021fd2..1ef183b2f 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -325,15 +325,30 @@ class BuildTarget(): self.compilers[lang] = compiler def validate_sources(self): - if len(self.sources) > 0: + if len(self.sources) == 0: + return + for lang in ('cs', 'java'): + if lang in self.compilers: + check_sources = list(self.sources) + compiler = self.compilers[lang] + if not self.can_compile_remove_sources(compiler, check_sources): + m = 'No {} sources found in target {!r}'.format(lang, self.name) + raise InvalidArguments(m) + if check_sources: + m = '{0} targets can only contain {0} files:\n'.format(lang.capitalize()) + m += '\n'.join([repr(c) for c in check_sources]) + raise InvalidArguments(m) + # CSharp and Java targets can't contain any other file types + assert(len(self.compilers) == 1) + return + if 'rust' in self.compilers: firstname = self.sources[0] if isinstance(firstname, File): firstname = firstname.fname first = os.path.split(firstname)[1] (base, suffix) = os.path.splitext(first) - if suffix == '.rs': - if self.name != base: - raise InvalidArguments('In Rust targets, the first source file must be named projectname.rs.') + if suffix != '.rs' or self.name != base: + raise InvalidArguments('In Rust targets, the first source file must be named projectname.rs.') def get_original_kwargs(self): return self.kwargs