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 generation of XZ-compressed tarballs #57

Merged
merged 2 commits into from
Apr 27, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
addons:
apt:
packages:
- p7zip-full

script:
- ./test.sh
10 changes: 4 additions & 6 deletions combine-installers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,7 @@ need_ok "failed to generate install script"
mkdir -p "$CFG_OUTPUT_DIR"
need_ok "couldn't create output dir"

rm -Rf "$CFG_OUTPUT_DIR/$CFG_PACKAGE_NAME.tar.gz"
need_ok "couldn't delete old tarball"

# Make a tarball
tar -czf "$CFG_OUTPUT_DIR/$CFG_PACKAGE_NAME.tar.gz" -C "$CFG_WORK_DIR" "$CFG_PACKAGE_NAME"
need_ok "failed to tar"
"$src_dir/make-tarballs.sh" \
--work-dir="$CFG_WORK_DIR" \
--input="$CFG_PACKAGE_NAME" \
--output="$CFG_OUTPUT_DIR/$CFG_PACKAGE_NAME"
11 changes: 4 additions & 7 deletions gen-installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ abs_path() {
msg "looking for programs"
msg

need_cmd tar
need_cmd cp
need_cmd rm
need_cmd mkdir
Expand Down Expand Up @@ -339,9 +338,7 @@ need_ok "failed to generate install script"
mkdir -p "$CFG_OUTPUT_DIR"
need_ok "couldn't create output dir"

rm -Rf "$CFG_OUTPUT_DIR/$CFG_PACKAGE_NAME.tar.gz"
need_ok "couldn't delete old tarball"

# Make a tarball
tar -czf "$CFG_OUTPUT_DIR/$CFG_PACKAGE_NAME.tar.gz" -C "$CFG_WORK_DIR" "$CFG_PACKAGE_NAME"
need_ok "failed to tar"
"$src_dir/make-tarballs.sh" \
--work-dir="$CFG_WORK_DIR" \
--input="$CFG_PACKAGE_NAME" \
--output="$CFG_OUTPUT_DIR/$CFG_PACKAGE_NAME"
278 changes: 278 additions & 0 deletions make-tarballs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,278 @@
#!/bin/sh
# Copyright 2014 The Rust Project Developers. See the COPYRIGHT
# file at the top-level directory of this distribution and at
# http://rust-lang.org/COPYRIGHT.
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.

set -ue

msg() {
echo "make-tarballs: ${1-}"
}

step_msg() {
msg
msg "$1"
msg
}

warn() {
echo "make-tarballs: WARNING: $1" >&2
}

err() {
echo "make-tarballs: error: $1" >&2
exit 1
}

need_ok() {
if [ $? -ne 0 ]
then
err "$1"
fi
}

need_cmd() {
if command -v $1 >/dev/null 2>&1
then msg "found $1"
else err "need $1"
fi
}

putvar() {
local t
local tlen
eval t=\$$1
eval tlen=\${#$1}
if [ $tlen -gt 35 ]
then
printf "make-tarballs: %-20s := %.35s ...\n" $1 "$t"
else
printf "make-tarballs: %-20s := %s %s\n" $1 "$t"
fi
}

valopt() {
VAL_OPTIONS="$VAL_OPTIONS $1"

local op=$1
local default=$2
shift
shift
local doc="$*"
if [ $HELP -eq 0 ]
then
local uop=$(echo $op | tr '[:lower:]' '[:upper:]' | tr '\-' '\_')
local v="CFG_${uop}"
eval $v="$default"
for arg in $CFG_ARGS
do
if echo "$arg" | grep -q -- "--$op="
then
local val=$(echo "$arg" | cut -f2 -d=)
eval $v=$val
fi
done
putvar $v
else
if [ -z "$default" ]
then
default="<none>"
fi
op="${op}=[${default}]"
printf " --%-30s %s\n" "$op" "$doc"
fi
}

opt() {
BOOL_OPTIONS="$BOOL_OPTIONS $1"

local op=$1
local default=$2
shift
shift
local doc="$*"
local flag=""

if [ $default -eq 0 ]
then
flag="enable"
else
flag="disable"
doc="don't $doc"
fi

if [ $HELP -eq 0 ]
then
for arg in $CFG_ARGS
do
if [ "$arg" = "--${flag}-${op}" ]
then
op=$(echo $op | tr 'a-z-' 'A-Z_')
flag=$(echo $flag | tr 'a-z' 'A-Z')
local v="CFG_${flag}_${op}"
eval $v=1
putvar $v
fi
done
else
if [ ! -z "$META" ]
then
op="$op=<$META>"
fi
printf " --%-30s %s\n" "$flag-$op" "$doc"
fi
}

flag() {
BOOL_OPTIONS="$BOOL_OPTIONS $1"

local op=$1
shift
local doc="$*"

if [ $HELP -eq 0 ]
then
for arg in $CFG_ARGS
do
if [ "$arg" = "--${op}" ]
then
op=$(echo $op | tr 'a-z-' 'A-Z_')
local v="CFG_${op}"
eval $v=1
putvar $v
fi
done
else
if [ ! -z "$META" ]
then
op="$op=<$META>"
fi
printf " --%-30s %s\n" "$op" "$doc"
fi
}

validate_opt () {
for arg in $CFG_ARGS
do
local is_arg_valid=0
for option in $BOOL_OPTIONS
do
if test --disable-$option = $arg
then
is_arg_valid=1
fi
if test --enable-$option = $arg
then
is_arg_valid=1
fi
if test --$option = $arg
then
is_arg_valid=1
fi
done
for option in $VAL_OPTIONS
do
if echo "$arg" | grep -q -- "--$option="
then
is_arg_valid=1
fi
done
if [ "$arg" = "--help" ]
then
echo
echo "No more help available for Configure options,"
echo "check the Wiki or join our IRC channel"
break
else
if test $is_arg_valid -eq 0
then
err "Option '$arg' is not recognized"
fi
fi
done
}

# Prints the absolute path of a directory to stdout
abs_path() {
local path="$1"
# Unset CDPATH because it causes havok: it makes the destination unpredictable
# and triggers 'cd' to print the path to stdout. Route `cd`'s output to /dev/null
# for good measure.
(unset CDPATH && cd "$path" > /dev/null && pwd)
}

msg "looking for programs"
msg

need_cmd tar
need_cmd rm
need_cmd mkdir
need_cmd echo
need_cmd tr
need_cmd find
need_cmd rev
need_cmd sort
need_cmd gzip
need_cmd 7z

CFG_ARGS="$@"

HELP=0
if [ "$1" = "--help" ]
then
HELP=1
shift
echo
echo "Usage: $0 [options]"
echo
echo "Options:"
echo
else
step_msg "processing arguments"
fi

OPTIONS=""
BOOL_OPTIONS=""
VAL_OPTIONS=""

valopt input "package" "The input folder to be compressed"
valopt output "./dist" "The prefix of the tarballs"
valopt work-dir "./workdir" "The folder in which the input is to be found"

if [ $HELP -eq 1 ]
then
echo
exit 0
fi

step_msg "validating arguments"
validate_opt

rm -Rf "$CFG_OUTPUT.tar.gz"
need_ok "couldn't delete old gz tarball"

rm -Rf "$CFG_OUTPUT.tar.xz"
need_ok "couldn't delete old xz tarball"

# Make a tarball
cd "$CFG_WORK_DIR"

# Sort files by their suffix, to group files with the same name from
# different locations (likely identical) and files with the same
# extension (likely containing similar data).
find "$CFG_INPUT" \( -type d -empty \) -or \( -not -type d \) \
| rev | sort | rev | tar -cf "$CFG_OUTPUT.tar" -T -
need_ok "failed to tar"

# xz -9 -T2 --keep "$CFG_OUTPUT.tar"
7z a -bd -txz -mx=9 -mmt=off "$CFG_OUTPUT.tar.xz" "$CFG_OUTPUT.tar"
need_ok "failed to xz"

gzip "$CFG_OUTPUT.tar"
need_ok "failed to gzip"
1 change: 1 addition & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ tarball_with_package_name() {
--package-name=rustc-nightly
try "$WORK_DIR/rustc-nightly/install.sh" --prefix="$PREFIX_DIR"
try test -e "$OUT_DIR/rustc-nightly.tar.gz"
try test -e "$OUT_DIR/rustc-nightly.tar.xz"
}
runtest tarball_with_package_name

Expand Down