Skip to content

Commit

Permalink
Merge branch 'git-sdk'
Browse files Browse the repository at this point in the history
This enhances the `sdk` shell function we want to promote as the main
way to Do Things In The SDK by introducing the `cd` subcommand to
initialize and switch to a given project, by improving the help, by
adding the `git-extra` project to the known projects, and by adding
support for Tab completion (in the Git SDK Bash).

It also updates the SDK installer to initialize a shallow clone of the
Git mirror of the SDK instead of "Pacman'ing everything from scratch".

Signed-off-by: Johannes Schindelin <[email protected]>
  • Loading branch information
dscho committed Apr 11, 2018
2 parents e826d31 + d1a55d3 commit 0976d8e
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 241 deletions.
3 changes: 3 additions & 0 deletions git-extra/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ source=('inputrc'
'gitattributes'
'astextplain'
'git-sdk.sh'
'sdk.completion'
'git-update-git-for-windows'
'git-update'
'blocked-file-util.c'
Expand Down Expand Up @@ -96,6 +97,7 @@ build() {
package() {
builddir=build-${MINGW_CHOST}
install -d -m755 $pkgdir/etc/profile.d
install -d -m755 $pkgdir/usr/share/bash-completion/completions
install -d -m755 $pkgdir/etc/post-install
install -d -m755 $pkgdir/usr/bin
install -d -m755 $pkgdir/usr/share/git
Expand All @@ -118,6 +120,7 @@ package() {
install -m755 env.sh $pkgdir/etc/profile.d
install -m755 bash_profile.sh $pkgdir/etc/profile.d
install -m755 git-sdk.sh $pkgdir/etc/profile.d
install -m755 sdk.completion $pkgdir/usr/share/bash-completion/completions/sdk
install -m644 msys2-32.ico $pkgdir/usr/share/git
install -m644 99-post-install-cleanup.post $pkgdir/etc/post-install
install -m755 astextplain $pkgdir/usr/bin
Expand Down
57 changes: 41 additions & 16 deletions git-extra/git-sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ sdk () {
The 'sdk' shell function helps you to get up and running
with the Git for Windows SDK. The available subcommands are:
create-desktop-icon: install a desktop icon that starts the GfW SDK shell.
create-desktop-icon: install a desktop icon that starts the Git for
Windows SDK Bash.
init <repo>: initialize and/or update a development repo. Known repos
are: build-extra, git, MINGW-packages, MSYS2-packages.
cd <project>: initialize/update a worktree and cd into it. Known projects
are: git, git-extra, build-extra, MINGW-packages, MSYS2-packages.
build: builds one of the following: git, git-and-installer.
init <project>: initialize and/or update a worktree. Known projects
are the same as for the 'cd' command.
build <project>: builds one of the following: git, git-and-installer.
EOF
;;
welcome)
Expand Down Expand Up @@ -67,42 +71,62 @@ sdk () {
echo "$*" >&2
return 1
;;
# for completion
valid_commands)
echo "build cd create-desktop-icon init"
;;
valid_projects)
echo "build-extra git git-extra MINGW-packages MSYS2-packages"
;;
# here start the commands
init-lazy)
case "$2" in
build-extra|git|MINGW-packages|MSYS2-packages)
test -d /usr/src/"$2"/.git && return
mkdir -p /usr/src/"$2" &&
git -C /usr/src/"$2" init &&
git -C /usr/src/"$2" config core.autocrlf false &&
git -C /usr/src/"$2" remote add origin \
src_dir=/usr/src/"$2"
src_cdup_dir="$src_dir"
test -d "$src_dir"/.git && return
mkdir -p "$src_dir" &&
git -C "$src_dir" init &&
git -C "$src_dir" config core.autocrlf false &&
git -C "$src_dir" remote add origin \
https://github.com/git-for-windows/"$2" ||
sdk die "Could not initialize /usr/src/$2"
sdk die "Could not initialize $src_dir"
;;
git-extra)
sdk init-lazy build-extra &&
src_dir="$src_dir/$2" ||
return 1
;;
*)
sdk die "Unhandled repository: $2" >&2
;;
esac
;;
cd)
sdk init "$2" &&
cd "$src_dir" ||
sdk die "Could not change directory to '$2'"
;;
init)
sdk init-lazy "$2" &&
git -C "/usr/src/$2" pull origin master
git -C "$src_cdup_dir" pull origin master
;;
build)
case "$2" in
git)
sdk init git &&
make -C /usr/src/git -j$(nproc) DEVELOPER=1
make -C "$src_dir" -j$(nproc) DEVELOPER=1
;;
installer)
sdk init build-extra &&
/usr/src/build-extra/installer/release.sh "${3:-0-test}"
"$src_dir"/installer/release.sh "${3:-0-test}"
;;
git-and-installer)
sdk build git &&
make -C /usr/src/git strip install &&
make -C "$src_dir" strip install &&
pacman -Syyu git-extra &&
sdk init build-extra &&
/usr/src/build-extra/installer/release.sh "${3:-0-test}"
"$src_dir"/installer/release.sh "${3:-0-test}"
;;
*)
cat >&2 <<EOF
Expand All @@ -118,7 +142,8 @@ EOF
esac
;;
*)
sdk die "Usage: sdk ( build-git | init <repo> | create-desktop-icon | help )"
printf "Usage: sdk <command> [<argument>...]\n\n" >&2 &&
sdk help
;;
esac
}
Expand Down
23 changes: 23 additions & 0 deletions git-extra/sdk.completion
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
_sdk()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"

