From a0fc9ae0eba075bad28435ea536ae1d11d91ae1a Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Thu, 12 Apr 2018 17:02:16 +0700 Subject: [PATCH] [samples] Allow using KONAN_DATA_DIR in samples --- samples/curl/build.gradle | 1 + samples/konan.sh | 2 +- samples/tensorflow/README.md | 3 ++- samples/tensorflow/build.gradle | 3 ++- samples/tensorflow/build.sh | 3 ++- samples/tensorflow/downloadTensorflow.sh | 3 ++- samples/tetris/build.bat | 3 ++- samples/tetris/build.gradle | 4 +++- samples/tetris/build.sh | 3 ++- samples/torch/README.md | 3 ++- samples/torch/build.gradle | 3 ++- samples/torch/build.sh | 2 +- samples/torch/downloadTorch.sh | 3 ++- samples/zephyr/build.bat | 4 ++-- 14 files changed, 26 insertions(+), 14 deletions(-) diff --git a/samples/curl/build.gradle b/samples/curl/build.gradle index be963eaa9a7..2788acf56a7 100644 --- a/samples/curl/build.gradle +++ b/samples/curl/build.gradle @@ -22,6 +22,7 @@ repositories { konanArtifacts { program('Curl') { + dependsOn ':libcurl:publish' dependencies { artifactCurl 'org.jetbrains.kotlin.native:libcurl:1.0' } diff --git a/samples/konan.sh b/samples/konan.sh index 2b71a177d17..c203df866f9 100644 --- a/samples/konan.sh +++ b/samples/konan.sh @@ -6,5 +6,5 @@ else PATH="$KONAN_HOME/bin:$PATH" fi -KONAN_USER_DIR="$HOME/.konan" +KONAN_USER_DIR=${KONAN_DATA_DIR:-"$HOME/.konan"} KONAN_DEPS="$KONAN_USER_DIR/dependencies" diff --git a/samples/tensorflow/README.md b/samples/tensorflow/README.md index 9f88b01a6a9..c3dc868f874 100644 --- a/samples/tensorflow/README.md +++ b/samples/tensorflow/README.md @@ -13,7 +13,8 @@ showing how a TensorFlow client in Kotlin/Native could look like. ./downloadTensorflow.sh will install [TensorFlow for C](https://www.tensorflow.org/versions/r1.1/install/install_c) into -`$HOME/.konan/third-party/tensorflow` (if not yet done). +`$HOME/.konan/third-party/tensorflow` (if not yet done). One may override the location of +`third-party/tensorflow` by setting the `KONAN_DATA_DIR` environment variable. To build use `../gradlew build` or `./build.sh`. diff --git a/samples/tensorflow/build.gradle b/samples/tensorflow/build.gradle index 7421ef4ae21..2fdcc006a38 100644 --- a/samples/tensorflow/build.gradle +++ b/samples/tensorflow/build.gradle @@ -2,7 +2,8 @@ apply plugin: 'konan' konan.targets = ['macbook', 'linux'] -def tensorflowHome = "${System.getProperty("user.home")}/.konan/third-party/tensorflow" +def konanUserDir = System.getenv("KONAN_DATA_DIR") ?: "${System.getProperty("user.home")}/.konan" +def tensorflowHome = "$konanUserDir/third-party/tensorflow" task downloadTensorflow(type: Exec) { workingDir getProjectDir() diff --git a/samples/tensorflow/build.sh b/samples/tensorflow/build.sh index 1b11a0d8d47..a6b7f27259f 100755 --- a/samples/tensorflow/build.sh +++ b/samples/tensorflow/build.sh @@ -6,7 +6,8 @@ source "$DIR/../konan.sh" $DIR/downloadTensorflow.sh -TF_TARGET_DIRECTORY="$HOME/.konan/third-party/tensorflow" +# KONAN_USER_DIR is set by konan.sh +TF_TARGET_DIRECTORY="$KONAN_USER_DIR/third-party/tensorflow" TF_TYPE="cpu" # Change to "gpu" for GPU support if [ x$TARGET == x ]; then diff --git a/samples/tensorflow/downloadTensorflow.sh b/samples/tensorflow/downloadTensorflow.sh index 096e66652a3..051d71d6a38 100755 --- a/samples/tensorflow/downloadTensorflow.sh +++ b/samples/tensorflow/downloadTensorflow.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash -TF_TARGET_DIRECTORY="$HOME/.konan/third-party/tensorflow" +KONAN_USER_DIR=${KONAN_DATA_DIR:-"$HOME/.konan"} +TF_TARGET_DIRECTORY="$KONAN_USER_DIR/third-party/tensorflow" TF_TYPE="cpu" # Change to "gpu" for GPU support if [ x$TARGET == x ]; then diff --git a/samples/tetris/build.bat b/samples/tetris/build.bat index 3687d276b0d..35aae3105e7 100644 --- a/samples/tetris/build.bat +++ b/samples/tetris/build.bat @@ -1,7 +1,8 @@ @echo off setlocal set DIR=. -set "PATH=..\..\dist\bin;..\..\bin;%HOME%\.konan\dependencies\msys2-mingw-w64-x86_64-gcc-7.2.0-clang-llvm-5.0.0-windows-x86-64\bin;%PATH%" +if "%KONAN_DATA_DIR%"=="" (set KONAN_DATA_DIR="%HOME%\.konan") +set "PATH=..\..\dist\bin;..\..\bin;%KONAN_DATA_DIR%\dependencies\msys2-mingw-w64-x86_64-gcc-7.2.0-clang-llvm-5.0.0-windows-x86-64\bin;%PATH%" if "%TARGET%" == "" set TARGET=mingw rem Requires default mingw64 install path yet. set MINGW=\msys64\mingw64 diff --git a/samples/tetris/build.gradle b/samples/tetris/build.gradle index 038ae6f3e90..720fa40b000 100644 --- a/samples/tetris/build.gradle +++ b/samples/tetris/build.gradle @@ -2,6 +2,8 @@ apply plugin: 'konan' konan.targets = ['macbook', 'linux', 'raspberrypi'] +def konanUserDir = System.getenv("KONAN_DATA_DIR") ?: "${System.getProperty("user.home")}/.konan" + konanArtifacts { interop ('sdl') { @@ -20,7 +22,7 @@ konanArtifacts { } target 'raspberrypi', { - includeDirs "${System.getProperty("user.home")}/.konan/dependencies/target-sysroot-1-raspberrypi/usr/include/SDL2" + includeDirs "$konanUserDir/dependencies/target-sysroot-1-raspberrypi/usr/include/SDL2" } } diff --git a/samples/tetris/build.sh b/samples/tetris/build.sh index d077446c711..e553956e8ab 100755 --- a/samples/tetris/build.sh +++ b/samples/tetris/build.sh @@ -4,7 +4,8 @@ DIR=$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd ) source "$DIR/../konan.sh" -DEPS="$HOME/.konan/dependencies" +# KONAN_DEPS is set in konan.sh +DEPS="$KONAN_DEPS" CFLAGS_macbook=-I$HOME/Library/Frameworks/SDL2.framework/Headers LINKER_ARGS_macbook="-F $HOME/Library/Frameworks -framework SDL2" diff --git a/samples/torch/README.md b/samples/torch/README.md index 7e465f69502..8a5419c10ab 100644 --- a/samples/torch/README.md +++ b/samples/torch/README.md @@ -23,7 +23,8 @@ Now ./downloadTorch.sh -will install it into `$HOME/.konan/third-party/torch` (if not yet done). +will install it into `$HOME/.konan/third-party/torch` (if not yet done). One may override the location of +`third-party/torch` by setting the `KONAN_DATA_DIR` environment variable. To build use `../gradlew build` or `./build.sh`. diff --git a/samples/torch/build.gradle b/samples/torch/build.gradle index 1c5b980bb6d..b4f37d58029 100644 --- a/samples/torch/build.gradle +++ b/samples/torch/build.gradle @@ -2,7 +2,8 @@ apply plugin: 'konan' konan.targets = ['macbook', 'linux'] -def torchHome = "${System.getProperty("user.home")}/.konan/third-party/torch" +def konanUserDir = System.getenv("KONAN_DATA_DIR") ?: "${System.getProperty("user.home")}/.konan" +def torchHome = "$konanUserDir/third-party/torch" task downloadTorch(type: Exec) { workingDir getProjectDir() diff --git a/samples/torch/build.sh b/samples/torch/build.sh index 917436eeb4d..7ddc42ce4c2 100755 --- a/samples/torch/build.sh +++ b/samples/torch/build.sh @@ -6,7 +6,7 @@ source "$DIR/../konan.sh" $DIR/downloadTorch.sh -TH_TARGET_DIRECTORY="$HOME/.konan/third-party/torch" +TH_TARGET_DIRECTORY="$KONAN_USER_DIR/third-party/torch" if [ x$TARGET == x ]; then case "$OSTYPE" in diff --git a/samples/torch/downloadTorch.sh b/samples/torch/downloadTorch.sh index b8ddee3fd93..268e6dc8c12 100755 --- a/samples/torch/downloadTorch.sh +++ b/samples/torch/downloadTorch.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash -TH_TARGET_DIRECTORY=~/.konan/third-party/torch +KONAN_USER_DIR=${KONAN_DATA_DIR:-"$HOME/.konan"} +TH_TARGET_DIRECTORY="$KONAN_USER_DIR/third-party/torch" NO_CUDA=true # set to false for GPU support if [ ! -d $TH_TARGET_DIRECTORY/include/THNN ]; then diff --git a/samples/zephyr/build.bat b/samples/zephyr/build.bat index bc47682a4b8..ae42543835c 100644 --- a/samples/zephyr/build.bat +++ b/samples/zephyr/build.bat @@ -6,8 +6,8 @@ set ZEPHYR_BASE=%userprofile%\zephyr set TOOLCHAIN=gcc-arm-none-eabi-7-2017-q4-major-win32 set DIR=%~dp0 -set KONAN_USER_DIR=%userprofile%/.konan -set KONAN_DEPS=%KONAN_USER_DIR%/dependencies +if "%KONAN_DATA_DIR%"=="" (set KONAN_DATA_DIR="%HOME%\.konan") +set KONAN_DEPS=%KONAN_DATA_DIR%/dependencies set GCC_ARM=%KONAN_DEPS%/%TOOLCHAIN% set ZEPHYR_TOOLCHAIN_VARIANT=gccarmemb set GCCARMEMB_TOOLCHAIN_PATH=%GCC_ARM%