Skip to content

Fix shell script compatibility with macOS #17

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

Merged
merged 3 commits into from
May 1, 2019
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
20 changes: 14 additions & 6 deletions build-src.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@
#
# commit-db.rb list-valid nightly|GIT_DIR=/your/rust/dir/.git ./build-src.sh

if [ $(uname) == 'Darwin' ]; then
alias tac='tail -r'
fi

prompt_changes() {
local MAIN_GIT_DIR="$GIT_DIR"
local GIT_DIR=./.git CORE_IO_COMMIT=$IO_COMMIT
git init > /dev/null
git add .
git commit -m "rust src import" > /dev/null
export CORE_IO_COMMIT

bold_arrow; echo 'No patch found for' $IO_COMMIT
bold_arrow; echo 'Nearby commit(s) with patches:'
echo
GIT_DIR="$MAIN_GIT_DIR" git_commits_ordered '%H %cd' $(get_patch_commits) $IO_COMMIT | \
grep --color=always -1 $IO_COMMIT | sed /$IO_COMMIT/'s/$/ <=== your commit/'
echo
bold_arrow; echo -e "Try applying one of those using: \e[1;36mtry_patch COMMIT\e[0m"
bold_arrow; echo -e "Remember to test your changes with: \e[1;36mcargo build\e[0m"
bold_arrow; echo -e "Make your changes now (\e[1;36mctrl-D\e[0m when finished)"
bold_arrow; echo -e "Try applying one of those using: \033[1;36mtry_patch COMMIT\033[0m"
bold_arrow; echo -e "Remember to test your changes with: \033[1;36mcargo build\033[0m"
bold_arrow; echo -e "Make your changes now (\033[1;36mctrl-D\033[0m when finished)"
bash_diff_loop "No changes were made"
bold_arrow; echo "Saving changes as $IO_COMMIT.patch"
git clean -f -x
Expand Down Expand Up @@ -52,7 +56,7 @@ find src -mindepth 1 -type d -prune -exec rm -rf {} \;
for IO_COMMIT in $OLD_COMMITS $(git_commits_ordered %H $NEW_COMMITS|tac); do
if ! [ -d src/$IO_COMMIT ]; then
prepare_version

if [ -f patches/$IO_COMMIT.patch ]; then
bold_arrow; echo "Patching $IO_COMMIT"
patch -s -p1 -d src/$IO_COMMIT < patches/$IO_COMMIT.patch
Expand All @@ -64,7 +68,11 @@ for IO_COMMIT in $OLD_COMMITS $(git_commits_ordered %H $NEW_COMMITS|tac); do
fi
done

OLD_GIT_PERM=$(stat --printf=%a .git)
if [ $(uname) == 'Darwin' ]; then
OLD_GIT_PERM=$(stat -f %Op .git)
else
OLD_GIT_PERM=$(stat --printf=%a .git)
fi
trap "chmod $OLD_GIT_PERM .git; exit 1" SIGINT
chmod 000 .git
cargo ${1:-package}
Expand Down
6 changes: 3 additions & 3 deletions edit-patches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

prompt_changes() {
bold_arrow; echo "Editing $IO_COMMIT"
bold_arrow; echo -e "Remember to test your changes with: \e[1;36mcargo build\e[0m"
bold_arrow; echo -e "Remember to test your changes with: \033[1;36mcargo build\033[0m"

local MAIN_GIT_DIR="$GIT_DIR"
local GIT_DIR=./.git CORE_IO_COMMIT=$IO_COMMIT
Expand All @@ -18,9 +18,9 @@ prompt_changes() {
patch -s -p1 < $PATCH_DIR/$IO_COMMIT.patch
git commit -a -m "existing patch for $IO_COMMIT" > /dev/null

bold_arrow; echo -e "Applying patch from \e[1;36m$TMP_PATCH\e[0m"
bold_arrow; echo -e "Applying patch from \033[1;36m$TMP_PATCH\033[0m"
patch -p1 < $TMP_PATCH || true
bold_arrow; echo -e "Make your changes now (\e[1;36mctrl-D\e[0m when finished)"
bold_arrow; echo -e "Make your changes now (\033[1;36mctrl-D\033[0m when finished)"
bash_diff_loop "No changes were made"
bold_arrow; echo "Replacing $IO_COMMIT.patch with updated version"
git diff > $TMP_PATCH
Expand Down
4 changes: 2 additions & 2 deletions functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ get_io_commits() {
}

get_patch_commits() {
find $PATCH_DIR -type f -printf %f\\n|cut -d. -f1
find $PATCH_DIR -type f -print0|xargs -0 -n 1 basename|cut -d. -f1
}

prepare_version() {
Expand All @@ -54,7 +54,7 @@ prepare_version() {
}

bold_arrow() {
echo -ne '\e[1;36m==> \e[0m'
echo -ne '\033[1;36m==> \033[0m'
}

custom_bashrc() {
Expand Down