Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use python3 to run MakeMacBundleRelocatable.py #6784

Merged
merged 5 commits into from May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/MacAppBundle/CMakeLists.txt
Expand Up @@ -130,7 +130,7 @@ install(CODE
# The top-level CMakeLists.txt should prevent multiple package manager
# prefixes from being set, so the lib path will resolve correctly...
execute_process(
COMMAND python2.7
COMMAND python3
${CMAKE_SOURCE_DIR}/src/Tools/MakeMacBundleRelocatable.py
${APP_PATH} ${HOMEBREW_PREFIX}${MACPORTS_PREFIX}/lib ${ICU_PREFIX}/lib/ /usr/local/opt ${CONFIG_NGLIB} ${Qt5Core_DIR}/../../.. ${XCTEST_PATH} ${WEBKIT_FRAMEWORK_DIR}
)"
Expand Down
31 changes: 17 additions & 14 deletions src/Tools/MakeMacBundleRelocatable.py
Expand Up @@ -51,7 +51,7 @@ class DepsGraph:
graph = {}

def in_graph(self, node):
return node.name in self.graph.keys()
return node.name in list(self.graph)

def add_node(self, node):
self.graph[node.name] = node
Expand All @@ -68,10 +68,10 @@ def visit(self, operation, op_args=[]):
"""
stack = []

for k in self.graph.keys():
for k in list(self.graph):
self.graph[k]._marked = False

for k in self.graph.keys():
for k in list(self.graph):
if not self.graph[k]._marked:
stack.append(k)
while stack:
Expand All @@ -84,11 +84,14 @@ def visit(self, operation, op_args=[]):


def is_macho(path):
output = check_output(["file", path])
if output.count("Mach-O") != 0:
return True
return b'Mach-O' in check_output(['file', path])

return False
def get_token(txt, delimiter=' (', first=True):
result = txt.decode().split(delimiter)
if first:
return result[0]
else:
return result

def is_system_lib(lib):
for p in systemPaths:
Expand All @@ -109,18 +112,18 @@ def get_path(name, search_paths):

def list_install_names(path_macho):
output = check_output(["otool", "-L", path_macho])
lines = output.split("\t")
lines = output.split(b"\t")
libs = []

#first line is the filename, and if it is a library, the second line
#is the install name of it
if path_macho.endswith(os.path.basename(lines[1].split(" (")[0])):
if path_macho.endswith(os.path.basename(get_token(lines[1]))):
lines = lines[2:]
else:
lines = lines[1:]

for line in lines:
lib = line.split(" (")[0]
lib = get_token(line)
if not is_system_lib(lib):
libs.append(lib)
return libs
Expand Down Expand Up @@ -223,7 +226,7 @@ def build_deps_graph(graph, bundle_path, dirs_filter=None, search_paths=[]):
visited[fpath] = False

stack = []
for k in visited.keys():
for k in list(visited):
if not visited[k]:
stack.append(k)
while stack:
Expand All @@ -245,7 +248,7 @@ def build_deps_graph(graph, bundle_path, dirs_filter=None, search_paths=[]):
node.children.append(d.name)

dk = os.path.join(d.path, d.name)
if dk not in visited.keys():
if dk not in list(visited):
visited[dk] = False
if not visited[dk]:
stack.append(dk)
Expand Down Expand Up @@ -276,7 +279,7 @@ def get_rpaths(library):
pathRegex = r"^path (.*) \(offset \d+\)$"
expectingRpath = False
rpaths = []
for line in out.split('\n'):
for line in get_token(out, '\n', False):
line = line.strip()

if "cmd LC_RPATH" in line:
Expand Down Expand Up @@ -385,4 +388,4 @@ def main():
logging.info("Done.")

if __name__ == "__main__":
main()
main()