Set executable file permissions for qmake

This commit is contained in:
Dave Dalcino
2022-12-04 09:26:51 -08:00
parent 313321217d
commit 18c8259e8c
2 changed files with 7 additions and 3 deletions

View File

@@ -20,6 +20,7 @@
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import logging import logging
import os import os
import stat
import subprocess import subprocess
from logging import getLogger from logging import getLogger
from pathlib import Path from pathlib import Path
@@ -69,8 +70,9 @@ class Updater:
file.write_text(data, "UTF-8") file.write_text(data, "UTF-8")
os.chmod(str(file), st.st_mode) os.chmod(str(file), st.st_mode)
def _patch_textfile(self, file: Path, old: Union[str, List[str]], new: str): def _patch_textfile(self, file: Path, old: Union[str, List[str]], new: str, *, is_executable: bool = False):
st = file.stat() st = file.stat()
file_mode = st.st_mode | (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH if is_executable else 0)
data = file.read_text("UTF-8") data = file.read_text("UTF-8")
if isinstance(old, str): if isinstance(old, str):
data = data.replace(old, new) data = data.replace(old, new)
@@ -78,7 +80,7 @@ class Updater:
for old_str in old: for old_str in old:
data = data.replace(old_str, new) data = data.replace(old_str, new)
file.write_text(data, "UTF-8") file.write_text(data, "UTF-8")
os.chmod(str(file), st.st_mode) os.chmod(str(file), file_mode)
def _detect_qmake(self) -> bool: def _detect_qmake(self) -> bool:
"""detect Qt configurations from qmake.""" """detect Qt configurations from qmake."""
@@ -178,7 +180,7 @@ class Updater:
unpatched = [f"{p}/bin" for p in unpatched_paths()] unpatched = [f"{p}/bin" for p in unpatched_paths()]
qmake_path = self.prefix / "bin" / ("qmake.bat" if os_name == "windows" else "qmake") qmake_path = self.prefix / "bin" / ("qmake.bat" if os_name == "windows" else "qmake")
self.logger.info(f"Patching {qmake_path}") self.logger.info(f"Patching {qmake_path}")
self._patch_textfile(qmake_path, unpatched, patched) self._patch_textfile(qmake_path, unpatched, patched, is_executable=True)
def patch_qtcore(self, target): def patch_qtcore(self, target):
"""patch to QtCore""" """patch to QtCore"""

View File

@@ -1001,6 +1001,8 @@ def test_install(
for patched_file in archive.contents: for patched_file in archive.contents:
file_path = installed_path / patched_file.filename file_path = installed_path / patched_file.filename
assert file_path.is_file() assert file_path.is_file()
if file_path.name == "qmake":
assert os.access(file_path, os.X_OK), "qmake file must be executable"
expect_content = patched_file.expected_content(base_dir=output_dir, sep=os.sep) expect_content = patched_file.expected_content(base_dir=output_dir, sep=os.sep)
actual_content = file_path.read_text(encoding="utf_8") actual_content = file_path.read_text(encoding="utf_8")