diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2022-03-21 23:16:41 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-21 23:16:41 +0200 |
commit | 42af1f7092c9cfdcffd2b7ba021dc8e5d392aa8c (patch) | |
tree | f66d713eed1e6b63b2523f91dca1d67fa47a28f6 | |
parent | adc509ed98694d3c7a7b0c578c94cb3a886c21eb (diff) | |
parent | cf4d02d82a2e9d455a3d40ced6f7a07d6467fd98 (diff) | |
download | meson-42af1f7092c9cfdcffd2b7ba021dc8e5d392aa8c.zip meson-42af1f7092c9cfdcffd2b7ba021dc8e5d392aa8c.tar.gz meson-42af1f7092c9cfdcffd2b7ba021dc8e5d392aa8c.tar.bz2 |
Merge pull request #10147 from dcbaker/submit/structured-sources-subdir
structured_sources: fix subdir handling
-rw-r--r-- | mesonbuild/backend/ninjabackend.py | 23 | ||||
-rw-r--r-- | mesonbuild/build.py | 14 | ||||
-rw-r--r-- | mesonbuild/interpreter/interpreter.py | 6 | ||||
-rwxr-xr-x | test cases/rust/19 structured sources/gen.py (renamed from test cases/rust/18 structured sources/gen.py) | 0 | ||||
-rw-r--r-- | test cases/rust/19 structured sources/main-gen-copy.rs | 5 | ||||
-rw-r--r-- | test cases/rust/19 structured sources/meson.build (renamed from test cases/rust/18 structured sources/meson.build) | 19 | ||||
-rwxr-xr-x | test cases/rust/19 structured sources/no_copy_test.py (renamed from test cases/rust/18 structured sources/no_copy_test.py) | 0 | ||||
-rw-r--r-- | test cases/rust/19 structured sources/priv.rs | 3 | ||||
-rw-r--r-- | test cases/rust/19 structured sources/src/foo.rs.in (renamed from test cases/rust/18 structured sources/src/foo.rs.in) | 0 | ||||
-rw-r--r-- | test cases/rust/19 structured sources/src/main.rs (renamed from test cases/rust/18 structured sources/src/main.rs) | 0 | ||||
-rw-r--r-- | test cases/rust/19 structured sources/src2/foo/mod.rs (renamed from test cases/rust/18 structured sources/src2/foo/mod.rs) | 0 | ||||
-rw-r--r-- | test cases/rust/19 structured sources/src2/main-unique.rs (renamed from test cases/rust/18 structured sources/src2/main-unique.rs) | 0 | ||||
-rw-r--r-- | test cases/rust/19 structured sources/src2/meson.build | 4 |
13 files changed, 54 insertions, 20 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index fdd5cd3..614e864 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -1669,9 +1669,7 @@ class NinjaBackend(backends.Backend): root = Path(self.get_target_private_dir(target)) / 'structured' for path, files in target.structured_sources.sources.items(): for file in files: - if isinstance(file, (str, File)): - if isinstance(file, str): - file = File.from_absolute_file(file) + if isinstance(file, File): out = root / path / Path(file.fname).name orderdeps.append(str(out)) self._generate_copy_target(file, out) @@ -1707,23 +1705,28 @@ class NinjaBackend(backends.Backend): main_rust_file = None if target.structured_sources: - if target.structured_sources.needs_copy(target): + if target.structured_sources.needs_copy(): _ods, main_rust_file = self.__generate_compile_structure(target) orderdeps.extend(_ods) 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, str): - g = File.from_source_file(self.environment.source_dir, target.subdir, g) 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), i) + 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(), i) - orderdeps.extend([os.path.join(self.build_to_src, target.subdir, s) - for s in target.structured_sources.as_list()]) + main_rust_file = os.path.join(g.get_subdir(), g.get_outputs()[0]) + for f in target.structured_sources.as_list(): + if isinstance(f, File): + orderdeps.append(f.rel_to_builddir(self.build_to_src)) + else: + orderdeps.extend([os.path.join(self.build_to_src, f.subdir, s) + for s in f.get_outputs()]) for i in target.get_sources(): if not rustc.can_compile(i): diff --git a/mesonbuild/build.py b/mesonbuild/build.py index fbc1618..4f569a6 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -463,7 +463,7 @@ class StructuredSources(HoldableObject): represent the required filesystem layout. """ - sources: T.DefaultDict[str, T.List[T.Union[str, File, CustomTarget, CustomTargetIndex, GeneratedList]]] = field( + sources: T.DefaultDict[str, T.List[T.Union[File, CustomTarget, CustomTargetIndex, GeneratedList]]] = field( default_factory=lambda: defaultdict(list)) def __add__(self, other: StructuredSources) -> StructuredSources: @@ -475,30 +475,26 @@ class StructuredSources(HoldableObject): def __bool__(self) -> bool: return bool(self.sources) - def first_file(self) -> T.Union[str, File, CustomTarget, CustomTargetIndex, GeneratedList]: + def first_file(self) -> T.Union[File, CustomTarget, CustomTargetIndex, GeneratedList]: """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[str, File, CustomTarget, CustomTargetIndex, GeneratedList]]: + def as_list(self) -> T.List[T.Union[File, CustomTarget, CustomTargetIndex, GeneratedList]]: return list(itertools.chain.from_iterable(self.sources.values())) - def needs_copy(self, target: BuildTarget) -> bool: + def needs_copy(self) -> bool: """Do we need to create a structure in the build directory. This allows us to avoid making copies if the structures exists in the source dir. Which could happen in situations where a generated source only exists in some configurations """ - p = pathlib.Path(target.subdir) for files in self.sources.values(): for f in files: - if isinstance(f, str): - if not (target.environment.source_dir / p / f).exists(): - return True - elif isinstance(f, File): + if isinstance(f, File): if f.is_built: return True else: diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index b5e990a..ecbfd7a 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -2122,11 +2122,13 @@ external dependencies (including libraries) must go to "dependencies".''') args: T.Tuple[object, T.Optional[T.Dict[str, object]]], kwargs: 'TYPE_kwargs') -> build.StructuredSources: valid_types = (str, mesonlib.File, build.GeneratedList, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList) - sources: T.Dict[str, T.List[T.Union['mesonlib.FileOrString', 'build.GeneratedTypes']]] = collections.defaultdict(list) + sources: T.Dict[str, T.List[T.Union[mesonlib.File, 'build.GeneratedTypes']]] = collections.defaultdict(list) for arg in mesonlib.listify(args[0]): if not isinstance(arg, valid_types): raise InvalidArguments(f'structured_sources: type "{type(arg)}" is not valid') + if isinstance(arg, str): + arg = mesonlib.File.from_source_file(self.environment.source_dir, self.subdir, arg) sources[''].append(arg) if args[1]: if '' in args[1]: @@ -2135,6 +2137,8 @@ external dependencies (including libraries) must go to "dependencies".''') for arg in mesonlib.listify(v): if not isinstance(arg, valid_types): raise InvalidArguments(f'structured_sources: type "{type(arg)}" is not valid') + if isinstance(arg, str): + arg = mesonlib.File.from_source_file(self.environment.source_dir, self.subdir, arg) sources[k].append(arg) return build.StructuredSources(sources) diff --git a/test cases/rust/18 structured sources/gen.py b/test cases/rust/19 structured sources/gen.py index 16e5c04..16e5c04 100755 --- a/test cases/rust/18 structured sources/gen.py +++ b/test cases/rust/19 structured sources/gen.py diff --git a/test cases/rust/19 structured sources/main-gen-copy.rs b/test cases/rust/19 structured sources/main-gen-copy.rs new file mode 100644 index 0000000..db66a51 --- /dev/null +++ b/test cases/rust/19 structured sources/main-gen-copy.rs @@ -0,0 +1,5 @@ +include!(r#"@dir@/include.rs"#); + +pub fn main() { + priv_func(); +} diff --git a/test cases/rust/18 structured sources/meson.build b/test cases/rust/19 structured sources/meson.build index 8fa0443..d84e83f 100644 --- a/test cases/rust/18 structured sources/meson.build +++ b/test cases/rust/19 structured sources/meson.build @@ -37,3 +37,22 @@ executable( ) test('no-copy', find_program('no_copy_test.py'), args : meson.current_build_dir()) + +subdir('src2') + +executable('copy-no-gen', srcs2) + +m_src = configure_file( + input : 'main-gen-copy.rs', + output : 'main-gen-copy.rs', + configuration : {'dir' : meson.current_build_dir().replace('\\', '/')}, +) + +m_src2 = configure_file( + input : 'priv.rs', + output : 'include.rs', + copy : true +) + +executable('gen-no-copy', structured_sources([m_src, m_src2])) + diff --git a/test cases/rust/18 structured sources/no_copy_test.py b/test cases/rust/19 structured sources/no_copy_test.py index 91506b2..91506b2 100755 --- a/test cases/rust/18 structured sources/no_copy_test.py +++ b/test cases/rust/19 structured sources/no_copy_test.py diff --git a/test cases/rust/19 structured sources/priv.rs b/test cases/rust/19 structured sources/priv.rs new file mode 100644 index 0000000..aad196b --- /dev/null +++ b/test cases/rust/19 structured sources/priv.rs @@ -0,0 +1,3 @@ +fn priv_func() { + std::process::exit(0); +} diff --git a/test cases/rust/18 structured sources/src/foo.rs.in b/test cases/rust/19 structured sources/src/foo.rs.in index 4f3fc42..4f3fc42 100644 --- a/test cases/rust/18 structured sources/src/foo.rs.in +++ b/test cases/rust/19 structured sources/src/foo.rs.in diff --git a/test cases/rust/18 structured sources/src/main.rs b/test cases/rust/19 structured sources/src/main.rs index 3ffeee2..3ffeee2 100644 --- a/test cases/rust/18 structured sources/src/main.rs +++ b/test cases/rust/19 structured sources/src/main.rs diff --git a/test cases/rust/18 structured sources/src2/foo/mod.rs b/test cases/rust/19 structured sources/src2/foo/mod.rs index 9463d95..9463d95 100644 --- a/test cases/rust/18 structured sources/src2/foo/mod.rs +++ b/test cases/rust/19 structured sources/src2/foo/mod.rs diff --git a/test cases/rust/18 structured sources/src2/main-unique.rs b/test cases/rust/19 structured sources/src2/main-unique.rs index 3ffeee2..3ffeee2 100644 --- a/test cases/rust/18 structured sources/src2/main-unique.rs +++ b/test cases/rust/19 structured sources/src2/main-unique.rs diff --git a/test cases/rust/19 structured sources/src2/meson.build b/test cases/rust/19 structured sources/src2/meson.build new file mode 100644 index 0000000..b4844d2 --- /dev/null +++ b/test cases/rust/19 structured sources/src2/meson.build @@ -0,0 +1,4 @@ +srcs2 = structured_sources( + ['main-unique.rs'], + {'foo': 'foo/mod.rs'}, +) |