Skip to content

Commit 5530bc8

Browse files
committed
Meson: rework install flow, plus more and better comments.
1 parent 459acb3 commit 5530bc8

File tree

1 file changed

+44
-31
lines changed

1 file changed

+44
-31
lines changed

lisa/tools/meson.py

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -42,58 +42,71 @@ def _install(self) -> bool:
4242
# packaged as 'meson' on older systems and 'python3-meson' on newer ones,
4343
# since it's actually just a python package.
4444
# But now we have a bunch of annoying cases.
45-
# 'meson' is installed but the wrong version
46-
# meson is installed but the right version
47-
# meson is not installed and it's the wrong version
48-
# meson is not installed and it's the right version
45+
# 1. meson is installed and it's the right version
46+
# 2. 'meson' is installed but the wrong version
47+
# 3. meson is not installed and the right version is in the repo
48+
# 4. meson is not installed and the wrong version is in the repo
49+
4950
for pkg in [
5051
"python3-meson",
5152
"meson",
5253
]:
5354
if posix_os.package_exists(pkg):
5455
package_installed = pkg
55-
break
56-
elif posix_os.is_package_in_repo(pkg):
56+
if posix_os.is_package_in_repo(pkg):
5757
package_available = pkg
58+
if package_installed or package_available:
5859
break
5960

60-
# install the available package, if one was available and not installed
61+
if package_installed:
62+
# check the installed version before touching anything
63+
if (
64+
posix_os.get_package_information(package_installed, use_cached=False)
65+
>= self._minimum_version
66+
):
67+
# meson is installed and it's the right version
68+
return self._check_exists()
69+
70+
# otherwise, install the available package from the repo
6171
if package_available:
6272
posix_os.install_packages(package_available)
73+
# and update the cached version info
74+
posix_os.get_package_information(package_available, use_cached=False)
6375
package_installed = package_available
6476

65-
# now, if either previoulsy or newly installed package, check the version
77+
# check the version, return if it's good, remove if not
6678
if package_installed:
6779
if (
68-
posix_os.get_package_information(package_installed, use_cached=False)
69-
< self._minimum_version
80+
posix_os.get_package_information(package_installed)
81+
>= self._minimum_version
7082
):
71-
# and uninstall if the version is not recent enough
83+
# the right version was in the repo
84+
return self._check_exists()
85+
else:
86+
# the wrong version was in the repo
87+
# (or wrong version installed and no update available from repo)
7288
posix_os.uninstall_packages(package_installed)
7389
package_installed = ""
74-
else:
75-
# otherwise, we're done.
76-
return self._check_exists()
7790

78-
# If we get here, we couldn't find a good version from the package manager
79-
# so we will install with pip. This is least desirable since it introduces
91+
# If we get here, we couldn't find a good version from the package manager.
92+
# So we will install with pip. This is least desirable since it introduces
8093
# unpredictable behavior when running meson or ninja with sudo.
8194
# Like sudo ninja install, for example.
82-
if not package_installed:
83-
username = self.node.tools[Whoami].get_username()
84-
self.node.tools[Pip].install_packages("meson", install_to_user=True)
85-
self.node.tools[Ln].create_link(
86-
f"/home/{username}/.local/bin/meson", "/usr/bin/meson", force=True
87-
)
88-
# ensure sudo has access as well
89-
self.node.execute(
90-
"pip3 install meson",
91-
sudo=True,
92-
shell=True,
93-
no_debug_log=True,
94-
no_info_log=True,
95-
no_error_log=True,
96-
)
95+
96+
username = self.node.tools[Whoami].get_username()
97+
self.node.tools[Pip].install_packages("meson", install_to_user=True)
98+
self.node.tools[Ln].create_link(
99+
f"/home/{username}/.local/bin/meson", "/usr/bin/meson", force=True
100+
)
101+
# ensure sudo has access as well
102+
self.node.execute(
103+
"pip3 install meson",
104+
sudo=True,
105+
shell=True,
106+
no_debug_log=True,
107+
no_info_log=True,
108+
no_error_log=True,
109+
)
97110

98111
return self._check_exists()
99112

0 commit comments

Comments
 (0)