Skip to content

Commit 2d29a57

Browse files
committed
optimization for apt and dpkg commands
1 parent e02c62b commit 2d29a57

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

scripts/gha/build_desktop.py

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,27 +59,18 @@ def append_line_to_file(path, line):
5959
def install_x86_support_libraries():
6060
"""Install support libraries needed to build x86 on x86_64 hosts."""
6161
if utils.is_linux_os():
62-
packages = ('libglib2.0-dev:i386', 'libsecret-1-dev:i386')
62+
packages = ('gcc-multilib', 'g++-multilib', 'libglib2.0-dev:i386', 'libsecret-1-dev:i386')
6363

6464
# First check if these packages exist on the machine already
65-
for package in packages:
66-
devnull = open(os.devnull, "w")
67-
retval = subprocess.call(["dpkg", "-s", package], stdout=devnull, stderr=subprocess.STDOUT)
68-
devnull.close()
69-
# if package is not installed, dpkg returns a value other than 0 and in this case,
70-
# we get out of this loop and install those packages.
71-
if retval != 0:
72-
break
73-
else:
74-
# If the for loop iterated without breaking, all required packages are already installed.
75-
# Nothing to do. Return from the function.
76-
return
77-
78-
utils.run_command(['apt', 'install', 'gcc-multilib', 'g++-multilib'], as_root=True)
79-
utils.run_command(['dpkg', '--add-architecture', 'i386'], as_root=True)
80-
utils.run_command(['apt', 'update'], as_root=True)
81-
for package in packages:
82-
utils.run_command(['apt', 'install', package], as_root=True)
65+
devnull = open(os.devnull, "w")
66+
process = subprocess.run(["dpkg", "-s"] + packages, stdout=devnull, stderr=subprocess.STDOUT)
67+
devnull.close()
68+
if process.returncode != 0:
69+
# This implies not all of the required packages are already installed on user's machine
70+
# Install them.
71+
utils.run_command(['dpkg', '--add-architecture', 'i386'], as_root=True)
72+
utils.run_command(['apt', 'update'], as_root=True)
73+
utils.run_command(['apt', 'install'] + packages, as_root=True)
8374

8475

8576
def _install_cpp_dependencies_with_vcpkg(arch, msvc_runtime_library):

0 commit comments

Comments
 (0)