1010
1111
1212def find_packages (library_name ):
13- stdout = run_command (["apt-file" , "search" , library_name ])
13+ stdout , stderr , status_code = run_command (["apt-file" , "search" , library_name ])
14+ # Check if ldd has failed for a good reason, or if there are no results
15+ if status_code != 0 :
16+ # Any other case should be be caught
17+ msg = f"apt-file search (exit code { status_code } ): { stderr } "
18+ raise ValueError (msg )
19+
1420 if not stdout .strip ():
1521 return []
1622 libs = [line .split (":" )[0 ] for line in stdout .strip ().split ("\n " )]
1723 return list (set (libs ))
1824
1925
2026def run_command (cmd , cwd = None , env = None ):
27+ # Do not raise exception here because some commands are too loose with negative exit codes
2128 result = subprocess .run (cmd , cwd = cwd , env = env , capture_output = True , text = True , check = False )
22- return result .stdout
29+ return result .stdout . strip (), result . stderr . strip (), result . returncode
2330
2431
2532def ldd (file_path ):
26- stdout = run_command (["ldd" , file_path ])
27- # For simplicity, I'm assuming if we get an error, the code is non-zero.
28- try :
29- result = subprocess .run (
30- ["ldd" , file_path ], capture_output = True , text = True , check = False ,
31- )
32- stdout = result .stdout
33- code = result .returncode
34- except subprocess .CalledProcessError :
35- stdout = ""
36- code = 1
37- return stdout , code
33+ stdout , stderr , status_code = run_command (["ldd" , file_path ])
34+ # Check if ldd has failed for a good reason, or if there are no results
35+ if status_code != 0 :
36+ # It is often the case when stdout will be empty. This is not an error
37+ if not stdout :
38+ return stdout , status_code
39+ # Any other case should be be caught
40+ msg = f"ldd (exit code { status_code } ): { stderr } "
41+ raise ValueError (msg )
42+
43+ return stdout , status_code
3844
3945
4046raw_deps = ldd ("/opt/chrome/chrome" )
4147dependencies = raw_deps [0 ].splitlines ()
42-
4348missing_deps = {
4449 r [0 ].strip ()
4550 for d in dependencies
4651 for r in [d .split ("=>" )]
4752 if len (r ) == 2 and r [1 ].strip () == "not found"
4853}
49-
5054missing_packages = []
5155for d in missing_deps :
5256 all_packages = find_packages (d )
@@ -59,5 +63,4 @@ def ldd(file_path):
5963 ]
6064 for p in packages :
6165 missing_packages .append (p )
62-
6366logger .info ("missing_packages: " + (" " .join (missing_packages )))
0 commit comments