From d28f8ce7f20c6e984a8835c622e40ac0dbc51503 Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Fri, 12 May 2017 18:05:14 +0700 Subject: [PATCH] samples: Add scripts for samples building This pach adds a root gradle project in the samples directory which allows one to build all gradle samples using `./gradlew build` command. It also adds a shell script in the samples directory which can build all samples (excluding tensorflow one) using their build.sh scripts. --- samples/build.gradle | 24 +++++++++++++ samples/build.sh | 26 ++++++++++++++ samples/csvparser/build.gradle | 28 ++++++--------- samples/csvparser/gradle.properties | 1 - samples/gitchurn/build.gradle | 28 ++++++--------- samples/gitchurn/gradle.properties | 1 - samples/gitchurn/gradle.properties.for_bundle | 1 - samples/gradle.properties | 2 ++ .../gradle.properties.for_bundle | 0 samples/gtk/README.md | 3 ++ samples/gtk/build.gradle | 36 +++++++++++++++++++ samples/gtk/build.sh | 4 ++- samples/libcurl/build.gradle | 21 ++++------- samples/libcurl/gradle.properties | 1 - samples/libcurl/gradle.properties.for_bundle | 1 - samples/nonBlockingEchoServer/build.gradle | 20 ++++------- .../nonBlockingEchoServer/gradle.properties | 1 - .../gradle.properties.for_bundle | 1 - samples/opengl/build.gradle | 20 ++++------- samples/opengl/gradle.properties | 1 - samples/opengl/gradle.properties.for_bundle | 1 - samples/settings.gradle | 8 +++++ samples/socket/build.gradle | 20 ++++------- samples/socket/gradle.properties | 1 - samples/socket/gradle.properties.for_bundle | 1 - samples/tetris/build.gradle | 35 +++++++++--------- samples/tetris/gradle.properties | 1 - samples/tetris/gradle.properties.for_bundle | 1 - 28 files changed, 168 insertions(+), 120 deletions(-) create mode 100644 samples/build.gradle create mode 100755 samples/build.sh delete mode 100644 samples/csvparser/gradle.properties delete mode 100644 samples/gitchurn/gradle.properties delete mode 100644 samples/gitchurn/gradle.properties.for_bundle create mode 100644 samples/gradle.properties rename samples/{csvparser => }/gradle.properties.for_bundle (100%) create mode 100644 samples/gtk/build.gradle delete mode 100644 samples/libcurl/gradle.properties delete mode 100644 samples/libcurl/gradle.properties.for_bundle delete mode 100644 samples/nonBlockingEchoServer/gradle.properties delete mode 100644 samples/nonBlockingEchoServer/gradle.properties.for_bundle delete mode 100644 samples/opengl/gradle.properties delete mode 100644 samples/opengl/gradle.properties.for_bundle create mode 100644 samples/settings.gradle delete mode 100644 samples/socket/gradle.properties delete mode 100644 samples/socket/gradle.properties.for_bundle delete mode 100644 samples/tetris/gradle.properties delete mode 100644 samples/tetris/gradle.properties.for_bundle diff --git a/samples/build.gradle b/samples/build.gradle new file mode 100644 index 00000000000..506070e6f74 --- /dev/null +++ b/samples/build.gradle @@ -0,0 +1,24 @@ +subprojects { + buildscript { + repositories { + mavenCentral() + maven { + url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies" + } + } + + dependencies { + if (project.hasProperty("konan.plugin.path")) { + classpath files(project.property("konan.plugin.path")) + classpath "org.jetbrains.kotlin:kotlin-stdlib:+" + } else { + classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:+" + } + } + } +} + +task buildBash(type: Exec) { + commandLine "${projectDir.canonicalPath}/build.sh" + workingDir projectDir.canonicalPath +} diff --git a/samples/build.sh b/samples/build.sh new file mode 100755 index 00000000000..fe8b1b5d84b --- /dev/null +++ b/samples/build.sh @@ -0,0 +1,26 @@ +EXCLUDE=() +BUILD_SCRIPT="build.sh" + +function isExcluded() { + CHECKED="${1}" + for VALUE in $EXCLUDE; do + if [ "x$CHECKED" == "x$VALUE" ]; then + return 0 + fi + done + return -1 +} + +for SAMPLE_DIR in *; do + if [ -d "$SAMPLE_DIR" ] && [ -e "$SAMPLE_DIR/$BUILD_SCRIPT" ]; then + echo + echo "======================================================" + date + echo "Building a sample: $SAMPLE_DIR." + if ! isExcluded "$SAMPLE_DIR"; then + (cd "$SAMPLE_DIR" && . build.sh && cd $OLD_PWD) || (echo "Cannot build a sample: $SAMPLE_DIR. See log for details." && exit 1) + else + echo "The sample excluded." + fi + fi +done \ No newline at end of file diff --git a/samples/csvparser/build.gradle b/samples/csvparser/build.gradle index 6f746266893..0e066cf8231 100644 --- a/samples/csvparser/build.gradle +++ b/samples/csvparser/build.gradle @@ -1,16 +1,3 @@ -buildscript { - repositories { - mavenCentral() - maven { - url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies" - } - } - - dependencies { - classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:+" - } -} - apply plugin: 'konan' konanInterop { @@ -27,6 +14,7 @@ konanArtifacts { } build { + project.ext { outputFile = "${projectDir.canonicalPath}/${file(compileKonanCsvParser.artifactPath).name}" } doLast { copy { from compileKonanCsvParser.artifactPath @@ -35,7 +23,7 @@ build { } } -void dumpCompilatioTask(Task task) { +void dumpCompilationTask(Task task) { println() println("Compilation task: ${task.name}") println("outputDir : ${task.outputDir}") @@ -69,10 +57,16 @@ void dumpInteropTask(Task task) { println("linkFiles : ${task.linkFiles}") } -task dumpParameters { +task dumpParameters(type: DefaultTask) { doLast { - dumpCompilatioTask(konanArtifacts['CsvParser'].compilationTask) + dumpCompilationTask(konanArtifacts['CsvParser'].compilationTask) dumpInteropTask(konanInterop['stdio'].generateStubsTask) - dumpCompilatioTask(konanInterop['stdio'].compileStubsTask) + dumpCompilationTask(konanInterop['stdio'].compileStubsTask) + } +} + +clean { + doLast { + delete outputFile } } \ No newline at end of file diff --git a/samples/csvparser/gradle.properties b/samples/csvparser/gradle.properties deleted file mode 100644 index 3be37412632..00000000000 --- a/samples/csvparser/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -konan.home=../../dist \ No newline at end of file diff --git a/samples/gitchurn/build.gradle b/samples/gitchurn/build.gradle index f890502aefa..bb5d6bc83d7 100644 --- a/samples/gitchurn/build.gradle +++ b/samples/gitchurn/build.gradle @@ -1,16 +1,3 @@ -buildscript { - repositories { - mavenCentral() - maven { - url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies" - } - } - - dependencies { - classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:+" - } -} - apply plugin: 'konan' @@ -31,6 +18,7 @@ konanArtifacts { build { + project.ext { outputFile = "${projectDir.canonicalPath}/${file(compileKonanGitChurn.artifactPath).name}" } doLast { copy { from compileKonanGitChurn.artifactPath @@ -39,7 +27,7 @@ build { } } -void dumpCompilatioTask(Task task) { +void dumpCompilationTask(Task task) { println() println("Compilation task: ${task.name}") println("outputDir : ${task.outputDir}") @@ -73,10 +61,16 @@ void dumpInteropTask(Task task) { println("linkFiles : ${task.linkFiles}") } -task dumpParameters { +task dumpParameters(type: DefaultTask) { doLast { - dumpCompilatioTask(konanArtifacts['GitChurn'].compilationTask) + dumpCompilationTask(konanArtifacts['GitChurn'].compilationTask) dumpInteropTask(konanInterop['libgit2'].generateStubsTask) - dumpCompilatioTask(konanInterop['libgit2'].compileStubsTask) + dumpCompilationTask(konanInterop['libgit2'].compileStubsTask) + } +} + +clean { + doLast { + delete outputFile } } \ No newline at end of file diff --git a/samples/gitchurn/gradle.properties b/samples/gitchurn/gradle.properties deleted file mode 100644 index 3be37412632..00000000000 --- a/samples/gitchurn/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -konan.home=../../dist \ No newline at end of file diff --git a/samples/gitchurn/gradle.properties.for_bundle b/samples/gitchurn/gradle.properties.for_bundle deleted file mode 100644 index da99cc6e771..00000000000 --- a/samples/gitchurn/gradle.properties.for_bundle +++ /dev/null @@ -1 +0,0 @@ -konan.home=../.. \ No newline at end of file diff --git a/samples/gradle.properties b/samples/gradle.properties new file mode 100644 index 00000000000..cb093dd4dba --- /dev/null +++ b/samples/gradle.properties @@ -0,0 +1,2 @@ +konan.home=../../dist +konan.plugin.path=../../tools/gradle-plugin/dist/gradle-plugin.jar \ No newline at end of file diff --git a/samples/csvparser/gradle.properties.for_bundle b/samples/gradle.properties.for_bundle similarity index 100% rename from samples/csvparser/gradle.properties.for_bundle rename to samples/gradle.properties.for_bundle diff --git a/samples/gtk/README.md b/samples/gtk/README.md index 4894257160e..6bf2c0e9496 100644 --- a/samples/gtk/README.md +++ b/samples/gtk/README.md @@ -4,7 +4,10 @@ applications with the GTK toolkit. To build use `./build.sh` script without arguments (or specify `TARGET` variable if cross-compiling). +You also may use gradle to build the sample: `../gradlew build`. + Do not forget to install GTK3. + On Mac use `port install gtk3`, on Debian flavours of Linux - `apt-get install libgtk-3-dev`. To run on Mac also install XQuartz X server (https://www.xquartz.org/), and then diff --git a/samples/gtk/build.gradle b/samples/gtk/build.gradle new file mode 100644 index 00000000000..0c3b890ec36 --- /dev/null +++ b/samples/gtk/build.gradle @@ -0,0 +1,36 @@ +apply plugin: 'konan' + +konanInterop { + def includePrefixes = [ '/opt/local/include', '/usr/include', '/usr/local/include' ] + gtk3 { + includePrefixes.each { + includeDirs "$it/atk-1.0", "$it/gdk-pixbuf-2.0", "$it/cairo", "$it/pango-1.0", "$it/gtk-3.0", "$it/glib-2.0" + } + includeDirs '/opt/local/lib/glib-2.0/include', '/usr/lib/x86_64-linux-gnu/glib-2.0/include', '/usr/local/lib/glib-2.0/include' + defFile 'gtk3.def' + } +} + +konanArtifacts { + Gtk3Demo { + inputFiles project.fileTree('src') + useInterop 'gtk3' + linkerOpts "-L/opt/local/lib -L/usr/local/lib -L/usr/lib/x86_64-linux-gnu -lglib-2.0 -lgdk-3.0 -lgtk-3 -lgio-2.0 -lgobject-2.0" + } +} + +build { + project.ext { outputFile = "${projectDir.canonicalPath}/${file(compileKonanGtk3Demo.artifactPath).name}" } + doLast { + copy { + from compileKonanGtk3Demo.artifactPath + into projectDir.canonicalPath + } + } +} + +clean { + doLast { + delete outputFile + } +} \ No newline at end of file diff --git a/samples/gtk/build.sh b/samples/gtk/build.sh index 7c2d29d25fe..4113fc961c1 100755 --- a/samples/gtk/build.sh +++ b/samples/gtk/build.sh @@ -4,6 +4,7 @@ PATH=../../dist/bin:../../bin:$PATH DIR=. IPREFIX_macbook=-I/opt/local/include +#IPREFIX_macbook=-I/usr/local/include IPREFIX_linux=-I/usr/include LINKER_ARGS_macbook="-L/opt/local/lib -lglib-2.0 -lgdk-3.0 -lgtk-3 -lgio-2.0 -lgobject-2.0" LINKER_ARGS_linux="-L/usr/lib/x86_64-linux-gnu -lglib-2.0 -lgdk-3 -lgtk-3 -lgio-2.0 -lgobject-2.0" @@ -26,7 +27,8 @@ COMPILER_ARGS=${!var} # add -opt for an optimized build. if [ ! -f $DIR/gtk3.bc ]; then echo "Generating GTK stubs (once), may take few mins depending on the hardware..." cinterop -J-Xmx8g -copt $IPREFIX/atk-1.0 -copt $IPREFIX/gdk-pixbuf-2.0 -copt $IPREFIX/cairo -copt $IPREFIX/pango-1.0 \ - -copt -I/opt/local/lib/glib-2.0/include -copt -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -copt $IPREFIX/gtk-3.0 -copt $IPREFIX/glib-2.0 -def $DIR/gtk3.def \ + -copt -I/opt/local/lib/glib-2.0/include -copt -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -copt -I/usr/local/lib/glib-2.0/include \ + -copt $IPREFIX/gtk-3.0 -copt $IPREFIX/glib-2.0 -def $DIR/gtk3.def \ -target $TARGET -o $DIR/gtk3.bc || exit 1 fi konanc -target $TARGET $DIR/src -library $DIR/gtk3.bc -linkerArgs "$LINKER_ARGS" -o $DIR/Gtk3Demo.kexe || exit 1 diff --git a/samples/libcurl/build.gradle b/samples/libcurl/build.gradle index 475b4b4f2cc..e4145783fb6 100644 --- a/samples/libcurl/build.gradle +++ b/samples/libcurl/build.gradle @@ -1,16 +1,3 @@ -buildscript { - repositories { - mavenCentral() - maven { - url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies" - } - } - - dependencies { - classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:+" - } -} - apply plugin: 'konan' konanInterop { @@ -28,12 +15,18 @@ konanArtifacts { } } - build { + project.ext { outputFile = "${projectDir.canonicalPath}/${file(compileKonanCurl.artifactPath).name}" } doLast { copy { from compileKonanCurl.artifactPath into projectDir.canonicalPath } } +} + +clean { + doLast { + delete outputFile + } } \ No newline at end of file diff --git a/samples/libcurl/gradle.properties b/samples/libcurl/gradle.properties deleted file mode 100644 index 3be37412632..00000000000 --- a/samples/libcurl/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -konan.home=../../dist \ No newline at end of file diff --git a/samples/libcurl/gradle.properties.for_bundle b/samples/libcurl/gradle.properties.for_bundle deleted file mode 100644 index da99cc6e771..00000000000 --- a/samples/libcurl/gradle.properties.for_bundle +++ /dev/null @@ -1 +0,0 @@ -konan.home=../.. \ No newline at end of file diff --git a/samples/nonBlockingEchoServer/build.gradle b/samples/nonBlockingEchoServer/build.gradle index 8982b2d20c0..c8a26b5ea2e 100644 --- a/samples/nonBlockingEchoServer/build.gradle +++ b/samples/nonBlockingEchoServer/build.gradle @@ -1,16 +1,3 @@ -buildscript { - repositories { - mavenCentral() - maven { - url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies" - } - } - - dependencies { - classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:0.1" - } -} - apply plugin: 'konan' konanInterop { @@ -27,6 +14,7 @@ konanArtifacts { } build { + project.ext { outputFile = "${projectDir.canonicalPath}/${file(compileKonanEchoServer.artifactPath).name}" } doLast { copy { from compileKonanEchoServer.artifactPath @@ -34,3 +22,9 @@ build { } } } + +clean { + doLast { + delete outputFile + } +} \ No newline at end of file diff --git a/samples/nonBlockingEchoServer/gradle.properties b/samples/nonBlockingEchoServer/gradle.properties deleted file mode 100644 index 196f4b3055e..00000000000 --- a/samples/nonBlockingEchoServer/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -konan.home=../../dist diff --git a/samples/nonBlockingEchoServer/gradle.properties.for_bundle b/samples/nonBlockingEchoServer/gradle.properties.for_bundle deleted file mode 100644 index 5e41860b04f..00000000000 --- a/samples/nonBlockingEchoServer/gradle.properties.for_bundle +++ /dev/null @@ -1 +0,0 @@ -konan.home=../.. diff --git a/samples/opengl/build.gradle b/samples/opengl/build.gradle index fb6a597d0ee..46da90254d9 100644 --- a/samples/opengl/build.gradle +++ b/samples/opengl/build.gradle @@ -1,16 +1,3 @@ -buildscript { - repositories { - mavenCentral() - maven { - url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies" - } - } - - dependencies { - classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:+" - } -} - apply plugin: 'konan' konanInterop { @@ -36,10 +23,17 @@ konanArtifacts { build { + project.ext { outputFile = "${projectDir.canonicalPath}/${file(compileKonanOpenGlTeapot.artifactPath).name}" } doLast { copy { from compileKonanOpenGlTeapot.artifactPath into projectDir.canonicalPath } } +} + +clean { + doLast { + delete outputFile + } } \ No newline at end of file diff --git a/samples/opengl/gradle.properties b/samples/opengl/gradle.properties deleted file mode 100644 index 3be37412632..00000000000 --- a/samples/opengl/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -konan.home=../../dist \ No newline at end of file diff --git a/samples/opengl/gradle.properties.for_bundle b/samples/opengl/gradle.properties.for_bundle deleted file mode 100644 index da99cc6e771..00000000000 --- a/samples/opengl/gradle.properties.for_bundle +++ /dev/null @@ -1 +0,0 @@ -konan.home=../.. \ No newline at end of file diff --git a/samples/settings.gradle b/samples/settings.gradle new file mode 100644 index 00000000000..981a02417bf --- /dev/null +++ b/samples/settings.gradle @@ -0,0 +1,8 @@ +include ':csvparser' +include ':gitchurn' +include ':gtk' +include ':libcurl' +include ':nonBlockingEchoServer' +include ':opengl' +include ':socket' +include ':tetris' diff --git a/samples/socket/build.gradle b/samples/socket/build.gradle index 6706c263c90..c8a26b5ea2e 100644 --- a/samples/socket/build.gradle +++ b/samples/socket/build.gradle @@ -1,16 +1,3 @@ -buildscript { - repositories { - mavenCentral() - maven { - url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies" - } - } - - dependencies { - classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:+" - } -} - apply plugin: 'konan' konanInterop { @@ -27,10 +14,17 @@ konanArtifacts { } build { + project.ext { outputFile = "${projectDir.canonicalPath}/${file(compileKonanEchoServer.artifactPath).name}" } doLast { copy { from compileKonanEchoServer.artifactPath into projectDir.canonicalPath } } +} + +clean { + doLast { + delete outputFile + } } \ No newline at end of file diff --git a/samples/socket/gradle.properties b/samples/socket/gradle.properties deleted file mode 100644 index 3be37412632..00000000000 --- a/samples/socket/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -konan.home=../../dist \ No newline at end of file diff --git a/samples/socket/gradle.properties.for_bundle b/samples/socket/gradle.properties.for_bundle deleted file mode 100644 index da99cc6e771..00000000000 --- a/samples/socket/gradle.properties.for_bundle +++ /dev/null @@ -1 +0,0 @@ -konan.home=../.. \ No newline at end of file diff --git a/samples/tetris/build.gradle b/samples/tetris/build.gradle index 2290a74ce26..30efe387373 100644 --- a/samples/tetris/build.gradle +++ b/samples/tetris/build.gradle @@ -1,16 +1,3 @@ -buildscript { - repositories { - mavenCentral() - maven { - url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies" - } - } - - dependencies { - classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:+" - } -} - apply plugin: 'konan' konanInterop { @@ -84,14 +71,24 @@ konanArtifacts { } build { + project.ext { + buildTasks = getTaskDependencies().getDependencies().findAll { task -> task.name.startsWith("compileKonan") } + outputFiles = buildTasks.collect { task -> "${projectDir.canonicalPath}/${file(task.artifactPath).name}" } + } doLast { - getTaskDependencies().getDependencies().forEach() { task -> - if (task.name.startsWith("compileKonan")) { - copy { - from task.artifactPath - into projectDir.canonicalPath - } + buildTasks.forEach() { task -> + copy { + from task.artifactPath + into projectDir.canonicalPath } } } } + +clean { + doLast { + outputFiles.forEach { + delete it + } + } +} diff --git a/samples/tetris/gradle.properties b/samples/tetris/gradle.properties deleted file mode 100644 index 3be37412632..00000000000 --- a/samples/tetris/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -konan.home=../../dist \ No newline at end of file diff --git a/samples/tetris/gradle.properties.for_bundle b/samples/tetris/gradle.properties.for_bundle deleted file mode 100644 index da99cc6e771..00000000000 --- a/samples/tetris/gradle.properties.for_bundle +++ /dev/null @@ -1 +0,0 @@ -konan.home=../.. \ No newline at end of file