diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 06e40f571..a4a4f1916 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -40,7 +40,7 @@ from .linkers import StaticLinker from .interpreterbase import FeatureNew if T.TYPE_CHECKING: - from .interpreter import Test + from .interpreter.interpreter import Test, SourceOutputs from .mesonlib import FileMode, FileOrString from .mesonlib.backend import Backend @@ -589,12 +589,11 @@ class BuildTarget(Target): known_kwargs = known_build_target_kwargs def __init__(self, name: str, subdir: str, subproject: str, for_machine: MachineChoice, - sources: T.List[File], objects, environment: environment.Environment, kwargs): + sources: T.List['SourceOutputs'], objects, environment: environment.Environment, kwargs): super().__init__(name, subdir, subproject, True, for_machine) unity_opt = environment.coredata.get_option(OptionKey('unity')) self.is_unity = unity_opt == 'on' or (unity_opt == 'subprojects' and subproject != '') self.environment = environment - self.sources: T.List[File] = [] self.compilers = OrderedDict() # type: OrderedDict[str, Compiler] self.objects = [] self.external_deps = [] @@ -613,6 +612,7 @@ class BuildTarget(Target): self.need_install = False self.pch = {} self.extra_args: T.Dict[str, T.List['FileOrString']] = {} + self.sources: T.List[File] = [] self.generated: T.Sequence[T.Union[GeneratedList, CustomTarget, CustomTargetIndex]] = [] self.d_features = {} self.pic = False diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 891f67eff..484db7866 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -68,8 +68,9 @@ if T.TYPE_CHECKING: SourceInputs = T.Union[mesonlib.File, GeneratedListHolder, TargetHolder, CustomTargetIndexHolder, GeneratedObjectsHolder, str] # Input source types passed to the build.Target5 classes - SourceOutputs = T.Union[mesonlib.File, GeneratedListHolder, TargetHolder, - CustomTargetIndexHolder, GeneratedObjectsHolder] + SourceOutputs = T.Union[mesonlib.File, build.GeneratedList, + build.BuildTarget, build.CustomTargetIndex, + build.GeneratedList] def stringifyUserArguments(args, quote=False): if isinstance(args, list): @@ -2705,13 +2706,16 @@ Try setting b_lundef to false instead.'''.format(self.coredata.options[OptionKey for s in sources: if isinstance(s, str): self.validate_within_subproject(self.subdir, s) - s = mesonlib.File.from_source_file(self.environment.source_dir, self.subdir, s) - elif not isinstance(s, (mesonlib.File, GeneratedListHolder, - TargetHolder, CustomTargetIndexHolder, - GeneratedObjectsHolder)): - raise InterpreterException('Source item is {!r} instead of ' - 'string or File-type object'.format(s)) - results.append(s) + results.append(mesonlib.File.from_source_file(self.environment.source_dir, self.subdir, s)) + elif isinstance(s, mesonlib.File): + results.append(s) + elif isinstance(s, (GeneratedListHolder, TargetHolder, + CustomTargetIndexHolder, + GeneratedObjectsHolder)): + results.append(unholder(s)) + else: + raise InterpreterException(f'Source item is {s!r} instead of ' + 'string or File-type object') return results def add_target(self, name, tobj):