diff options
| -rw-r--r-- | mesonbuild/backend/ninjabackend.py | 48 | ||||
| -rw-r--r-- | mesonbuild/build.py | 7 | ||||
| -rw-r--r-- | test cases/rust/19 structured sources/empty.file | 0 | ||||
| -rw-r--r-- | test cases/rust/19 structured sources/meson.build | 2 | ||||
| -rw-r--r-- | test cases/rust/19 structured sources/src2/meson.build | 4 |
5 files changed, 37 insertions, 24 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 91f4129a8..166b118e3 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -1892,24 +1892,28 @@ class NinjaBackend(backends.Backend): elem.add_orderdep(instr) self.add_build(elem) - def __generate_sources_structure(self, root: Path, structured_sources: build.StructuredSources) -> T.Tuple[T.List[str], T.Optional[str]]: + def __generate_sources_structure(self, root: Path, structured_sources: build.StructuredSources, + main_file_ext: T.Union[str, T.Tuple[str, ...]] = tuple(), + ) -> T.Tuple[T.List[str], T.Optional[str]]: first_file: T.Optional[str] = None orderdeps: T.List[str] = [] for path, files in structured_sources.sources.items(): for file in files: if isinstance(file, File): out = root / path / Path(file.fname).name - orderdeps.append(str(out)) self._generate_copy_target(file, out) - if first_file is None: - first_file = str(out) + out_s = str(out) + orderdeps.append(out_s) + if first_file is None and out_s.endswith(main_file_ext): + first_file = out_s else: for f in file.get_outputs(): out = root / path / f - orderdeps.append(str(out)) + out_s = str(out) + orderdeps.append(out_s) self._generate_copy_target(str(Path(file.subdir) / f), out) - if first_file is None: - first_file = str(out) + if first_file is None and out_s.endswith(main_file_ext): + first_file = out_s return orderdeps, first_file def _add_rust_project_entry(self, name: str, main_rust_file: str, args: CompilerArgs, @@ -1955,23 +1959,33 @@ class NinjaBackend(backends.Backend): # Rust compiler takes only the main file as input and # figures out what other files are needed via import # statements and magic. - main_rust_file = None + main_rust_file: T.Optional[str] = None if target.structured_sources: if target.structured_sources.needs_copy(): _ods, main_rust_file = self.__generate_sources_structure(Path( - self.get_target_private_dir(target)) / 'structured', target.structured_sources) + self.get_target_private_dir(target)) / 'structured', target.structured_sources, '.rs') + if main_rust_file is None: + raise MesonException('Could not find a rust file to treat as the main file for ', target.name) else: # The only way to get here is to have only files in the "root" # positional argument, which are all generated into the same # directory - g = target.structured_sources.first_file() - - if isinstance(g, File): - main_rust_file = g.rel_to_builddir(self.build_to_src) - elif isinstance(g, GeneratedList): - main_rust_file = os.path.join(self.get_target_private_dir(target), g.get_outputs()[0]) - else: - main_rust_file = os.path.join(g.get_subdir(), g.get_outputs()[0]) + for g in target.structured_sources.sources['']: + if isinstance(g, File): + if g.endswith('.rs'): + main_rust_file = g.rel_to_builddir(self.build_to_src) + elif isinstance(g, GeneratedList): + for h in g.get_outputs(): + if h.endswith('.rs'): + main_rust_file = os.path.join(self.get_target_private_dir(target), h) + break + else: + for h in g.get_outputs(): + if h.endswith('.rs'): + main_rust_file = os.path.join(g.get_subdir(), h) + break + if main_rust_file is not None: + break _ods = [] for f in target.structured_sources.as_list(): diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 41ba32b63..7c83a2f57 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -577,13 +577,6 @@ class StructuredSources(HoldableObject): def __bool__(self) -> bool: return bool(self.sources) - def first_file(self) -> T.Union[File, GeneratedTypes]: - """Get the first source in the root - - :return: The first source in the root - """ - return self.sources[''][0] - def as_list(self) -> T.List[T.Union[File, GeneratedTypes]]: return list(itertools.chain.from_iterable(self.sources.values())) diff --git a/test cases/rust/19 structured sources/empty.file b/test cases/rust/19 structured sources/empty.file new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/test cases/rust/19 structured sources/empty.file diff --git a/test cases/rust/19 structured sources/meson.build b/test cases/rust/19 structured sources/meson.build index d5b3909ea..f1925835a 100644 --- a/test cases/rust/19 structured sources/meson.build +++ b/test cases/rust/19 structured sources/meson.build @@ -41,6 +41,7 @@ test('no-copy', find_program('no_copy_test.py'), args : meson.current_build_dir( subdir('src2') executable('copy-no-gen', srcs2) +executable('copy-no-gen-with-non-rs', srcs2_empty) m_src = configure_file( input : 'main-gen-copy.rs', @@ -56,3 +57,4 @@ m_src2 = configure_file( executable('gen-no-copy', structured_sources([m_src, m_src2])) +executable('gen-no-copy-with-non-rust', structured_sources(['empty.file', m_src, m_src2])) diff --git a/test cases/rust/19 structured sources/src2/meson.build b/test cases/rust/19 structured sources/src2/meson.build index b4844d272..16ede0d8f 100644 --- a/test cases/rust/19 structured sources/src2/meson.build +++ b/test cases/rust/19 structured sources/src2/meson.build @@ -2,3 +2,7 @@ srcs2 = structured_sources( ['main-unique.rs'], {'foo': 'foo/mod.rs'}, ) +srcs2_empty = structured_sources( + ['../empty.file', 'main-unique.rs'], + {'foo': 'foo/mod.rs'}, +) |
