Makefile 10.4 KB
Newer Older
1 2 3
# Basic Makefile for contrib/docker. This can be expanded later as more targets
# are added.

4 5 6 7 8 9 10 11
# Default is to build with -j for parallel builds.  Turn off with
#   make PARELLEL=
PARALLEL=-j

# DIR is an internal variable that serves as an anchor to this cloned git
# repository.  DIR is mounted into the docker container, so that builds
# can occur within the container on this cloned git repository.  DIR should
# not be modified - if it is, then the build system will not work.
12
DIR = $(realpath ../..)
13 14 15 16 17 18 19 20 21 22

# DOCKUSER_HOME is the location of the home directory of the fabricated
# "dockuser" user, used only within the docker containers.  "dockuser" is
# created (from the passed-in RUN_UID) to map the docker-caller user's UID to a
# first-class user (/etc/passwd entry, member of sudo group, proper home dir)
# /home/dockuser is also used in other scripts, notably run_as_user.sh, so if
# changed it must be done in other areas for the builds to work.
DOCKUSER_HOME=/home/dockuser

# Use /home/dockuser/ngraph-cpp-test, because we run as the user (and not root)
23
# /root/ngraph-cpp-test is not used, because /root is not accessible to user
24
VOLUME = -v "${DIR}:${DOCKUSER_HOME}/ngraph-cpp-test"
25
GIT_COMMIT = $(shell git rev-parse HEAD)
26 27 28
DBUILD_VERSION = ${GIT_COMMIT}_${PYTHON_VERSION}
DBUILD_DIR = ${DIR}/contrib/docker/.build-${DBUILD_VERSION}

29 30 31 32 33
# Enable additional options to be added on the command line
ifndef CMAKE_OPTIONS_EXTRA
    CMAKE_OPTIONS_EXTRA = ""
endif

34 35
# For gcc builds, we do NOT regard warnings as errors
# For clang builds, we DO make warnings into errors
36 37 38
CMAKE_OPTIONS_COMMON=-DNGRAPH_BUILD_DOXYGEN_DOCS=ON -DNGRAPH_BUILD_SPHINX_DOCS=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo $(CMAKE_OPTIONS_EXTRA)
CMAKE_OPTIONS_GCC=$(CMAKE_OPTIONS_COMMON) -DNGRAPH_INSTALL_PREFIX=${DOCKUSER_HOME}/ngraph-cpp-test/BUILD-GCC/ngraph_dist -DNGRAPH_USE_PREBUILT_LLVM=TRUE
CMAKE_OPTIONS_CLANG=$(MAKE_OPTIONS_COMMON)-DNGRAPH_INSTALL_PREFIX=${DOCKUSER_HOME}/ngraph-cpp-test/BUILD-CLANG/ngraph_dist -DCMAKE_CXX_COMPILER=clang++-3.9 -DCMAKE_C_COMPILER=clang-3.9 -DNGRAPH_WARNINGS_AS_ERRORS=ON -DNGRAPH_USE_PREBUILT_LLVM=TRUE
39 40 41 42

CALLER_UID := $(shell id -u)
CALLER_GID := $(shell id -g)

43
# Default version is python 2, but can be switched to 3 from command
44 45 46
# line
PYTHON_VERSION = 2

47 48 49 50
# Some targets are DEPRECATED and will be removed at a later date: check_cpu build_ngraph_cpp_cpu
# These DEPRECATED targets are currently included for Jenkins job compatibility with older dev branches
# Please see comments for individual targets for more details
.PHONY: clean build_docker_image build_gcc check_gcc build_clang check_clang install_gcc install_clang shell check_cpu build_all build_ngraph_cpp_cpu
51 52 53 54 55

DOCKER_BUILD=docker build --rm=true

ifdef http_proxy
DOCKER_BUILD+=--build-arg http_proxy=$(http_proxy)
56
DOCKER_RUN_ENV+=--env "http_proxy=$(http_proxy)"
57 58
endif

59
ifdef https_proxy
60
DOCKER_BUILD+=--build-arg https_proxy=$(https_proxy)
61
DOCKER_RUN_ENV+=--env "https_proxy=$(https_proxy)"
62 63
endif

64 65 66 67
all: check_gcc check_clang

# Docker actions

68
expand_dockerfile_templates:
69
	cd "${DIR}"/contrib/docker
70 71
	mkdir "${DBUILD_DIR}" || true
	sed -e 's/\(FROM ngraph.*\)/\1:${DBUILD_VERSION}/' Dockerfile.ngraph_cpp > "${DBUILD_DIR}"/Dockerfile.build_ngraph_cpp
72

73 74
build_docker_image: expand_dockerfile_templates
	$(DOCKER_BUILD) -f="${DBUILD_DIR}"/Dockerfile.build_ngraph_cpp --build-arg python_version="${PYTHON_VERSION}" -t=build_ngraph_cpp:"${DBUILD_VERSION}" .
75
	# remove the tag for the previous latest image
76 77
	docker rmi build_ngraph_cpp:latest || echo "keep going if docker rmi command fails"
	docker tag `docker images -q "build_ngraph_cpp:${DBUILD_VERSION}"` build_ngraph_cpp:latest
