diff options
| author | Dudemanguy <random342@airmail.cc> | 2023-10-20 16:50:43 -0500 |
|---|---|---|
| committer | Jussi Pakkanen <jpakkane@gmail.com> | 2023-10-25 23:43:40 +0300 |
| commit | e9e098b73e116c865ae0e52bb29001740b23ba22 (patch) | |
| tree | 2954d60fb42dd866bd903a48217fc67fc8fdb726 /mesonbuild | |
| parent | ae7a9b0f4430a055ac419c6f1157cbd0e6eed45c (diff) | |
| download | meson-e9e098b73e116c865ae0e52bb29001740b23ba22.tar.gz | |
build: improve the warning for executables with the same name
adb1a360b9f9edb26eda233326b1d539baeccd5b added the feature and also the
usual meson-style warning to users that might be using the feature but
were not targeting a new enough meson version. Well unfortunately the
warning both doesn't actually work (it didn't take different directories
into account) and is also really slow because it creates an O(N^2) loop
for checking this.
Instead, rework this by adding an additional set that stores a tuple
containing the target name and its subdirectory. We only add this tuple
if the target is an executable since it is the only time it will be
relevant. After that, simply check if the name + subdir combination
already exists in the set along with the target being executable. If so,
then we execute FeatureNew which may possibly warn. This is a simply
O(1) lookup which is way faster. Fixes #12404.
Diffstat (limited to 'mesonbuild')
| -rw-r--r-- | mesonbuild/build.py | 1 | ||||
| -rw-r--r-- | mesonbuild/interpreter/interpreter.py | 18 |
2 files changed, 13 insertions, 6 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 05ec9deb7..4fc409a8d 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -252,6 +252,7 @@ class Build: self.environment = environment self.projects = {} self.targets: 'T.OrderedDict[str, T.Union[CustomTarget, BuildTarget]]' = OrderedDict() + self.targetnames: T.Set[T.Tuple[str, str]] = set() # Set of executable names and their subdir self.global_args: PerMachine[T.Dict[str, T.List[str]]] = PerMachine({}, {}) self.global_link_args: PerMachine[T.Dict[str, T.List[str]]] = PerMachine({}, {}) self.projects_args: PerMachine[T.Dict[str, T.Dict[str, T.List[str]]]] = PerMachine({}, {}) diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 7fb3c9234..2fba33486 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -3163,12 +3163,15 @@ class Interpreter(InterpreterBase, HoldableObject): # To permit an executable and a shared library to have the # same name, such as "foo.exe" and "libfoo.a". idname = tobj.get_id() - for t in self.build.targets.values(): - if t.get_id() == idname: - raise InvalidCode(f'Tried to create target "{name}", but a target of that name already exists.') - if isinstance(tobj, build.Executable) and isinstance(t, build.Executable) and t.name == tobj.name: - FeatureNew.single_use('multiple executables with the same name but different suffixes', - '1.3.0', self.subproject, location=self.current_node) + subdir = tobj.get_subdir() + namedir = (name, subdir) + + if idname in self.build.targets: + raise InvalidCode(f'Tried to create target "{name}", but a target of that name already exists.') + + if isinstance(tobj, build.Executable) and namedir in self.build.targetnames: + FeatureNew.single_use(f'multiple executables with the same name, "{tobj.name}", but different suffixes in the same directory', + '1.3.0', self.subproject, location=self.current_node) if isinstance(tobj, build.BuildTarget): self.add_languages(tobj.missing_languages, True, tobj.for_machine) @@ -3176,6 +3179,9 @@ class Interpreter(InterpreterBase, HoldableObject): self.add_stdlib_info(tobj) self.build.targets[idname] = tobj + # Only need to add executables to this set + if isinstance(tobj, build.Executable): + self.build.targetnames.update([namedir]) if idname not in self.coredata.target_guids: self.coredata.target_guids[idname] = str(uuid.uuid4()).upper() |