case "$prev" in
build|cd|init)
local projects=$(sdk valid_projects)
COMPREPLY=($(compgen -W "$projects" -- $cur))
return 0
;;
create-desktop-icon)
return 1
;;
esac

opts=$(sdk valid_commands)
COMPREPLY=($(compgen -W "$opts" -- $cur))
return 0
}
complete -F _sdk sdk
85 changes: 34 additions & 51 deletions sdk-installer/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Recreate git-sdk-$VERSION.exe

test -z "$1" && {
echo "Usage: $0 <version> [<gitbranch>]"
echo "Usage: $0 <version>"
exit 1
}

Expand All @@ -25,75 +25,58 @@ x86_64)
;;
esac

GIT_BRANCH="${2:-master}"
GIT_CLONE_URL=https://github.com/git-for-windows/git
GIT_SDK_URL=https://github.com/git-for-windows/git-sdk-$BITNESS

FAKEROOTDIR="$(cd "$(dirname "$0")" && pwd)/root"
TARGET="$HOME"/git-sdk-installer-"$1"-$BITNESS.7z.exe
OPTS7="-m0=lzma -mx=9 -md=64M"
TMPPACK=/tmp.7z
SCRIPT_PATH="$(cd "$(dirname "$0")" && pwd)"
BIN_DIR=/mingw$BITNESS/bin

mkdir -p "$FAKEROOTDIR/usr/bin" "$FAKEROOTDIR/etc" ||
die "Could not create fake root directory"
echo "Enumerating required files..." >&2
# First, enumerate the .dll files needed by the .exe files, then, enumerate all
# the .dll files in bin/, then filter out the duplicates (which are the .dll
# files in bin/ which are needed by the .exe files).
exes_and_dlls=
todo="git.exe ../libexec/git-core/git-remote-https.exe "
# Add DLLs' transitive dependencies
while test -n "$todo"
do
file=${todo%% *}
todo=${todo#* }
exes_and_dlls="$exes_and_dlls$file "

for dll in $(objdump -p "$BIN_DIR/$file" |
sed -n "s|^\tDLL Name: ||p")
do
case " $exes_and_dlls $todo " in
*" $dll "*) ;; # already found/queued
*) test ! -f "$BIN_DIR/$dll" || todo="$todo$dll ";;
esac
done
done

echo "Copying and compressing files..." >&2
rm -rf "$FAKEROOTDIR" &&
mkdir -p "$FAKEROOTDIR/mini$BIN_DIR" ||
die "Could not create $FAKEROOTDIR$BIN_DIR directory"

sed -e "s|@@ARCH@@|$ARCH|g" \
-e "s|@@BITNESS@@|$BITNESS|g" \
-e "s|@@GIT_BRANCH@@|$GIT_BRANCH|g" \
-e "s|@@GIT_CLONE_URL@@|$GIT_CLONE_URL|g" \
-e "s|@@GIT_SDK_URL@@|$GIT_SDK_URL|g" \
<"$SCRIPT_PATH"/setup-git-sdk.bat >"$FAKEROOTDIR"/setup-git-sdk.bat ||
die "Could not generate setup script"

cp /usr/bin/dash.exe "$FAKEROOTDIR/usr/bin/sh.exe" &&
sed -e 's/^#\(XferCommand.*curl\).*/\1 --anyauth -C - -L -f %u >%o/' \
</etc/pacman.conf >"$FAKEROOTDIR/etc/pacman.conf.proxy" ||
die "Could not copy extra files into fake root"

dlls_for_exes () {
# Add DLLs' transitive dependencies
dlls=
todo="$* "
while test -n "$todo"
do
path=${todo%% *}
todo=${todo#* }
case "$path" in ''|' ') continue;; esac
for dll in $(objdump -p "$path" |
sed -n 's/^\tDLL Name: msys-/usr\/bin\/msys-/p')
do
case "$dlls" in
*"$dll"*) ;; # already found
*) dlls="$dlls $dll"; todo="$todo /$dll ";;
esac
done
done
echo "$dlls"
}

fileList="etc/nsswitch.conf \
etc/pacman.conf \
etc/pacman.d \
usr/bin/pacman-key \
usr/bin/tput.exe \
usr/bin/pacman.exe \
usr/bin/curl.exe \
usr/bin/gpg.exe \
usr/bin/chmod.exe \
usr/bin/wc.exe \
usr/bin/find.exe \
$(dlls_for_exes /usr/bin/gpg.exe /usr/bin/curl.exe /usr/bin/chmod.exe \
/usr/bin/wc.exe /usr/bin/find.exe) \
usr/ssl/certs/ca-bundle.crt \
var/lib/pacman \
usr/share/pacman/keyrings \
$FAKEROOTDIR/setup-git-sdk.bat $FAKEROOTDIR/etc $FAKEROOTDIR/usr"
(cd $BIN_DIR && cp $exes_and_dlls "$FAKEROOTDIR/mini$BIN_DIR") ||
die "Could not copy .exe and .dll files into fake root"

type 7za ||
pacman -Sy --noconfirm p7zip ||
die "Could not install 7-Zip"

echo "Creating archive" &&
(cd / && 7za -x'!var/lib/pacman/*' a $OPTS7 "$TMPPACK" $fileList) &&
(cd "$FAKEROOTDIR" && 7za -x'!var/lib/pacman/*' a $OPTS7 "$TMPPACK" *) &&
(cat "$SCRIPT_PATH/../7-Zip/7zSD.sfx" &&
echo ';!@Install@!UTF-8!' &&
echo 'Title="Git for Windows '$BITNESS'-bit SDK"' &&
Expand Down
Loading

0 comments on commit 0976d8e

Please sign in to comment.