Skip to content

Commit

Permalink
Add sepate build for precise-engine and precise-all
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewScholefield committed Apr 10, 2019
1 parent fbb594b commit 096c518
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 23 deletions.
64 changes: 47 additions & 17 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,56 @@
#!/usr/bin/env bash


tar_name() {
local tar_prefix=$1
echo "${tar_prefix}_$(precise-engine --version 2>&1)_$(uname -m).tar.gz"
}

replace() {
local pattern=$1
local replacement=$2
sed -e "s/$pattern/$replacement/gm"
}

package_scripts() {
local tar_prefix=$1
local combined_folder=$2
local scripts=$3
local train_libs=$4

rm -rf dist/

for script in $scripts; do
tmp_name=$(mktemp).spec
cat "precise.template.spec" | replace "%%SCRIPT%%" "$script" | replace "%%TRAIN_LIBS%%" "$train_libs" > "$tmp_name"
pyinstaller -y "$tmp_name"
done

local items=dist/*
for i in $items; do
mkdir -p "dist/$combined_folder"
if [ "$(readlink -f "$i")" != "$(readlink -f "dist/$combined_folder")" ]; then
cp -R $i/* "dist/$combined_folder"
fi
done

out_name=$(tar_name "$tar_prefix")
cd dist
tar czvf "$out_name" "$tar_prefix"
cd ..
mv "dist/$out_name" .
}

set -eE

./setup.sh
source .venv/bin/activate
pip install pyinstaller

rm -rf dist/

for script in listen train calc_threshold; do
tmp_name=$(mktemp).spec
cat "precise.template.spec" | sed -e 's/%%SCRIPT%%/'"$script"'/gm' > "$tmp_name"
pyinstaller -y "$tmp_name"
done

items=dist/*
for i in $items; do
mkdir -p dist/precise
cp -R $i/* dist/precise
done
all_scripts=$(grep -oP '(?<=precise.scripts.)[a-z_]+' setup.py)
package_scripts "precise-all" "precise" "$all_scripts" True
package_scripts "precise-engine" "precise-engine" "engine" False

out_name="precise_$(precise-engine --version 2>&1)_$(uname -m).tar.gz"
cd dist
tar czvf "$out_name" "precise"
echo "Wrote to dist/$out_name"
tar_1=$(tar_name precise-all)
tar_2=$(tar_name precise-engine)
echo "Wrote to $tar_1 and $tar_2"
22 changes: 16 additions & 6 deletions precise.template.spec
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@ from glob import iglob
from os.path import basename, dirname, abspath

script_name = '%%SCRIPT%%'
strip = False
train_libs = %%TRAIN_LIBS%%
strip = True
site_packages = '.venv/lib/python3.6/site-packages/'
print('PATH:', abspath('precise/scripts/{}.py'.format(script_name)))

if train_libs:
binaries = [
(abspath(i), dirname(i.replace(site_packages, '')))
for i in iglob(site_packages + "tensorflow/**/*.so", recursive=True)
]
else:
binaries = []

a = Analysis(
[abspath('precise/scripts/{}.py'.format(script_name))],
pathex=['.'],
binaries=[
(abspath(i), dirname(i.replace(site_packages, '')))
for i in iglob(site_packages + "tensorflow/**/*.so", recursive=True)
],
binaries=binaries,
datas=[],
hiddenimports=['prettyparse', 'speechpy'],
hookspath=[],
Expand All @@ -26,6 +31,11 @@ a = Analysis(
cipher=block_cipher
)

for i in range(len(a.binaries)):
dest, origin, kind = a.binaries[i]
if '_pywrap_tensorflow_internal' in dest:
a.binaries[i] = ('tensorflow.python.' + dest, origin, kind)

pyz = PYZ(
a.pure, a.zipped_data,
cipher=block_cipher
Expand Down

0 comments on commit 096c518

Please sign in to comment.