{"action":"created","comment":{"url":"https://api.github.com/repos/LLNL/spack/pulls/comments/74385957","id":74385957,"diff_hunk":"@@ -0,0 +1,210 @@\n+#  \"Benedikt Hegner (CERN)\"\n+#  \"Patrick Gartung (FNAL)\"\n+\n+import os\n+import stat\n+import platform\n+import re\n+from commands import getstatusoutput\n+from spack.util.executable import which\n+\n+import llnl.util.tty as tty\n+\n+\n+def get_existing_elf_rpaths(path_name, patchelf_executable):\n+    \"\"\"\n+    Return the RPATHS in given elf file as a list of strings.\n+    \"\"\"\n+    if platform.system() == 'Linux':\n+        command = '%s --print-rpath %s ' % (patchelf_executable, path_name)\n+        status, output = getstatusoutput(command)\n+        if status != 0:\n+            tty.warn('failed reading rpath for %s.' % path_name)\n+            return False\n+        return output.split(':')\n+    else:\n+        tty.die('relocation not supported for this platform')\n+    return retval\n+\n+def modify_macho_object(path_name, old_dir, new_dir):\n+    \"\"\"\n+    Modify MachO binaries by changing rpaths,and id and dependency lib paths.\n+\n+    Examines the output of otool -l for these three patterns\n+\n+          cmd LC_ID_DYLIB\n+      cmdsize 160\n+         name /Users/gartung/spack-macdev/opt/spack/darwin-x86_64/clang-7.0.2-apple/tcl-8.6.5-xfeydlhaojmei6iws2rnxndvriym242k/lib/libtcl8.6.dylib (offset 24)\n+\n+          cmd LC_LOAD_DYLIB\n+      cmdsize 160\n+         name /Users/gartung/spack-macdev/opt/spack/darwin-x86_64/clang-7.0.2-apple/zlib-1.2.8-cyvcqvrzlgurne424y55hxvfucvz2354/lib/libz.1.dylib (offset 24)\n+\n+          cmd LC_RPATH\n+      cmdsize 128\n+         path /Users/gartung/spack-macdev/opt/spack/darwin-x86_64/clang-7.0.2-apple/xz-5.2.2-d4ecxpuzf2g3ycz3cnj3xmdj7zdnuqwb/lib (offset 12)\n+  \n+    the old install dir in LC_LOAD_DYLIB is replace with the new install dir  using \n+        install_name_tool -id newid binary\n+\n+    the old install dir in LC_LOAD_DYLIB is replaced with the new install dir  using \n+        install_name_tool -change old new binary\n+\n+    the old install dir in LC_RPATH is replaced with the new install dir using\n+        install_name_tool  -rpath old new binary\n+   \n+    \"\"\"\n+    command = which('otool')\n+    output  = command(\"-l\", path_name, output=str, err=str)\n+    if command.returncode != 0:\n+        tty.warn('failed reading rpath for %s.' % path_name)\n+        return False\n+    last_cmd = None\n+    idpath = ''\n+    rpaths = []\n+    deps = []\n+    for line in output.split('\\n'):\n+        match = re.search('( *[a-zA-Z]+ )(.*)', line)\n+        if match:\n+            lhs = match.group(1).lstrip().rstrip()\n+            rhs = match.group(2)\n+            match2 = re.search('(.*) \\(.*\\)', rhs)\n+            if match2:\n+                rhs = match2.group(1)\n+            if lhs == 'cmd':\n+                last_cmd = rhs\n+            if lhs == 'path' and last_cmd == 'LC_RPATH':\n+                rpaths.append(rhs)\n+            if lhs == 'name' and last_cmd == 'LC_ID_DYLIB':\n+                idpath=rhs\n+            if lhs == 'name' and last_cmd == 'LC_LOAD_DYLIB':\n+                deps.append(rhs)\n+    id = idpath.replace(old_dir,new_dir)\n+    nrpaths = []\n+    for rpath in rpaths:\n+        nrpath = rpath.replace(old_dir,new_dir)\n+        nrpaths.append(nrpath)\n+    ndeps = []\n+    for dep in deps:\n+        ndep = dep.replace(old_dir,new_dir)\n+        ndeps.append(ndep)\n+\n+    st = os.stat(path_name)\n+    wmode = os.access(path_name, os.W_OK)\n+    if not wmode:\n+        os.chmod(path_name, st.st_mode | stat.S_IWUSR)\n+\n+    if id :\n+        command = (\"install_name_tool -id  %s  %s\" % (id,path_name) )\n+        status, output = getstatusoutput(command)\n+        if status != 0:\n+            tty.warn('failed writing id for %s.' % path_name)\n+            tty.warn(output)\n+\n+    for orig, new in zip(deps, ndeps):\n+        command = (\"install_name_tool -change  %s %s %s\" % \n+                         (orig, new, path_name))\n+        status, output = getstatusoutput(command)\n+        if status != 0:\n+            tty.warn('failed writing dep for %s.' % path_name)\n+            tty.warn(output)\n+\n+    for orig, new in zip(rpaths, nrpaths):\n+        command= (\"install_name_tool -rpath %s %s %s\" % \n+                         (orig,new,path_name) )\n+        status, output = getstatusoutput(command)\n+        if status != 0:\n+            tty.warn('failed writing id for %s.' % path_name)\n+            tty.warn(output)\n+\n+    os.chmod(path_name, st.st_mode)\n+    return\n+\n+\n+\n+def get_filetype(path_name):\n+    \"\"\"\n+    Check the output of the file command for given string.\n+    \"\"\"\n+    file_command = \"LC_ALL=C file -b -h \\\"%s\\\"\" % path_name\n+    status, output = getstatusoutput(file_command)\n+    if status != 0:\n+        tty.warn('getting filetype of \"%s\" failed' % path_name)\n+        return None\n+    return output.strip()\n+\n+\n+def modify_elf_object(path_name, orig_rpath, new_rpath, patchelf_executable):\n+    \"\"\"\n+    Replace RPATH's in given elf object\n+    \"\"\"\n+    st = os.stat(path_name)\n+    wmode = os.access(path_name, os.W_OK)\n+    if not wmode:\n+        os.chmod(path_name, st.st_mode | stat.S_IWUSR)\n+    if platform.system() == 'Linux':\n+        new_joined = ':'.join(new_rpath)\n+        command = \"%s --force-rpath --set-rpath '%s' '%s'\" % \\\n+            (patchelf_executable, new_joined, path_name)\n+        status, output = getstatusoutput(command)\n+        if status != 0:\n+            tty.warn('failed writing rpath for %s.' % path_name)\n+    else:\n+        tty.die('relocation not supported for this platform')\n+    os.chmod(path_name, st.st_mode)\n+\n+\n+def needs_binary_relocation(filetype):\n+    \"\"\"\n+    Check whether the given filetype is a binary that may need relocation.\n+    \"\"\"\n+    retval = False\n+    if \"relocatable\" in filetype:\n+        return False\n+    if platform.system() == 'Darwin':\n+        return ('Mach-O' in filetype)\n+    elif platform.system() == 'Linux':\n+        return ('ELF' in filetype)\n+    else:\n+        tty.die(\"Relocation not implemented for %s\" % platform.system())\n+    return retval\n+\n+\n+def needs_text_relocation(filetype):\n+    \"\"\"\n+    Check whether the given filetype needs relocation.\n+    \"\"\"\n+    return (\"text\" in filetype)\n+\n+\n+def relocate_binary(path_name, old_dir, new_dir, patchelf_executable):\n+    \"\"\"\n+    Change RPATHs in given elf or mach-o file\n+    \"\"\"\n+    if platform.system() == 'Darwin':\n+        modify_macho_object(path_name, old_dir, new_dir)\n+    elif platform.system() == 'Linux':\n+        orig_rpaths = get_existing_elf_rpaths(path_name, patchelf_executable)\n+        new_rpaths  = substitute_rpath(orig_rpaths, old_dir, new_dir)\n+        modify_elf_object(path_name, orig_rpaths, new_rpaths, patchelf_executable)\n+    else:\n+        tty.die(\"Relocation not implemented for %s\" % platform.system())\n+\n+\n+def relocate_text(path_name, old_dir, new_dir):\n+    \"\"\"\n+    Replace old path with new path in text files\n+    \"\"\"\n+    os.system(\"LC_ALL=C sed -i -e \\\"s#%s#%s#g\\\" \\\"%s\\\"\"\n+              % (old_dir, new_dir, path_name))","path":"lib/spack/spack/relocate.py","position":199,"original_position":199,"commit_id":"9ce486301c4ffcd017cc264e0ab3e1eac39ea04d","original_commit_id":"9ce486301c4ffcd017cc264e0ab3e1eac39ea04d","user":{"login":"tgamblin","id":299842,"avatar_url":"https://avatars.githubusercontent.com/u/299842?v=3","gravatar_id":"","url":"https://api.github.com/users/tgamblin","html_url":"https://github.com/tgamblin","followers_url":"https://api.github.com/users/tgamblin/followers","following_url":"https://api.github.com/users/tgamblin/following{/other_user}","gists_url":"https://api.github.com/users/tgamblin/gists{/gist_id}","starred_url":"https://api.github.com/users/tgamblin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tgamblin/subscriptions","organizations_url":"https://api.github.com/users/tgamblin/orgs","repos_url":"https://api.github.com/users/tgamblin/repos","events_url":"https://api.github.com/users/tgamblin/events{/privacy}","received_events_url":"https://api.github.com/users/tgamblin/received_events","type":"User","site_admin":false},"body":"This should probably use `filter_file` (which spack packages use) from `llnl.util.filesystem`.","created_at":"2016-08-11T08:42:03Z","updated_at":"2016-08-11T08:42:03Z","html_url":"https://github.com/LLNL/spack/pull/1013#discussion_r74385957","pull_request_url":"https://api.github.com/repos/LLNL/spack/pulls/1013","_links":{"self":{"href":"https://api.github.com/repos/LLNL/spack/pulls/comments/74385957"},"html":{"href":"https://github.com/LLNL/spack/pull/1013#discussion_r74385957"},"pull_request":{"href":"https://api.github.com/repos/LLNL/spack/pulls/1013"}}},"pull_request":{"url":"https://api.github.com/repos/LLNL/spack/pulls/1013","id":72190561,"html_url":"https://github.com/LLNL/spack/pull/1013","diff_url":"https://github.com/LLNL/spack/pull/1013.diff","patch_url":"https://github.com/LLNL/spack/pull/1013.patch","issue_url":"https://api.github.com/repos/LLNL/spack/issues/1013","number":1013,"state":"open","locked":false,"title":"Feature: creation of relocatable tarballs from installed package","user":{"login":"gartung","id":4292184,"avatar_url":"https://avatars.githubusercontent.com/u/4292184?v=3","gravatar_id":"","url":"https://api.github.com/users/gartung","html_url":"https://github.com/gartung","followers_url":"https://api.github.com/users/gartung/followers","following_url":"https://api.github.com/users/gartung/following{/other_user}","gists_url":"https://api.github.com/users/gartung/gists{/gist_id}","starred_url":"https://api.github.com/users/gartung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gartung/subscriptions","organizations_url":"https://api.github.com/users/gartung/orgs","repos_url":"https://api.github.com/users/gartung/repos","events_url":"https://api.github.com/users/gartung/events{/privacy}","received_events_url":"https://api.github.com/users/gartung/received_events","type":"User","site_admin":false},"body":"This extends #445 which allows the creation of binary tarballs from installed packages and the installation of those tarballs on other machine with the appropriate rewriting of rpaths with patchelf on linux or install_name_tool on macos.","created_at":"2016-06-01T14:28:05Z","updated_at":"2016-08-11T08:42:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1af59030adbf7890ec9311fe9717de83206fdf6f","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/LLNL/spack/pulls/1013/commits","review_comments_url":"https://api.github.com/repos/LLNL/spack/pulls/1013/comments","review_comment_url":"https://api.github.com/repos/LLNL/spack/pulls/comments{/number}","comments_url":"https://api.github.com/repos/LLNL/spack/issues/1013/comments","statuses_url":"https://api.github.com/repos/LLNL/spack/statuses/9ce486301c4ffcd017cc264e0ab3e1eac39ea04d","head":{"label":"gartung:binary_packages","ref":"binary_packages","sha":"9ce486301c4ffcd017cc264e0ab3e1eac39ea04d","user":{"login":"gartung","id":4292184,"avatar_url":"https://avatars.githubusercontent.com/u/4292184?v=3","gravatar_id":"","url":"https://api.github.com/users/gartung","html_url":"https://github.com/gartung","followers_url":"https://api.github.com/users/gartung/followers","following_url":"https://api.github.com/users/gartung/following{/other_user}","gists_url":"https://api.github.com/users/gartung/gists{/gist_id}","starred_url":"https://api.github.com/users/gartung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gartung/subscriptions","organizations_url":"https://api.github.com/users/gartung/orgs","repos_url":"https://api.github.com/users/gartung/repos","events_url":"https://api.github.com/users/gartung/events{/privacy}","received_events_url":"https://api.github.com/users/gartung/received_events","type":"User","site_admin":false},"repo":{"id":48127611,"name":"spack","full_name":"gartung/spack","owner":{"login":"gartung","id":4292184,"avatar_url":"https://avatars.githubusercontent.com/u/4292184?v=3","gravatar_id":"","url":"https://api.github.com/users/gartung","html_url":"https://github.com/gartung","followers_url":"https://api.github.com/users/gartung/followers","following_url":"https://api.github.com/users/gartung/following{/other_user}","gists_url":"https://api.github.com/users/gartung/gists{/gist_id}","starred_url":"https://api.github.com/users/gartung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gartung/subscriptions","organizations_url":"https://api.github.com/users/gartung/orgs","repos_url":"https://api.github.com/users/gartung/repos","events_url":"https://api.github.com/users/gartung/events{/privacy}","received_events_url":"https://api.github.com/users/gartung/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/gartung/spack","description":"A flexible package manager designed to support multiple versions, configurations, platforms, and compilers.","fork":true,"url":"https://api.github.com/repos/gartung/spack","forks_url":"https://api.github.com/repos/gartung/spack/forks","keys_url":"https://api.github.com/repos/gartung/spack/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gartung/spack/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gartung/spack/teams","hooks_url":"https://api.github.com/repos/gartung/spack/hooks","issue_events_url":"https://api.github.com/repos/gartung/spack/issues/events{/number}","events_url":"https://api.github.com/repos/gartung/spack/events","assignees_url":"https://api.github.com/repos/gartung/spack/assignees{/user}","branches_url":"https://api.github.com/repos/gartung/spack/branches{/branch}","tags_url":"https://api.github.com/repos/gartung/spack/tags","blobs_url":"https://api.github.com/repos/gartung/spack/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gartung/spack/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gartung/spack/git/refs{/sha}","trees_url":"https://api.github.com/repos/gartung/spack/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gartung/spack/statuses/{sha}","languages_url":"https://api.github.com/repos/gartung/spack/languages","stargazers_url":"https://api.github.com/repos/gartung/spack/stargazers","contributors_url":"https://api.github.com/repos/gartung/spack/contributors","subscribers_url":"https://api.github.com/repos/gartung/spack/subscribers","subscription_url":"https://api.github.com/repos/gartung/spack/subscription","commits_url":"https://api.github.com/repos/gartung/spack/commits{/sha}","git_commits_url":"https://api.github.com/repos/gartung/spack/git/commits{/sha}","comments_url":"https://api.github.com/repos/gartung/spack/comments{/number}","issue_comment_url":"https://api.github.com/repos/gartung/spack/issues/comments{/number}","contents_url":"https://api.github.com/repos/gartung/spack/contents/{+path}","compare_url":"https://api.github.com/repos/gartung/spack/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gartung/spack/merges","archive_url":"https://api.github.com/repos/gartung/spack/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gartung/spack/downloads","issues_url":"https://api.github.com/repos/gartung/spack/issues{/number}","pulls_url":"https://api.github.com/repos/gartung/spack/pulls{/number}","milestones_url":"https://api.github.com/repos/gartung/spack/milestones{/number}","notifications_url":"https://api.github.com/repos/gartung/spack/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gartung/spack/labels{/name}","releases_url":"https://api.github.com/repos/gartung/spack/releases{/id}","deployments_url":"https://api.github.com/repos/gartung/spack/deployments","created_at":"2015-12-16T18:25:55Z","updated_at":"2016-02-11T16:11:43Z","pushed_at":"2016-08-09T21:26:40Z","git_url":"git://github.com/gartung/spack.git","ssh_url":"git@github.com:gartung/spack.git","clone_url":"https://github.com/gartung/spack.git","svn_url":"https://github.com/gartung/spack","homepage":"http://scalability-llnl.github.io/spack","size":13713,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"llnl-develop"}},"base":{"label":"LLNL:develop","ref":"develop","sha":"d380d1642722c44837cb32712972f19b70476ecb","user":{"login":"LLNL","id":5921419,"avatar_url":"https://avatars.githubusercontent.com/u/5921419?v=3","gravatar_id":"","url":"https://api.github.com/users/LLNL","html_url":"https://github.com/LLNL","followers_url":"https://api.github.com/users/LLNL/followers","following_url":"https://api.github.com/users/LLNL/following{/other_user}","gists_url":"https://api.github.com/users/LLNL/gists{/gist_id}","starred_url":"https://api.github.com/users/LLNL/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LLNL/subscriptions","organizations_url":"https://api.github.com/users/LLNL/orgs","repos_url":"https://api.github.com/users/LLNL/repos","events_url":"https://api.github.com/users/LLNL/events{/privacy}","received_events_url":"https://api.github.com/users/LLNL/received_events","type":"Organization","site_admin":false},"repo":{"id":15730865,"name":"spack","full_name":"LLNL/spack","owner":{"login":"LLNL","id":5921419,"avatar_url":"https://avatars.githubusercontent.com/u/5921419?v=3","gravatar_id":"","url":"https://api.github.com/users/LLNL","html_url":"https://github.com/LLNL","followers_url":"https://api.github.com/users/LLNL/followers","following_url":"https://api.github.com/users/LLNL/following{/other_user}","gists_url":"https://api.github.com/users/LLNL/gists{/gist_id}","starred_url":"https://api.github.com/users/LLNL/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LLNL/subscriptions","organizations_url":"https://api.github.com/users/LLNL/orgs","repos_url":"https://api.github.com/users/LLNL/repos","events_url":"https://api.github.com/users/LLNL/events{/privacy}","received_events_url":"https://api.github.com/users/LLNL/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/LLNL/spack","description":"A flexible package manager designed to support multiple versions, configurations, platforms, and compilers.","fork":false,"url":"https://api.github.com/repos/LLNL/spack","forks_url":"https://api.github.com/repos/LLNL/spack/forks","keys_url":"https://api.github.com/repos/LLNL/spack/keys{/key_id}","collaborators_url":"https://api.github.com/repos/LLNL/spack/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/LLNL/spack/teams","hooks_url":"https://api.github.com/repos/LLNL/spack/hooks","issue_events_url":"https://api.github.com/repos/LLNL/spack/issues/events{/number}","events_url":"https://api.github.com/repos/LLNL/spack/events","assignees_url":"https://api.github.com/repos/LLNL/spack/assignees{/user}","branches_url":"https://api.github.com/repos/LLNL/spack/branches{/branch}","tags_url":"https://api.github.com/repos/LLNL/spack/tags","blobs_url":"https://api.github.com/repos/LLNL/spack/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/LLNL/spack/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/LLNL/spack/git/refs{/sha}","trees_url":"https://api.github.com/repos/LLNL/spack/git/trees{/sha}","statuses_url":"https://api.github.com/repos/LLNL/spack/statuses/{sha}","languages_url":"https://api.github.com/repos/LLNL/spack/languages","stargazers_url":"https://api.github.com/repos/LLNL/spack/stargazers","contributors_url":"https://api.github.com/repos/LLNL/spack/contributors","subscribers_url":"https://api.github.com/repos/LLNL/spack/subscribers","subscription_url":"https://api.github.com/repos/LLNL/spack/subscription","commits_url":"https://api.github.com/repos/LLNL/spack/commits{/sha}","git_commits_url":"https://api.github.com/repos/LLNL/spack/git/commits{/sha}","comments_url":"https://api.github.com/repos/LLNL/spack/comments{/number}","issue_comment_url":"https://api.github.com/repos/LLNL/spack/issues/comments{/number}","contents_url":"https://api.github.com/repos/LLNL/spack/contents/{+path}","compare_url":"https://api.github.com/repos/LLNL/spack/compare/{base}...{head}","merges_url":"https://api.github.com/repos/LLNL/spack/merges","archive_url":"https://api.github.com/repos/LLNL/spack/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/LLNL/spack/downloads","issues_url":"https://api.github.com/repos/LLNL/spack/issues{/number}","pulls_url":"https://api.github.com/repos/LLNL/spack/pulls{/number}","milestones_url":"https://api.github.com/repos/LLNL/spack/milestones{/number}","notifications_url":"https://api.github.com/repos/LLNL/spack/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/LLNL/spack/labels{/name}","releases_url":"https://api.github.com/repos/LLNL/spack/releases{/id}","deployments_url":"https://api.github.com/repos/LLNL/spack/deployments","created_at":"2014-01-08T09:22:12Z","updated_at":"2016-08-04T22:30:45Z","pushed_at":"2016-08-11T07:08:34Z","git_url":"git://github.com/LLNL/spack.git","ssh_url":"git@github.com:LLNL/spack.git","clone_url":"https://github.com/LLNL/spack.git","svn_url":"https://github.com/LLNL/spack","homepage":"http://software.llnl.gov/spack","size":17813,"stargazers_count":142,"watchers_count":142,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":127,"mirror_url":null,"open_issues_count":245,"forks":127,"open_issues":245,"watchers":142,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/LLNL/spack/pulls/1013"},"html":{"href":"https://github.com/LLNL/spack/pull/1013"},"issue":{"href":"https://api.github.com/repos/LLNL/spack/issues/1013"},"comments":{"href":"https://api.github.com/repos/LLNL/spack/issues/1013/comments"},"review_comments":{"href":"https://api.github.com/repos/LLNL/spack/pulls/1013/comments"},"review_comment":{"href":"https://api.github.com/repos/LLNL/spack/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/LLNL/spack/pulls/1013/commits"},"statuses":{"href":"https://api.github.com/repos/LLNL/spack/statuses/9ce486301c4ffcd017cc264e0ab3e1eac39ea04d"}}}}
{"actor":{"display_login":"tgamblin"}}