78

79
build_docker: build_docker_image
80

L.S. Cook's avatar
L.S. Cook committed
81 82
# Build docs
docs: sphinx_doc doxygen_doc
83

L.S. Cook's avatar
L.S. Cook committed
84 85
doxygen_doc:
	# doxygen html docs build
86 87 88 89
	docker run --rm --tty \
            ${VOLUME} \
	    ${DOCKER_RUN_ENV} \
            --env RUN_UID="$(shell id -u)" \
L.S. Cook's avatar
L.S. Cook committed
90
            --env RUN_CMD="set -e ; set -o pipefail ; cd ${DOCKUSER_HOME}/ngraph-cpp-test/doc/doxygen; env VERBOSE=1 make html 2>&1 | tee make_sphinx_html.log" \
91 92 93
            "build_ngraph_cpp:${DBUILD_VERSION}" \
	    sh -c "${DOCKUSER_HOME}/ngraph-cpp-test/contrib/docker/run_as_user.sh"

L.S. Cook's avatar
L.S. Cook committed
94 95 96 97 98 99 100 101 102 103 104
sphinx_doc:
	# sphinx html docs build
	docker run --rm --tty \
            ${VOLUME} \
	    ${DOCKER_RUN_ENV} \
            --env RUN_UID="$(shell id -u)" \
            --env RUN_CMD="set -e ; set -o pipefail ; cd ${DOCKUSER_HOME}/ngraph-cpp-test/doc/sphinx; env VERBOSE=1 make html 2>&1 | tee make_sphinx_html.log" \
            "build_ngraph_cpp:${DBUILD_VERSION}" \
	    sh -c "${DOCKUSER_HOME}/ngraph-cpp-test/contrib/docker/run_as_user.sh"

# Build
105 106 107
build_all: build_gcc build_clang

build_gcc: build_docker_image
108
	# Remove old distribution directory if present
109 110 111 112
	( test -d "${DIR}"/BUILD-GCC/ngraph_dist && rm -fr "${DIR}"/BUILD-GCC/ngraph_dist && echo "Removed old ${DIR}/BUILD-GCC/ngraph_dist directory" ) || echo "Previous ngraph_dist directory not found"
	# Make BUILD-GCC directory as user
	mkdir -p "${DIR}"/BUILD-GCC
	chmod ug+rwx "${DIR}"/BUILD-GCC
113 114 115
	docker run --rm --tty \
            ${VOLUME} \
	    ${DOCKER_RUN_ENV} \
116
            --env GTEST_OUTPUT="xml:${DOCKUSER_HOME}/ngraph-cpp-test/BUILD-GCC/unit-test-results.xml" \
117
            --env RUN_UID="$(shell id -u)" \
118 119
            --env RUN_CMD="set -e ; set -o pipefail ; cd ${DOCKUSER_HOME}/ngraph-cpp-test/BUILD-GCC; cmake ${CMAKE_OPTIONS_GCC} .. 2>&1 | tee cmake_gcc.log ; env VERBOSE=1 make ${PARALLEL} 2>&1 | tee make_gcc.log" \
            "build_ngraph_cpp:${DBUILD_VERSION}" \
120
	    sh -c "${DOCKUSER_HOME}/ngraph-cpp-test/contrib/docker/run_as_user.sh"
121

122 123 124 125 126 127 128
build_clang:
	# Remove old distribution directory if present
	( test -d "${DIR}"/BUILD-CLANG/ngraph_dist && rm -fr "${DIR}"/BUILD-CLANG/ngraph_dist && echo "Removed old ${DIR}/BUILD-CLANG/ngraph_dist directory" ) || echo "Previous ngraph_dist directory not found"
	# Make BUILD-CLANG directory as user
	mkdir -p "${DIR}"/BUILD-CLANG
	chmod ug+rwx "${DIR}"/BUILD-CLANG
	docker run --rm --tty \
129 130
            ${VOLUME} \
	    ${DOCKER_RUN_ENV} \
131
            --env GTEST_OUTPUT="xml:${DOCKUSER_HOME}/ngraph-cpp-test/BUILD-CLANG/unit-test-results.xml" \
132
            --env RUN_UID="$(shell id -u)" \
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
            --env RUN_CMD="set -e ; set -o pipefail ; cd ${DOCKUSER_HOME}/ngraph-cpp-test/BUILD-CLANG; cmake ${CMAKE_OPTIONS_CLANG} .. 2>&1 | tee cmake_clang.log ; env VERBOSE=1 make ${PARALLEL} 2>&1 | tee make_clang.log" \
            "build_ngraph_cpp:${DBUILD_VERSION}" \
	    sh -c "${DOCKUSER_HOME}/ngraph-cpp-test/contrib/docker/run_as_user.sh"

# Check (run unit-tests)

check_all: check_gcc check_clang

