Skip to content

Commit 3978b0e

Browse files
ldenningtonLessley Dennington
authored andcommitted
build: split linux build.sh script
Split the current build.sh script into 3 scripts: build.sh, layout.sh, and pack.sh. This has the advantages of decoupling building and packaging and more-closely reflects the process we use for building/packaging macOS binaries.
1 parent 571683a commit 3978b0e

File tree

3 files changed

+292
-198
lines changed

3 files changed

+292
-198
lines changed

src/linux/Packaging.Linux/build.sh

Lines changed: 32 additions & 198 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,16 @@ die () {
44
exit 1
55
}
66

7-
make_absolute () {
8-
case "$1" in
9-
/*)
10-
echo "$1"
11-
;;
12-
*)
13-
echo "$PWD/$1"
14-
;;
15-
esac
16-
}
17-
18-
#####################################################################
19-
# Building
20-
#####################################################################
217
echo "Building Packaging.Linux..."
8+
9+
# Directories
10+
THISDIR="$( cd "$(dirname "$0")" ; pwd -P )"
11+
ROOT="$( cd "$THISDIR"/../../.. ; pwd -P )"
12+
SRC="$ROOT/src"
13+
OUT="$ROOT/out"
14+
INSTALLER_SRC="$SRC/linux/Packaging.Linux"
15+
INSTALLER_OUT="$OUT/linux/Packaging.Linux"
16+
2217
# Parse script arguments
2318
for i in "$@"
2419
do
@@ -32,7 +27,7 @@ case "$i" in
3227
shift # past argument=value
3328
;;
3429
--install-from-source=*)
35-
INSTALL_FROM_SOURCE=${i#*=}
30+
INSTALL_FROM_SOURCE="${i#*=}"
3631
shift # past argument=value
3732
;;
3833
*)
@@ -41,208 +36,47 @@ case "$i" in
4136
esac
4237
done
4338

44-
# Directories
45-
THISDIR="$( cd "$(dirname "$0")" ; pwd -P )"
46-
ROOT="$( cd "$THISDIR"/../../.. ; pwd -P )"
47-
SRC="$ROOT/src"
48-
OUT="$ROOT/out"
49-
GCM_SRC="$SRC/shared/Git-Credential-Manager"
50-
GCM_UI_SRC="$SRC/shared/Git-Credential-Manager.UI.Avalonia"
51-
BITBUCKET_UI_SRC="$SRC/shared/Atlassian.Bitbucket.UI.Avalonia"
52-
GITHUB_UI_SRC="$SRC/shared/GitHub.UI.Avalonia"
53-
GITLAB_UI_SRC="$SRC/shared/GitLab.UI.Avalonia"
54-
PROJ_OUT="$OUT/linux/Packaging.Linux"
55-
56-
# Build parameters
57-
FRAMEWORK=net6.0
58-
RUNTIME=linux-x64
59-
6039
# Perform pre-execution checks
6140
CONFIGURATION="${CONFIGURATION:=Debug}"
6241
if [ -z "$VERSION" ]; then
6342
die "--version was not set"
6443
fi
6544

66-
if [ $INSTALL_FROM_SOURCE = false ]; then
67-
ARCH="`dpkg-architecture -q DEB_HOST_ARCH`"
68-
if test -z "$ARCH"; then
69-
die "Could not determine host architecture!"
70-
fi
71-
fi
72-
73-
# Outputs
74-
PAYLOAD="$PROJ_OUT/payload/$CONFIGURATION"
75-
SYMBOLOUT="$PROJ_OUT/payload.sym/$CONFIGURATION"
76-
77-
if [ $INSTALL_FROM_SOURCE = false ]; then
78-
TAROUT="$PROJ_OUT/tar/$CONFIGURATION"
79-
TARBALL="$TAROUT/gcm-linux_$ARCH.$VERSION.tar.gz"
80-
SYMTARBALL="$TAROUT/gcm-linux_$ARCH.$VERSION-symbols.tar.gz"
45+
OUTDIR="$INSTALLER_OUT/$CONFIGURATION"
46+
PAYLOAD="$OUTDIR/payload"
8147

82-
DEBOUT="$PROJ_OUT/deb/$CONFIGURATION"
83-
DEBROOT="$DEBOUT/root"
84-
DEBPKG="$DEBOUT/gcm-linux_$ARCH.$VERSION.deb"
85-
else
48+
if [ $INSTALL_FROM_SOURCE = true ]; then
8649
INSTALL_LOCATION="/usr/local"
87-
fi
88-
89-
# Cleanup payload directory
90-
if [ -d "$PAYLOAD" ]; then
91-
echo "Cleaning existing payload directory '$PAYLOAD'..."
92-
rm -rf "$PAYLOAD"
93-
fi
94-
95-
# Cleanup symbol directory
96-
if [ -d "$SYMBOLOUT" ]; then
97-
echo "Cleaning existing symbols directory '$SYMBOLOUT'..."
98-
rm -rf "$SYMBOLOUT"
99-
fi
100-
101-
# Ensure directories exists
102-
mkdir -p "$PAYLOAD" "$SYMBOLOUT"
103-
104-
if [ $INSTALL_FROM_SOURCE = false ]; then
105-
mkdir -p "$DEBROOT"
106-
else
10750
mkdir -p "$INSTALL_LOCATION"
108-
fi
109-
110-
if [ -z "$DOTNET_ROOT" ]; then
111-
DOTNET_ROOT="$(dirname $(which dotnet))"
112-
fi
113-
114-
# Publish core application executables
115-
echo "Publishing core application..."
116-
$DOTNET_ROOT/dotnet publish "$GCM_SRC" \
117-
--configuration="$CONFIGURATION" \
118-
--framework="$FRAMEWORK" \
119-
--runtime="$RUNTIME" \
120-
--self-contained=true \
121-
-p:PublishSingleFile=true \
122-
--output="$(make_absolute "$PAYLOAD")" || exit 1
123-
124-
echo "Publishing core UI helper..."
125-
$DOTNET_ROOT/dotnet publish "$GCM_UI_SRC" \
126-
--configuration="$CONFIGURATION" \
127-
--framework="$FRAMEWORK" \
128-
--runtime="$RUNTIME" \
129-
--self-contained=true \
130-
-p:PublishSingleFile=true \
131-
--output="$(make_absolute "$PAYLOAD")" || exit 1
132-
133-
echo "Publishing Bitbucket UI helper..."
134-
$DOTNET_ROOT/dotnet publish "$BITBUCKET_UI_SRC" \
135-
--configuration="$CONFIGURATION" \
136-
--framework="$FRAMEWORK" \
137-
--runtime="$RUNTIME" \
138-
--self-contained=true \
139-
-p:PublishSingleFile=true \
140-
--output="$(make_absolute "$PAYLOAD")" || exit 1
141-
142-
echo "Publishing GitHub UI helper..."
143-
$DOTNET_ROOT/dotnet publish "$GITHUB_UI_SRC" \
144-
--configuration="$CONFIGURATION" \
145-
--framework="$FRAMEWORK" \
146-
--runtime="$RUNTIME" \
147-
--self-contained=true \
148-
-p:PublishSingleFile=true \
149-
--output="$(make_absolute "$PAYLOAD")" || exit 1
150-
151-
echo "Publishing GitLab UI helper..."
152-
$DOTNET_ROOT/dotnet publish "$GITLAB_UI_SRC" \
153-
--configuration="$CONFIGURATION" \
154-
--framework="$FRAMEWORK" \
155-
--runtime="$RUNTIME" \
156-
--self-contained=true \
157-
-p:PublishSingleFile=true \
158-
--output="$(make_absolute "$PAYLOAD")" || exit 1
159-
160-
# Collect symbols
161-
echo "Collecting managed symbols..."
162-
mv "$PAYLOAD"/*.pdb "$SYMBOLOUT" || exit 1
163-
164-
echo "Build complete."
165-
166-
#####################################################################
167-
# PACKING AND INSTALLING
168-
#####################################################################
169-
# Set full read, write, execute permissions for owner and just read and execute permissions for group and other
170-
echo "Setting file permissions..."
171-
/bin/chmod -R 755 "$PAYLOAD" || exit 1
17251

173-
if [ $INSTALL_FROM_SOURCE = false ]; then
174-
echo "Packing Packaging.Linux..."
175-
# Cleanup any old archive files
176-
if [ -e "$TAROUT" ]; then
177-
echo "Deleteing old archive '$TAROUT'..."
178-
rm "$TAROUT"
179-
fi
180-
181-
# Ensure the parent directory for the archive exists
182-
mkdir -p "$TAROUT" || exit 1
183-
184-
# Build binaries tarball
185-
echo "Building binaries tarball..."
186-
pushd "$PAYLOAD"
187-
tar -czvf "$TARBALL" * || exit 1
188-
popd
189-
190-
# Build symbols tarball
191-
echo "Building symbols tarball..."
192-
pushd "$SYMBOLOUT"
193-
tar -czvf "$SYMTARBALL" * || exit 1
194-
popd
195-
196-
# Build .deb
197-
INSTALL_TO="$DEBROOT/usr/local/share/gcm-core/"
198-
LINK_TO="$DEBROOT/usr/local/bin/"
199-
mkdir -p "$DEBROOT/DEBIAN" "$INSTALL_TO" "$LINK_TO" || exit 1
200-
201-
# make the debian control file
202-
# this is purposefully not indented, see
203-
# https://stackoverflow.com/questions/9349616/bash-eof-in-if-statement
204-
# for details
205-
cat >"$DEBROOT/DEBIAN/control" <<EOF
206-
Package: gcm
207-
Version: $VERSION
208-
Section: vcs
209-
Priority: optional
210-
Architecture: $ARCH
211-
Depends:
212-
Maintainer: GCM <[email protected]>
213-
Description: Cross Platform Git Credential Manager command line utility.
214-
GCM supports authentication with a number of Git hosting providers
215-
including GitHub, BitBucket, and Azure DevOps.
216-
For more information see https://aka.ms/gcm
217-
EOF
218-
else
21952
echo "Installing..."
22053

22154
# Install directories
22255
INSTALL_TO="$INSTALL_LOCATION/share/gcm-core/"
22356
LINK_TO="$INSTALL_LOCATION/bin/"
224-
MESSAGE="Install complete."
225-
fi
22657

227-
mkdir -p "$INSTALL_TO" "$LINK_TO"
58+
mkdir -p "$INSTALL_TO" "$LINK_TO"
22859

229-
# Copy all binaries and shared libraries to target installation location
230-
cp -R "$PAYLOAD"/* "$INSTALL_TO" || exit 1
60+
# Copy all binaries and shared libraries to target installation location
61+
cp -R "$PAYLOAD"/* "$INSTALL_TO" || exit 1
23162

232-
# Create symlink
233-
if [ ! -f "$LINK_TO/git-credential-manager" ]; then
234-
ln -s -r "$INSTALL_TO/git-credential-manager" \
235-
"$LINK_TO/git-credential-manager" || exit 1
236-
fi
63+
# Create symlink
64+
if [ ! -f "$LINK_TO/git-credential-manager" ]; then
65+
ln -s -r "$INSTALL_TO/git-credential-manager" \
66+
"$LINK_TO/git-credential-manager" || exit 1
67+
fi
23768

238-
# Create legacy symlink with older name
239-
if [ ! -f "$LINK_TO/git-credential-manager-core" ]; then
240-
ln -s -r "$INSTALL_TO/git-credential-manager" \
241-
"$LINK_TO/git-credential-manager-core" || exit 1
242-
fi
69+
# Create legacy symlink with older name
70+
if [ ! -f "$LINK_TO/git-credential-manager-core" ]; then
71+
ln -s -r "$INSTALL_TO/git-credential-manager" \
72+
"$LINK_TO/git-credential-manager-core" || exit 1
73+
fi
24374

244-
if [ $INSTALL_FROM_SOURCE = false ]; then
245-
dpkg-deb --build "$DEBROOT" "$DEBPKG" || exit 1
75+
echo "Install complete."
76+
else
77+
# Layout and pack
78+
"$INSTALLER_SRC/layout.sh" --configuration="$CONFIGURATION" --output="$PAYLOAD" --symbol-output="$" || exit 1
79+
"$INSTALLER_SRC/pack.sh" --configuration="$CONFIGURATION" --payload="$PAYLOAD" --version="$VERSION" || exit 1
24680
fi
24781

248-
echo $MESSAGE
82+
echo "Build of Packaging.Linux complete."

src/linux/Packaging.Linux/layout.sh

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#!/bin/bash
2+
die () {
3+
echo "$*" >&2
4+
exit 1
5+
}
6+
7+
make_absolute () {
8+
case "$1" in
9+
/*)
10+
echo "$1"
11+
;;
12+
*)
13+
echo "$PWD/$1"
14+
;;
15+
esac
16+
}
17+
18+
# Parse script arguments
19+
for i in "$@"
20+
do
21+
case "$i" in
22+
--configuration=*)
23+
CONFIGURATION="${i#*=}"
24+
shift # past argument=value
25+
;;
26+
*)
27+
# unknown option
28+
;;
29+
esac
30+
done
31+
32+
# Directories
33+
THISDIR="$( cd "$(dirname "$0")" ; pwd -P )"
34+
ROOT="$( cd "$THISDIR"/../../.. ; pwd -P )"
35+
SRC="$ROOT/src"
36+
OUT="$ROOT/out"
37+
GCM_SRC="$SRC/shared/Git-Credential-Manager"
38+
GCM_UI_SRC="$SRC/shared/Git-Credential-Manager.UI.Avalonia"
39+
BITBUCKET_UI_SRC="$SRC/shared/Atlassian.Bitbucket.UI.Avalonia"
40+
GITHUB_UI_SRC="$SRC/shared/GitHub.UI.Avalonia"
41+
GITLAB_UI_SRC="$SRC/shared/GitLab.UI.Avalonia"
42+
PROJ_OUT="$OUT/linux/Packaging.Linux"
43+
44+
# Build parameters
45+
FRAMEWORK=net6.0
46+
RUNTIME=linux-x64
47+
48+
# Perform pre-execution checks
49+
CONFIGURATION="${CONFIGURATION:=Debug}"
50+
51+
# Outputs
52+
PAYLOAD="$PROJ_OUT/$CONFIGURATION/payload"
53+
SYMBOLOUT="$PROJ_OUT/$CONFIGURATION/payload.sym"
54+
55+
# Cleanup payload directory
56+
if [ -d "$PAYLOAD" ]; then
57+
echo "Cleaning existing payload directory '$PAYLOAD'..."
58+
rm -rf "$PAYLOAD"
59+
fi
60+
61+
# Cleanup symbol directory
62+
if [ -d "$SYMBOLOUT" ]; then
63+
echo "Cleaning existing symbols directory '$SYMBOLOUT'..."
64+
rm -rf "$SYMBOLOUT"
65+
fi
66+
67+
# Ensure directories exists
68+
mkdir -p "$PAYLOAD" "$SYMBOLOUT"
69+
70+
if [ -z "$DOTNET_ROOT" ]; then
71+
DOTNET_ROOT="$(dirname $(which dotnet))"
72+
fi
73+
74+
# Publish core application executables
75+
echo "Publishing core application..."
76+
$DOTNET_ROOT/dotnet publish "$GCM_SRC" \
77+
--configuration="$CONFIGURATION" \
78+
--framework="$FRAMEWORK" \
79+
--runtime="$RUNTIME" \
80+
--self-contained \
81+
-p:PublishSingleFile=true \
82+
--output="$(make_absolute "$PAYLOAD")" || exit 1
83+
84+
echo "Publishing core UI helper..."
85+
$DOTNET_ROOT/dotnet publish "$GCM_UI_SRC" \
86+
--configuration="$CONFIGURATION" \
87+
--framework="$FRAMEWORK" \
88+
--runtime="$RUNTIME" \
89+
--self-contained \
90+
-p:PublishSingleFile=true \
91+
--output="$(make_absolute "$PAYLOAD")" || exit 1
92+
93+
echo "Publishing Bitbucket UI helper..."
94+
$DOTNET_ROOT/dotnet publish "$BITBUCKET_UI_SRC" \
95+
--configuration="$CONFIGURATION" \
96+
--framework="$FRAMEWORK" \
97+
--runtime="$RUNTIME" \
98+
--self-contained \
99+
-p:PublishSingleFile=true \
100+
--output="$(make_absolute "$PAYLOAD")" || exit 1
101+
102+
echo "Publishing GitHub UI helper..."
103+
$DOTNET_ROOT/dotnet publish "$GITHUB_UI_SRC" \
104+
--configuration="$CONFIGURATION" \
105+
--framework="$FRAMEWORK" \
106+
--runtime="$RUNTIME" \
107+
--self-contained \
108+
-p:PublishSingleFile=true \
109+
--output="$(make_absolute "$PAYLOAD")" || exit 1
110+
111+
echo "Publishing GitLab UI helper..."
112+
$DOTNET_ROOT/dotnet publish "$GITLAB_UI_SRC" \
113+
--configuration="$CONFIGURATION" \
114+
--framework="$FRAMEWORK" \
115+
--runtime="$RUNTIME" \
116+
--self-contained=true \
117+
-p:PublishSingleFile=true \
118+
--output="$(make_absolute "$PAYLOAD")" || exit 1
119+
120+
# Collect symbols
121+
echo "Collecting managed symbols..."
122+
mv "$PAYLOAD"/*.pdb "$SYMBOLOUT" || exit 1
123+
124+
echo "Build complete."

0 commit comments

Comments
 (0)