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

add this_file_dir before '..' and 'lib' in the wrapper library path for xz #73

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions build-support/bin/xz/linux/x86_64/5.2.4-3/build-xz.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/bin/bash

source "$(git rev-parse --show-toplevel)/utils.v1.bash"

set_strict_mode

XZ_WRAPPER_SCRIPT="$(get_existing_absolute_path ./xz.py)"

function wrap_xz_lib_path_then_package {
mv bin/xz{,-real}

cp "$XZ_WRAPPER_SCRIPT" bin/xz

chmod +x bin/xz

create_gz_package 'xz'
}

function package_xz {
local -r installed_dir_abs="$1"

with_pushd "$installed_dir_abs" \
wrap_xz_lib_path_then_package
}

function fetch_extract_xz_source_release {
local -r archive_dirname="xz-${XZ_VERSION}"
local -r archive_filename="${archive_dirname}.tar.gz"
local -r release_url="https://tukaani.org/xz/${archive_filename}"

local -r downloaded_archive="$(curl_file_with_fail "$release_url" "$archive_filename")"
extract_for "$downloaded_archive" "$archive_dirname"
}

function build_xz {
local -r install_dir_abs="$1"

# --disable-rpath is necessary to make the xz package work "out of the box" -- otherwise at
# runtime it searches for a path in the filesystem of the VM that created it!
./configure \
--disable-rpath \
--prefix="$install_dir_abs"

make "-j${MAKE_JOBS}"

make install
}

function fetch_build_xz {
local -r install_dir_abs="$(mkdirp_absolute_path 'xz-install')"

local -r xz_src_extracted_abs="$(fetch_extract_xz_source_release)"

with_pushd >&2 "$xz_src_extracted_abs" \
build_xz "$install_dir_abs"

package_xz "$install_dir_abs"
}

readonly TARGET_PLATFORM="$1" XZ_VERSION="$2"

readonly MAKE_JOBS="${MAKE_JOBS:-2}"

case "$TARGET_PLATFORM" in
osx)
with_pushd "$(mkdirp_absolute_path "xz-${XZ_VERSION}-osx")" \
fetch_build_xz
;;
linux)
with_pushd "$(mkdirp_absolute_path "xz-${XZ_VERSION}-linux")" \
fetch_build_xz
;;
*)
die "xz does not support building for '${TARGET_PLATFORM}'"
;;
esac
5 changes: 5 additions & 0 deletions build-support/bin/xz/linux/x86_64/5.2.4-3/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

readonly result="$(./build-xz.sh linux 5.2.4)"

cp "$result" ./xz.tar.gz
37 changes: 37 additions & 0 deletions build-support/bin/xz/linux/x86_64/5.2.4-3/xz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python

from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

import os
import subprocess
import sys

argv = sys.argv

this_file_dir = os.path.dirname(__file__)

xz_executable = os.path.realpath(os.path.join(this_file_dir, 'xz-real'))

xz_lib_dir = os.path.realpath(os.path.join(this_file_dir, '..', 'lib'))

platform = os.uname()[0]

if platform == 'Darwin':
env_var = 'DYLD_LIBRARY_PATH'
elif platform == 'Linux':
env_var = 'LD_LIBRARY_PATH'
else:
raise ValueError('Unrecognized platform: {}.'.format(platform))

prev_lib_path = os.environ.get(env_var, '')
lib_path_entries = [s for s in prev_lib_path.split(':') if s != '']
lib_path_ours_first = [xz_lib_dir] + lib_path_entries

new_env = os.environ.copy()

new_env[env_var] = ':'.join(lib_path_ours_first)

# Inherit the standard fds, close any extra we may have opened.
rc = subprocess.call(sys.argv, executable=xz_executable, env=new_env, close_fds=True)
sys.exit(rc)
76 changes: 76 additions & 0 deletions build-support/bin/xz/mac/10.13/5.2.4-3/build-xz.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/bin/bash

source "$(git rev-parse --show-toplevel)/utils.v1.bash"

set_strict_mode

XZ_WRAPPER_SCRIPT="$(get_existing_absolute_path ./xz.py)"

function wrap_xz_lib_path_then_package {
mv bin/xz{,-real}

cp "$XZ_WRAPPER_SCRIPT" bin/xz

chmod +x bin/xz

create_gz_package 'xz'
}

function package_xz {
local -r installed_dir_abs="$1"

with_pushd "$installed_dir_abs" \
wrap_xz_lib_path_then_package
}

function fetch_extract_xz_source_release {
local -r archive_dirname="xz-${XZ_VERSION}"
local -r archive_filename="${archive_dirname}.tar.gz"
local -r release_url="https://tukaani.org/xz/${archive_filename}"

local -r downloaded_archive="$(curl_file_with_fail "$release_url" "$archive_filename")"
extract_for "$downloaded_archive" "$archive_dirname"
}

function build_xz {
local -r install_dir_abs="$1"

# --disable-rpath is necessary to make the xz package work "out of the box" -- otherwise at
# runtime it searches for a path in the filesystem of the VM that created it!
./configure \
--disable-rpath \
--prefix="$install_dir_abs"

make "-j${MAKE_JOBS}"

make install
}

function fetch_build_xz {
local -r install_dir_abs="$(mkdirp_absolute_path 'xz-install')"

local -r xz_src_extracted_abs="$(fetch_extract_xz_source_release)"

with_pushd >&2 "$xz_src_extracted_abs" \
build_xz "$install_dir_abs"

package_xz "$install_dir_abs"
}

readonly TARGET_PLATFORM="$1" XZ_VERSION="$2"

readonly MAKE_JOBS="${MAKE_JOBS:-2}"

case "$TARGET_PLATFORM" in
osx)
with_pushd "$(mkdirp_absolute_path "xz-${XZ_VERSION}-osx")" \
fetch_build_xz
;;
linux)
with_pushd "$(mkdirp_absolute_path "xz-${XZ_VERSION}-linux")" \
fetch_build_xz
;;
*)
die "xz does not support building for '${TARGET_PLATFORM}'"
;;
esac
5 changes: 5 additions & 0 deletions build-support/bin/xz/mac/10.13/5.2.4-3/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

readonly result="$(./build-xz.sh linux 5.2.4)"

cp "$result" ./xz.tar.gz
37 changes: 37 additions & 0 deletions build-support/bin/xz/mac/10.13/5.2.4-3/xz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python

from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

import os
import subprocess
import sys

argv = sys.argv

this_file_dir = os.path.dirname(__file__)

xz_executable = os.path.realpath(os.path.join(this_file_dir, 'xz-real'))

xz_lib_dir = os.path.realpath(os.path.join(this_file_dir, '..', 'lib'))

platform = os.uname()[0]

if platform == 'Darwin':
env_var = 'DYLD_LIBRARY_PATH'
elif platform == 'Linux':
env_var = 'LD_LIBRARY_PATH'
else:
raise ValueError('Unrecognized platform: {}.'.format(platform))

prev_lib_path = os.environ.get(env_var, '')
lib_path_entries = [s for s in prev_lib_path.split(':') if s != '']
lib_path_ours_first = [xz_lib_dir] + lib_path_entries

new_env = os.environ.copy()

new_env[env_var] = ':'.join(lib_path_ours_first)

# Inherit the standard fds, close any extra we may have opened.
rc = subprocess.call(sys.argv, executable=xz_executable, env=new_env, close_fds=True)
sys.exit(rc)