1
1
mirror of https://github.com/rsms/inter.git synced 2024-12-24 08:02:04 +03:00

Adds docker toolchain for a simpler build setup

This commit is contained in:
Rasmus Andersson 2019-01-05 16:20:22 -08:00
parent c6c99df958
commit 4ded41f4a3
8 changed files with 210 additions and 61 deletions

1
.gitignore vendored
View File

@ -18,6 +18,7 @@ build
/docs/lab/_serve*
/docs/lab/fonts
/docs/_site
/githash.txt
src/FontInspector.html
src/svg

View File

@ -34,18 +34,48 @@ If these rules are not followed, generated styles will fail to build.
## Compiling font files
There are two ways by which you can generate font files (OTF, TTF, WOFF2, etc) from the sources files:
There are three ways to generate font files (OTF, TTF, WOFF2, etc) from the sources files:
- Using Inter UI's own build system: `dockermake` and locally (see ["Using the toolchain"](#using-the-toolchain))
- Using the "export" feature in font editors like [Glyphs](https://glyphsapp.com/) or [RoboFont](http://robofont.com/)
- Using Inter UI's own build system (which requires no external tools.)
Exporting from font editors is a great alternative if you just want to test things out, but using Inter UI's own build system is the way to go for "production quality" font files. The rest of this section covers how to use Inter UI's own build system, aka _the toolchain_.
### Using the toolchain
Currently the toolchain has only been tested on macOS, and all you need is [Python](https://www.python.org/), which comes pre-installed with macOS, so no need to install anything. Python can easily be installed in Windows, Linux and other OSes.
The Inter UI toolchain is a collection of programs setup to build everything
in a high-quality and reliable way. It can be fully automated and requires no
paid software.
You'll want to open a Terminal for this.
TL;DR: to make & test everything:
```
./dockermake -j test
```
There are two ways of using the toolchain:
- `dockermake` — a [prebuild Docker image](https://cloud.docker.com/u/rsms/repository/docker/rsms/inter-ui-build) containing the complete toolchain is used. This is the easiest and quickest way to build Inter UI. Supports any platform that can run Docker, like Windows, macOS and Linux.
- locally — setup the toolchain locally using `init.sh` and then build using make. Only supports macOS and Linux.
#### Using dockermake
`dockermake` is simply `make` running in a docker image with the complete toolchain preinstalled.
Simply edit source files and run `dockermake [make-arg ...]`
Example:
```
$ ./dockermake -j Regular SemiBoldItalic
misc/fontbuild instancegen src/Inter-UI.designspace SemiBoldItalic
...
```
#### Local toolchain
Currently the toolchain has only been tested on macOS and Linux. All you need to have preinstalled is [Python 3](https://www.python.org/downloads/).
The first step is to initialize the toolchain itself:
@ -60,7 +90,7 @@ This will fetch, setup and configure everything needed to build and test Inter U
We can now run `make` to build all font files:
```
$ make -j
$ make -j Regular SemiBoldItalic
```
This may take a long time (a few minutes) the first time as it generates "font instances" (i.e. all styles that are derived through interpolation from the master styles) in addition to compiling the actual font files (OTF, TTF, etc.)

View File

@ -55,7 +55,14 @@ all_var: \
$(FONTDIR)/var/Inter-UI-upright.var.ttf \
$(FONTDIR)/var/Inter-UI-italic.var.ttf
# Disabled. See https://github.com/rsms/inter/issues/75
all_ufo_masters = $(Thin_ufo_d) \
$(ThinItalic_ufo_d) \
$(Regular_ufo_d) \
$(Italic_ufo_d) \
$(Black_ufo_d) \
$(BlackItalic_ufo_d)
# Hinted variable font disabled. See https://github.com/rsms/inter/issues/75
# all_var_hinted: $(FONTDIR)/var-hinted/Inter-UI.var.ttf $(FONTDIR)/var-hinted/Inter-UI.var.woff2
# .PHONY: all_var_hinted
@ -79,43 +86,13 @@ build/%.woff: build/%.ttf
# make sure intermediate TTFs are not gc'd by make
.PRECIOUS: build/%.ttf
# TTF -> EOT (disabled)
# build/%.eot: build/%.ttf
# ttf2eot "$<" > "$@"
# Master UFO -> OTF, TTF
all_ufo_masters = $(Thin_ufo_d) \
$(ThinItalic_ufo_d) \
$(Regular_ufo_d) \
$(Italic_ufo_d) \
$(Black_ufo_d) \
$(BlackItalic_ufo_d)
# Master UFOs -> variable TTF
$(FONTDIR)/var/%.var.ttf: src/%.designspace $(all_ufo_masters)
misc/fontbuild compile-var -o $@ $<
$(FONTDIR)/const/Inter-UI-Thin.%: src/Inter-UI.designspace $(Thin_ufo_d)
misc/fontbuild compile -o $@ src/Inter-UI-Thin.ufo
$(FONTDIR)/const/Inter-UI-ThinItalic.%: src/Inter-UI.designspace $(ThinItalic_ufo_d)
misc/fontbuild compile -o $@ src/Inter-UI-ThinItalic.ufo
$(FONTDIR)/const/Inter-UI-Regular.%: src/Inter-UI.designspace $(Regular_ufo_d)
misc/fontbuild compile -o $@ src/Inter-UI-Regular.ufo
$(FONTDIR)/const/Inter-UI-Italic.%: src/Inter-UI.designspace $(Italic_ufo_d)
misc/fontbuild compile -o $@ src/Inter-UI-Italic.ufo
$(FONTDIR)/const/Inter-UI-Black.%: src/Inter-UI.designspace $(Black_ufo_d)
misc/fontbuild compile -o $@ src/Inter-UI-Black.ufo
$(FONTDIR)/const/Inter-UI-BlackItalic.%: src/Inter-UI.designspace $(BlackItalic_ufo_d)
misc/fontbuild compile -o $@ src/Inter-UI-BlackItalic.ufo
# Instance UFO -> OTF, TTF
# Instance UFO -> OTF, TTF (note: masters' rules in generated.make)
$(FONTDIR)/const/Inter-UI-%.otf: build/ufo/Inter-UI-%.ufo
misc/fontbuild compile -o $@ $<
@ -154,6 +131,8 @@ $(FONTDIR)/const-hinted/%.ttf: $(FONTDIR)/const/%.ttf
mkdir -p "$(dir $@)"
ttfautohint --fallback-stem-width=256 --no-info "$<" "$@"
# python -m ttfautohint --fallback-stem-width=256 --no-info "$<" "$@"
# $(FONTDIR)/var-hinted/%.ttf: $(FONTDIR)/var/%.ttf
# mkdir -p "$(dir $@)"
# ttfautohint --fallback-stem-width=256 --no-info "$<" "$@"
@ -200,13 +179,6 @@ $(FONTDIR)/samples:
# load version, used by zip and dist
VERSION := $(shell cat version.txt)
# distribution zip files
ZIP_FILE_DIST := build/release/Inter-UI-${VERSION}.zip
ZIP_FILE_DEV := build/release/Inter-UI-${VERSION}-$(shell git rev-parse --short=10 HEAD).zip
ZD = build/tmp/zip
# intermediate zip target that creates a zip file at build/tmp/a.zip
build/tmp/a.zip:
@ -246,6 +218,12 @@ build/tmp/a.zip:
cd "$(ZD)" && zip -q -X -r "../../../$@" * && cd ../..
@rm -rf "$(ZD)"
# load version, used by zip and dist
VERSION := $(shell cat version.txt)
# distribution zip files
ZIP_FILE_DIST := build/release/Inter-UI-${VERSION}.zip
# zip
build/release/Inter-UI-%.zip: build/tmp/a.zip
@mkdir -p "$(shell dirname "$@")"
@ -255,7 +233,7 @@ build/release/Inter-UI-%.zip: build/tmp/a.zip
zip: all
$(MAKE) check
$(MAKE) ${ZIP_FILE_DEV}
$(MAKE) build/release/Inter-UI-${VERSION}-$(shell git rev-parse --short=10 HEAD).zip
zip_dist: pre_dist all
$(MAKE) check

11
dockermake Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash -e
#
# Runs make in a prebuilt docker image.
# All you need to have installed is docker for this to work.
# This is an alternative to building locally.
#
cd "$(dirname "$0")"
if [[ -d .git ]]; then
git rev-parse --short HEAD > githash.txt
fi
docker run --rm -it -v "$PWD:/host" rsms/inter-ui-build:latest make "$@"

66
init.sh
View File

@ -22,7 +22,7 @@ if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
pushd "$SRCDIR" >/dev/null
SRCDIR_ABS=$(pwd)
popd >/dev/null
export PYTHONPATH=$SRCDIR_ABS/misc/pylib
export PYTHONPATH=$SRCDIR_ABS/misc/tools
fi
else
# Subshell
@ -41,6 +41,15 @@ else
clean=true
fi
platform=osx
UNAME=$(uname)
if [[ "$UNAME" == *"inux"* ]]; then
platform=linux
elif [[ "$UNAME" != *"arwin"* ]]; then
echo "Unsupported platform $UNAME (only macOS and Linux are supported)" >&2
exit 1
fi
# ——————————————————————————————————————————————————————————————————
# virtualenv
@ -194,6 +203,7 @@ else
rm -rf "$DEPS_DIR/woff2"
exit 1
fi
LINK=true
elif [[ ! -f "$VENV_DIR/bin/woff2_compress" ]]; then
LINK=true
fi
@ -265,7 +275,7 @@ else
if [[ ! -f "$OTS_DIR/ots-sanitize" ]]; then
mkdir -p "$OTS_DIR"
fetch \
https://github.com/khaledhosny/ots/releases/download/v${OTS_VERSION}/ots-${OTS_VERSION}-osx.zip \
https://github.com/khaledhosny/ots/releases/download/v${OTS_VERSION}/ots-${OTS_VERSION}-${platform}.zip \
"$OTS_DIR/ots.zip"
pushd "$OTS_DIR" >/dev/null
unzip ots.zip
@ -288,20 +298,40 @@ else
AUTOHINT_VERSION=1.8.2
AUTOHINT_SRC_VERSION=1.8.2.8
LINK=false
if [[ ! -f "$DEPS_DIR/ttfautohint-${AUTOHINT_VERSION}" ]]; then
fetch \
https://download.savannah.gnu.org/releases/freetype/ttfautohint-${AUTOHINT_VERSION}-tty-osx.tar.gz
"$DEPS_DIR/ttfautohint.tar.gz"
tar -C "$DEPS_DIR" -xzf "$DEPS_DIR/ttfautohint.tar.gz"
rm "$DEPS_DIR/ttfautohint.tar.gz"
mv -f "$DEPS_DIR/ttfautohint" "$DEPS_DIR/ttfautohint-${AUTOHINT_VERSION}"
if [[ "$platform" == "osx" ]]; then
fetch \
https://download.savannah.gnu.org/releases/freetype/ttfautohint-${AUTOHINT_VERSION}-tty-osx.tar.gz \
"$DEPS_DIR/ttfautohint.tar.gz"
tar -C "$DEPS_DIR" -xzf "$DEPS_DIR/ttfautohint.tar.gz"
rm "$DEPS_DIR/ttfautohint.tar.gz"
mv -f "$DEPS_DIR/ttfautohint" "$DEPS_DIR/ttfautohint-${AUTOHINT_VERSION}"
else
fetch \
https://github.com/source-foundry/ttfautohint-build/archive/v${AUTOHINT_SRC_VERSION}.tar.gz \
"$DEPS_DIR/ttfautohint-build.tar.gz"
pushd "$DEPS_DIR" >/dev/null
tar -xzf ttfautohint-build.tar.gz
rm ttfautohint-build.tar.gz
rm -rf ttfautohint-build
mv -f ttfautohint*/ ./ttfautohint-build
pushd ttfautohint-build >/dev/null
./ttfautohint-build.sh
popd >/dev/null
mv -f \
/root/ttfautohint-build/ttfautohint*/frontend/ttfautohint \
"ttfautohint-${AUTOHINT_VERSION}"
rm -rf /root/ttfautohint-build ttfautohint-build
popd >/dev/null
fi
LINK=true
elif [[ ! -f "$VENV_DIR/bin/ttfautohint" ]]; then
LINK=true
fi
if $LINK; then
ln -vfs ../../deps/ttfautohint-1.8.2 "$VENV_DIR/bin/ttfautohint"
ln -vfs ../../deps/ttfautohint-${AUTOHINT_VERSION} "$VENV_DIR/bin/ttfautohint"
fi
if [[ ! -f "$VENV_DIR/bin/ttf2woff" ]] || [[ ! -f "$SRCDIR/misc/ttf2woff/ttf2woff" ]]; then
@ -378,8 +408,20 @@ else
echo -n " src/Inter-UI-${style}.ufo/*.plist" >> "$GEN_MAKE_FILE"
echo -n " src/Inter-UI-${style}.ufo/*.fea" >> "$GEN_MAKE_FILE"
echo -n " src/Inter-UI-${style}.ufo/glyphs/*.plist" >> "$GEN_MAKE_FILE"
echo -n " src/Inter-UI-${style}.ufo/glyphs/*.glif" >> "$GEN_MAKE_FILE"
echo ")" >> "$GEN_MAKE_FILE"
# echo -n " src/Inter-UI-${style}.ufo/glyphs/*.glif" >> "$GEN_MAKE_FILE"
echo -n ")" >> "$GEN_MAKE_FILE"
echo " src/Inter-UI.designspace" >> "$GEN_MAKE_FILE"
done
echo "" >> "$GEN_MAKE_FILE"
# master OTF and TTF rules
for style in "${master_styles[@]}"; do
echo "${DIST_DIR_TOK}const/Inter-UI-${style}.otf: \$(${style}_ufo_d)" >> "$GEN_MAKE_FILE"
echo -e "\tmisc/fontbuild compile -o \$@ src/Inter-UI-${style}.ufo" >> "$GEN_MAKE_FILE"
echo "${DIST_DIR_TOK}const/Inter-UI-${style}.ttf: \$(${style}_ufo_d)" >> "$GEN_MAKE_FILE"
echo -e "\tmisc/fontbuild compile -o \$@ src/Inter-UI-${style}.ufo" >> "$GEN_MAKE_FILE"
echo "" >> "$GEN_MAKE_FILE"
done
# generate all_ufo: <master_ufos>
@ -388,8 +430,6 @@ else
# echo -n " \$(${style}_ufo_d)" >> "$GEN_MAKE_FILE"
# done
# echo "" >> "$GEN_MAKE_FILE"
echo "" >> "$GEN_MAKE_FILE"
# add derived styles to style array
for e in "${derived_styles[@]}"; do

37
misc/docker/Dockerfile Normal file
View File

@ -0,0 +1,37 @@
FROM python:3.7-stretch
RUN apt-get -qq update \
&& apt-get install -y -qq --no-install-recommends \
git curl unzip build-essential ca-certificates ttfautohint \
&& pip install virtualenv
RUN mkdir /inter
WORKDIR /inter
COPY . /inter/
RUN rm Dockerfile
RUN ln -s /host/src src \
&& ln -s /host/version.txt . \
&& ln -s /host/githash.txt . \
&& ln -s /host/Makefile . \
&& ./init.sh \
&& rm -rf build/fonts \
&& mkdir -p /host/build/fonts \
&& ln -s /host/build/fonts build/fonts
RUN rm init.sh && ln -s /host/init.sh . \
&& echo "source /inter/init.sh" >> "$HOME/.bashrc" \
&& echo "alias l='ls -lAF'" >> "$HOME/.bashrc" \
&& echo 'export PS1="\[\e[33;1m\]\u@\w\[\e[0m\]\\\$ "' >> "$HOME/.bashrc"
# cleanup
RUN apt-get -y autoremove \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
ENV PATH=/inter/build/venv/bin:$PATH
VOLUME /host
CMD "/bin/bash"

48
misc/docker/build.sh Executable file
View File

@ -0,0 +1,48 @@
#!/bin/bash -e
#
# Builds the docker image
#
cd "$(dirname "$0")"
DOCKER_DIR=$(pwd)
cd ../..
ROOT_DIR=$(pwd)
IMAGE_NAME=rsms/inter-ui-build
BUILD_DIR=$ROOT_DIR/build/docker
# setup build dir
mkdir -p "$BUILD_DIR/misc/tools"
# copy files to build dir
echo "Syncing build dir"
cp -a \
init.sh \
requirements.txt \
"$DOCKER_DIR/Dockerfile" \
"$BUILD_DIR/" &
rsync -v -acC --delete --filter="- *.pyc" --filter="- /*/" \
"misc/tools/" \
"$BUILD_DIR/misc/tools/" &
rsync -v -acC --delete \
misc/fontbuild \
misc/fonttools-3.34.2-psCharStrings.patch \
misc/ttf2woff \
"$BUILD_DIR/misc/"
wait
# update githash.txt
git rev-parse --short HEAD > githash.txt
pushd "$BUILD_DIR" >/dev/null
# build the image
echo "Building image. This might take a while..."
# docker build -f Dockerfile -t $IMAGE_NAME --squash .
docker build -f Dockerfile -t $IMAGE_NAME .
echo "You can push the image to Docker hub:"
echo " docker push $IMAGE_NAME:latest"
echo ""
echo "Run interactively:"
echo " docker run --rm -it -v \"$ROOT_DIR:/host\" $IMAGE_NAME:latest"

View File

@ -43,11 +43,15 @@ def getGitHash():
try:
_gitHash = subprocess.check_output(
['git', '-C', BASEDIR, 'rev-parse', '--short', 'HEAD'],
shell=False,
stderr=subprocess.STDOUT,
**_enc_kwargs
).strip()
except:
pass
try:
# git rev-parse --short HEAD > githash.txt
_gitHash = readTextFile(pjoin(BASEDIR, 'githash.txt')).strip()
except:
pass
return _gitHash