aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-10-03 00:15:19 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-06 07:39:33 +0200
commit5b25b99e2eed7eaf82bf73b8e8021b314fc3cbdb (patch)
tree9b6b1635fec12fb366ce7cc9181376b29bc6703b
parent4b8214854b5d7aa7033d91438edc50a48598b774 (diff)
Fix runtime crash in bundled package
-rw-r--r--README.md3
-rwxr-xr-xscripts/package.py26
2 files changed, 15 insertions, 14 deletions
diff --git a/README.md b/README.md
index 13051ed..430ccfe 100644
--- a/README.md
+++ b/README.md
@@ -38,7 +38,8 @@ Ccache is currently required on non-windows platforms but it will later be remov
# Usage
After you have installed sibs, execute `sibs` without any arguments and you will get a list of commands and description for them.
# Package
-Sibs supports creating a redistributable packages of projects (currently only on Linux, recommended to use --bundle option). Packaging is in testing phase and may not work. Currently you need to have ldd and patchelf installed and also set the environment variable SIBS_SCRIPT_DIR to scripts sub directory which is in sibs root directory (the directory that contains package.py).
+Sibs supports creating a redistributable packages of projects (currently only on Linux, run `sibs package --bundle`). Packaging is in testing phase and may not work for all projects. Currently you need to have python3, ldd and patchelf installed and also set the environment variable SIBS_SCRIPT_DIR to scripts sub directory which is in sibs root directory (the directory that contains package.py).
+Currently a script file is generated which should be used to run the project. The name of the script file is the same as project. This script file will most likely to be removed later. Do NOT run the executable called "program".
# IDE support
Sibs generates a compile_commands.json in the project root directory when executing `sibs build` and tools that support clang completion can be used, such as YouCompleteMe.
There are several editors that support YouCompleteMe, including Vim, Emacs and Visual Studio Code. Visual studio code now also supports clang completion with C/C++ extension by Microsoft; the extension will ask you which compile_commands.json file you want to use and you can choose the compile_commands.json in the project root directory.
diff --git a/scripts/package.py b/scripts/package.py
index 47fc45d..a10cdcb 100755
--- a/scripts/package.py
+++ b/scripts/package.py
@@ -13,10 +13,10 @@ run_script_linux = """
set -e
-script_path=`realpath $0`
+script_path=`readlink -f $0`
script_dir=`dirname $script_path`
cd "$script_dir"
-"./$PROGRAM_NAME"
+"./$SO_LOADER" --library-path libs "./$PROGRAM_NAME" "$@"
"""
def get_executable_dynamic_libraries(filepath):
@@ -31,7 +31,7 @@ def get_executable_dynamic_libraries(filepath):
if len(s) >= 3 and b"=>" in s:
lib_path = " ".join(x.decode("UTF-8") for x in s[2:-1])
if os.path.exists(lib_path):
- libs.append(os.path.realpath(lib_path))
+ libs.append([os.path.realpath(lib_path), os.path.basename(lib_path)])
return libs
def make_executable(filepath):
@@ -46,20 +46,20 @@ def main():
os.makedirs(sys.argv[2], exist_ok=True)
libs = get_executable_dynamic_libraries(sys.argv[1])
- so_loader_pattern = re.compile("ld-[0-9.]+\\.so.*")
+ so_loader_pattern = re.compile("ld-linux-x86-64\\.so.*")
so_loader = None
for lib in libs:
- lib_filename = os.path.basename(lib)
- if so_loader_pattern.match(lib_filename):
+ if so_loader_pattern.match(lib[1]):
if so_loader != None:
print("Unexpected error: found multiple so loaders, unable to recover")
exit(2)
- so_loader = lib_filename
+ so_loader = lib[1]
if not so_loader:
print("Unexpected error: no so loader found, unable to recover")
exit(5)
+ so_loader = os.path.join("libs", so_loader)
executable_filename = os.path.basename(sys.argv[1])
new_executable_path = os.path.join(sys.argv[2], executable_filename)
shutil.copyfile(sys.argv[1], new_executable_path)
@@ -72,7 +72,7 @@ def main():
print("Failed to execute patchelf --set-interpreter on executable %s, error: %s" % (new_executable_path, stderr))
exit(3)
- process = subprocess.Popen(["patchelf", "--set-rpath", ".", new_executable_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ process = subprocess.Popen(["patchelf", "--set-rpath", "libs", new_executable_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout, stderr) = process.communicate()
if process.returncode != 0:
print("Failed to execute patchelf --set-rpath on executable %s, error: %s" % (new_executable_path, stderr))
@@ -80,19 +80,19 @@ def main():
run_script_path = os.path.join(sys.argv[2], "run.sh")
with open(run_script_path, "wb") as run_script:
- run_script.write(run_script_linux.replace("$PROGRAM_NAME", executable_filename).encode("UTF-8"))
+ run_script.write(run_script_linux.replace("$SO_LOADER", so_loader).replace("$PROGRAM_NAME", "program").encode("UTF-8"))
make_executable(run_script_path)
package_name = new_executable_path + ".tar.gz"
print("Creating archive %s" % os.path.basename(package_name))
with tarfile.open(package_name, "w:gz") as tar:
for lib in libs:
- print("Adding shared library %s to package" % lib)
- tar.add(lib, arcname=os.path.basename(lib))
+ print("Adding shared library %s to package" % lib[0])
+ tar.add(lib[0], arcname=os.path.join("libs", lib[1]))
print("Adding executable %s to package" % sys.argv[1])
- tar.add(new_executable_path, arcname=executable_filename)
+ tar.add(new_executable_path, arcname="program")
print("Adding run script %s to package" % run_script_path)
- tar.add(run_script_path, arcname="run.sh")
+ tar.add(run_script_path, arcname=executable_filename)
print("Removing temporary files")
os.remove(new_executable_path)