-
Notifications
You must be signed in to change notification settings - Fork 193
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·104 lines (79 loc) · 3.08 KB
/
build.sh
File metadata and controls
executable file
·104 lines (79 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env bash
CLI_VERSION=1.0.0
if [ -z "$1" ]
then
echo "Argument should be path to local repo."
exit 1
fi
local_repo=$1
sudo apt-get update
# required to run the 'make install'
sudo apt-get install -y zlib1g-dev
# the ',,' makes environment variable lower case in Bash 4+
if [ "${MSSQL_CLI_OFFICIAL_BUILD,,}" != "true" ]
then
time_stamp=$(date +%y%m%d%H%M)
CLI_VERSION=$CLI_VERSION.dev$time_stamp
fi
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
debian_directory_creator=$script_dir/dir_creator.sh
# Install dependencies for the build
sudo apt-get install -y libssl-dev libffi-dev debhelper python-setuptools
# Download, Extract, Patch, Build CLI
tmp_pkg_dir=$(mktemp -d)
working_dir=$(mktemp -d)
cd $working_dir
source_dir=$local_repo
deb_file=$local_repo/../mssql-cli_$CLI_VERSION-${CLI_VERSION_REVISION:=1}_all.deb
# clean up old build output
rm -rf $source_dir/debian
rm -rf $source_dir/../debian_output
[ -d $local_repo/privates ] && cp $local_repo/privates/*.whl $tmp_pkg_dir
# Build Python from source and include
python_archive=$(mktemp)
wget https://www.python.org/ftp/python/3.8.7/Python-3.8.7.tgz -qO $python_archive
# A copy of Python is created for build dependencies only
python_dir=$(mktemp -d)
python_dir_build=$(mktemp -d)
tar -xvzf $python_archive -C $python_dir
tar -xvzf $python_archive -C $python_dir_build
echo "Python dir is $python_dir"
echo "Python build dir is $python_dir_build"
# clean any previous make files
make clean || echo "Nothing to clean"
$python_dir/*/configure --srcdir $python_dir/* --prefix $source_dir/python_env
make
make install
$python_dir_build/*/configure --srcdir $python_dir_build/* --prefix $source_dir/python_build
make
make install
# upgrade pip
$source_dir/python_env/bin/python3 -m pip install --upgrade pip
$source_dir/python_build/bin/python3 -m pip install --upgrade pip
# Download dependencies needed to run build stage
$source_dir/python_build/bin/python3 -m pip install -r $source_dir/requirements-dev.txt
# Set env var to ensure build.py uses the python we built from source.
export CUSTOM_PYTHON=$source_dir/python_build/bin/python3
export CUSTOM_PIP=$source_dir/python_build/bin/pip3
# Build mssql-cli wheel from source.
cd $source_dir
$source_dir/python_build/bin/python3 $source_dir/build.py build
cd -
# Remove python build version after build completes
rm -rf $source_dir/python_build
# Install mssql-cli wheel.
dist_dir=$source_dir/dist
# Ignore the dev latest wheel since build outputs two.
all_modules=`find $dist_dir -not -name "mssql_cli-dev-latest-py2.py3-none-manylinux1_x86_64.whl" -type f`
$source_dir/python_env/bin/pip3 install $all_modules
# Add the debian files.
mkdir $source_dir/debian
mkdir $source_dir/../debian_output
# Create temp dir for the debian/ directory used for CLI build.
cli_debian_dir_tmp=$(mktemp -d)
$debian_directory_creator $cli_debian_dir_tmp $source_dir $CLI_VERSION
cp -r $cli_debian_dir_tmp/* $source_dir/debian
cd $source_dir
dpkg-buildpackage -us -uc
cp $deb_file $source_dir/../debian_output
echo "The archive has also been outputted to $source_dir/../debian_output"