13
13
get_task_allow_plist = os .path .join (utils , 'get-task-allow.plist' )
14
14
15
15
16
+ def file_path (string ):
17
+ if os .path .isfile (string ):
18
+ return string
19
+ else :
20
+ raise argparse .ArgumentTypeError (f"{ string } is not a valid path" )
21
+
22
+
16
23
def main (arguments ):
17
24
parser = argparse .ArgumentParser (
18
25
description = 'Postprocess binaries to prepare for \
19
26
their execution on Darwin platforms' )
20
- parser .add_argument ('bins' , nargs = '+' , help = 'one or more binary files' )
27
+ parser .add_argument ('bins' , type = file_path , nargs = '+' , help = 'one or more binary files' )
21
28
22
29
args = parser .parse_args (arguments )
23
30
@@ -37,12 +44,12 @@ def unrpathize(filename):
37
44
# `dyldinfo` has been replaced with `dyld_info`, so we try it first
38
45
# before falling back to `dyldinfo`
39
46
dylibsOutput = subprocess .check_output (
40
- ['xcrun' , 'dyld_info' , '-dependents' , filename ],
47
+ ['/usr/bin/ xcrun' , 'dyld_info' , '-dependents' , filename ],
41
48
universal_newlines = True )
42
49
except subprocess .CalledProcessError :
43
50
sys .stderr .write ("falling back to 'xcrun dyldinfo' ...\n " )
44
51
dylibsOutput = subprocess .check_output (
45
- ['xcrun' , 'dyldinfo' , '-dylibs' , filename ],
52
+ ['/usr/bin/ xcrun' , 'dyldinfo' , '-dylibs' , filename ],
46
53
universal_newlines = True )
47
54
48
55
# Do not rewrite @rpath-relative load commands for these libraries:
@@ -71,7 +78,7 @@ def unrpathize(filename):
71
78
r"(^|.*\s)(?P<path>@rpath/(?P<filename>libswift.*\.dylib))\s*$" )
72
79
73
80
# Build a command to invoke install_name_tool.
74
- command = ['install_name_tool' ]
81
+ command = ['/usr/bin/xcrun' , ' install_name_tool' ]
75
82
for line in dylibsOutput .splitlines ():
76
83
match = dylib_regex .match (line )
77
84
if match and match .group ('filename' ) not in allow_list :
@@ -82,7 +89,7 @@ def unrpathize(filename):
82
89
83
90
# Don't run the command if we didn't find any dylibs to change:
84
91
# it's invalid to invoke install_name_tool without any operations.
85
- if len (command ) == 1 :
92
+ if len (command ) == 2 :
86
93
return
87
94
88
95
# The last argument is the filename to operate on.
0 commit comments