check_gcc: build_gcc
	docker run --rm --tty \
            ${VOLUME} \
	    ${DOCKER_RUN_ENV} \
            --env GTEST_OUTPUT="xml:${DOCKUSER_HOME}/ngraph-cpp-test/BUILD-GCC/unit-test-results.xml" \
            --env RUN_UID="$(shell id -u)" \
            --env RUN_CMD="set -e ; set -o pipefail ; cd ${DOCKUSER_HOME}/ngraph-cpp-test/BUILD-GCC; env VERBOSE=1 make check 2>&1 | tee make_check_gcc.log ; sed -E -e 's/classname\=\"[a-zA-Z0-9_]+/&1_gcc/' unit-test-results.xml > unit-test-results-gcc.xml" \
            "build_ngraph_cpp:${DBUILD_VERSION}" \
	    sh -c "${DOCKUSER_HOME}/ngraph-cpp-test/contrib/docker/run_as_user.sh"
150

151
check_clang: build_clang
152 153 154
	docker run --rm --tty \
            ${VOLUME} \
	    ${DOCKER_RUN_ENV} \
155
            --env GTEST_OUTPUT="xml:${DOCKUSER_HOME}/ngraph-cpp-test/BUILD-CLANG/unit-test-results.xml" \
156
            --env RUN_UID="$(shell id -u)" \
157 158
            --env RUN_CMD="set -e ; set -o pipefail ; cd ${DOCKUSER_HOME}/ngraph-cpp-test/BUILD-CLANG; env VERBOSE=1 make check 2>&1 | tee make_check_clang.log ; sed -E -e 's/classname\=\"[a-zA-Z0-9_]+/&1_clang/' unit-test-results.xml > unit-test-results-clang.xml" \
            "build_ngraph_cpp:${DBUILD_VERSION}" \
159
	    sh -c "${DOCKUSER_HOME}/ngraph-cpp-test/contrib/docker/run_as_user.sh"
160

161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
# Install

install_all: install_gcc install_clang

install_gcc: check_gcc
	# Puts ngraph_dist in BUILD-GCC directory.  This is used by Jenkins ngraph-tensorflow batch job.
	docker run --rm --tty \
            ${VOLUME} \
	    ${DOCKER_RUN_ENV} \
            --env RUN_UID="$(shell id -u)" \
            --env RUN_CMD="set -e ; set -o pipefail; cd ${DOCKUSER_HOME}/ngraph-cpp-test/BUILD-GCC ; test -d ngraph_dist && rm -fr ngraph_dist && echo 'Removed old ngraph_dist directory' ; make install 2>&1 | tee make_install_gcc.log ; tar czf ngraph_dist_gcc.tgz ngraph_dist 2>&1 | tee make_tarball_gcc.log" \
            "build_ngraph_cpp:${DBUILD_VERSION}" \
	    sh -c "${DOCKUSER_HOME}/ngraph-cpp-test/contrib/docker/run_as_user.sh"

install_clang: check_clang
	# Puts ngraph_dist in BUILD-CLANG directory.  This is used by Jenkins ngraph-tensorflow batch job.
	docker run --rm --tty \
            ${VOLUME} \
	    ${DOCKER_RUN_ENV} \
            --env RUN_UID="$(shell id -u)" \
            --env RUN_CMD="set -e ; set -o pipefail; cd ${DOCKUSER_HOME}/ngraph-cpp-test/BUILD-CLANG ; test -d ngraph_dist && rm -fr ngraph_dist && echo 'Removed old ngraph_dist directory' ; make install 2>&1 | tee make_install_clang.log ; tar czf ngraph_dist_clang.tgz ngraph_dist 2>&1 | tee make_tarball_clang.log" \
            "build_ngraph_cpp:${DBUILD_VERSION}" \
	    sh -c "${DOCKUSER_HOME}/ngraph-cpp-test/contrib/docker/run_as_user.sh"

# Interactive shell

shell: build_docker_image
	# "make shell" runs an interactive shell in the docker image, for debugging
	docker run --rm --tty --interactive \
            ${VOLUME} \
	    ${DOCKER_RUN_ENV} \
            --env RUN_UID="$(shell id -u)" \
            "build_ngraph_cpp:${DBUILD_VERSION}" \
            sh -c "cd ${DOCKUSER_HOME} ; ${DOCKUSER_HOME}/ngraph-cpp-test/contrib/docker/run_as_user.sh"

# Clean

clean:
	rm -f "${DIR}"/contrib/docker/.build-*/Dockerfile.* || echo "keep going if files are not present"
	rmdir "${DIR}"/contrib/docker/.build-* || echo "keep going if directory is not present"
	rm -fr "${DIR}"/BUILD-GCC
	rm -fr "${DIR}"/BUILD-CLANG

#
# DEPRECATED TARGETS -- These WILL BE REMOVED in a future revision.
#                       They exist here to maintain compatibility in Jenkins
#                       jobs on older development branches.
#

check_cpu: check_all
	echo 'WARNING: "make check_cpu" is DEPRECATED and will be removed in a future revision'
	echo '         "make check_cpu" runs "make check_all" now, building with all compilers (gcc and clang)'

build_ngraph_cpp_cpu: build_docker_image
	echo 'WARNING: "make build_ngraph_cpp_cpu" is DEPRECATED and will be removed in a future revision'
	echo '         "make build_ngraph_cpp_cpu" runs "make build_docker_image" now'