Fabcoin Core  0.16.2
P2P Digital Currency
fix_homebrew_paths_in_standalone_zip.py
Go to the documentation of this file.
1 # ------------------------------------------------------------------------------
2 # This file is part of cpp-ethereum.
3 #
4 # cpp-ethereum is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # cpp-ethereum is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>
16 #
17 # -----------------------------------------------------------------------------
18 #
19 # This Python script is used within the OS X release process, to ensure
20 # that the standalone OS X ZIP files which we make are actually
21 # standalone, and not implicitly dependent on Homebrew installs for
22 # external libraries which we use.
23 #
24 # This implicit dependencies seem to show up only where we have
25 # external dependencies which are dependent on each other, and the
26 # path from one to another is an absolute path to "/usr/local/opt",
27 # the Homebrew install location. External dependencies which only
28 # depend on system libraries are fine. Our main applications seem
29 # to be fine.
30 #
31 # An example of a dependency which requires this fix-up at the time
32 # of writing is the following dependency edge:
33 #
34 # libjsonrpccpp-client.0.dylib
35 # -> /usr/local/opt/jsoncpp/lib/libjsoncpp.0.dylib
36 #
37 # See https://blogs.oracle.com/dipol/entry/dynamic_libraries_rpath_and_mac
38 # for a little overview of "install_name_tool" and "otool".
39 #
40 # -----------------------------------------------------------------------------
41 
42 import os
43 import subprocess
44 import sys
45 
46 
47 def readDependencies(fname):
48  with open(fname) as f:
49  o = subprocess.Popen(['otool', '-L', fname], stdout=subprocess.PIPE)
50  for line in o.stdout:
51  if line[0] == '\t':
52  library = line.split(' ', 1)[0][1:]
53  if library.startswith("/usr/local/lib") or library.startswith("/usr/local/opt") or library.startswith("/Users/"):
54  if (os.path.basename(library) != os.path.basename(fname)):
55  command = "install_name_tool -change " + \
56  library + " @executable_path/./" + \
57  os.path.basename(library) + " " + fname
58  print command
59  os.system("chmod +w " + fname)
60  os.system(command)
61 
62 root = sys.argv[1]
63 for (dirpath, dirnames, filenames) in os.walk(root):
64  for filename in filenames:
65  readDependencies(os.path.join(root, filename))