Skip to content

Commit

Permalink
Use Sample plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lacasse committed Oct 7, 2019
1 parent 9c9e96b commit c5afcf0
Show file tree
Hide file tree
Showing 4 changed files with 2,258 additions and 0 deletions.
65 changes: 65 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,69 @@
import org.asciidoctor.gradle.AsciidoctorTask
import org.gradle.samples.Sample
import org.gradle.samples.plugins.generators.CppLibraryTemplate
import org.gradle.samples.plugins.generators.SourceCopyTask
import org.gradle.samples.plugins.generators.SwiftLibraryTemplate
import org.gradle.util.GUtil

// This root project is simply a container of sample builds
plugins {
id("org.gradle.samples.wrapper")
id("org.gradle.samples")
}

tasks.withType<AsciidoctorTask>().matching { it.name.contains("Sample") }.configureEach {
options(mapOf("doctype" to "book"))

inputs.file("src/docs/css/manual.css")
.withPropertyName("manual")
.withPathSensitivity(PathSensitivity.RELATIVE)

attributes(mapOf("stylesdir" to file("src/docs/css/").absolutePath,
"stylesheet" to "manual.css",
"nofooter" to true,
"sectanchors" to true,
"sectlinks" to true,
"linkattrs" to true))
}

val cppUtilsLib = CppLibraryTemplate.of("cpp-lib-with-api-dep", "utilities")
val cppListLib = CppLibraryTemplate.of("cpp-lib", "list")
val cppMessageLib = CppLibraryTemplate.of("cpp-message-api", "message")

val swiftUtilsLib = SwiftLibraryTemplate.of("swift-lib-with-api-dep", "Utilities")
val swiftListLib = SwiftLibraryTemplate.of("swift-lib", "List")

val samples = project.extensions.getByName("samples") as NamedDomainObjectContainer<Sample>

fun Sample.copySource(configuration: SourceCopyTask.() -> kotlin.Unit) {
val sample = this
val copySourceTask = tasks.register("generate${GUtil.toCamelCase(sample.name)}Sample", SourceCopyTask::class.java) {
val outputDir = project.layout.buildDirectory.dir("sample-generators/${sample.name}")
sampleDir.set(outputDir)
templatesDir.set(file("samples-dev/src/templates"))
}
copySourceTask.configure(configuration)

val sourceContent = project.fileTree(copySourceTask.flatMap { it.sampleDir }) {
builtBy(copySourceTask)

// Patch over the stubbed Gradle wrappers
exclude("gradlew*")
}
sample.archiveContent.from(sourceContent)
}

samples.create("cpp-application") {
sampleDirectory.set(file("cpp/application"))
withGroovyDsl {
archiveContent.from(fileTree(sampleDirectory).include("**/*.gradle"))
}
copySource {
appProject(".").buildRoot()
appProject(".").fromTemplate("cpp-app")
appProject(".").fromTemplate(cppMessageLib)
appProject(".").fromTemplate("cpp-message-static")
appProject(".").fromTemplate(cppUtilsLib)
appProject(".").fromTemplate(cppListLib)
}
}
21 changes: 21 additions & 0 deletions cpp/application/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
= Simple application (application)

ifndef::env-github[]
- link:{zip-base-file-name}-groovy-dsl.zip[Download Groovy DSL ZIP]
endif::[]

This sample shows how a simple C++ application can be built with Gradle. The application has no dependencies and the build has minimal configuration.

Although there is currently no out-of-the-box support for building applications and libraries from C, there is also a sample build that shows how the C++ support can be configured to build a C application.

To build and run the application:

```
> cd cpp-application
> ./gradlew assemble

BUILD SUCCESSFUL in 1s

> ./build/install/main/debug/app
Hello, World!
```
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include("samples-dev")

includeBuild("/Users/daniel/gradle/guides/guides/subprojects/gradle-guides-plugin")
includeBuild("samples-dev/plugins")
includeBuild("samples-dev/src/templates/custom-publication-plugin")
includeBuild("samples-dev/src/templates/build-wrapper-plugin")
Expand All @@ -14,3 +15,4 @@ pluginManagement {
}
}
}

Loading

0 comments on commit c5afcf0

Please sign in to comment.