@@ -42,58 +42,71 @@ def _install(self) -> bool:
42
42
# packaged as 'meson' on older systems and 'python3-meson' on newer ones,
43
43
# since it's actually just a python package.
44
44
# 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
+
49
50
for pkg in [
50
51
"python3-meson" ,
51
52
"meson" ,
52
53
]:
53
54
if posix_os .package_exists (pkg ):
54
55
package_installed = pkg
55
- break
56
- elif posix_os .is_package_in_repo (pkg ):
56
+ if posix_os .is_package_in_repo (pkg ):
57
57
package_available = pkg
58
+ if package_installed or package_available :
58
59
break
59
60
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
61
71
if package_available :
62
72
posix_os .install_packages (package_available )
73
+ # and update the cached version info
74
+ posix_os .get_package_information (package_available , use_cached = False )
63
75
package_installed = package_available
64
76
65
- # now, if either previoulsy or newly installed package, check the version
77
+ # check the version, return if it's good, remove if not
66
78
if package_installed :
67
79
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
70
82
):
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)
72
88
posix_os .uninstall_packages (package_installed )
73
89
package_installed = ""
74
- else :
75
- # otherwise, we're done.
76
- return self ._check_exists ()
77
90
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
80
93
# unpredictable behavior when running meson or ninja with sudo.
81
94
# 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
+ )
97
110
98
111
return self ._check_exists ()
99
112
0 commit comments