Skip to content

Commit

Permalink
Added run task. Ran into a bug where an xtcRun task assumes it must h…
Browse files Browse the repository at this point in the history
…ave xtc modules built by its project on the module path, when it can really be an aggregator of subprojects, or some other valid run job similar to that.
  • Loading branch information
lagergren committed Dec 20, 2023
1 parent 93fadf3 commit 687defc
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 29 deletions.
44 changes: 44 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,50 @@
* Main build file for the "platform" project.
*/

plugins {
alias(libs.plugins.xtc)
}

dependencies {
xdkZip(libs.xdk)
xtcModule(project(":kernel"))
}

fun readPassword(): String {
val password = findProperty("org.xtclang.platform.password")?.toString() ?: ""
if (password.isEmpty()) {
throw GradleException("Error. No password was given.")
}
logger.lifecycle("Resolved password: [REDACTED]")
return password
}

// The xtcRun plugin will give us runXtc<sourceSet> tasks, where
// it's just runXtc for the main source set
xtcRun {
verbose = true
// needs a password property
module {
moduleName = "kernel"
args(readPassword())
}
}

val runXtc by tasks.existing {
dependsOn(tasks.build)
}

//println("Please run the platform directly using the following command:")
//println(" xec -L lib/ kernel.xtc [password]")
val run by tasks.registering {
group = "application"
description = "Build (if necessary) and run the platform (equivalent to 'xec [-L <module>]+ kernel.xtc <password>)"
dependsOn("runXtc")
doFirst {
logger.lifecycle("Starting the XTC platform (kernel).")
}
}

/*
val libDir = "${projectDir}/lib"
val build = tasks.register("build") {
Expand Down
8 changes: 7 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
group=platform.xqiz.it
version=0.1.0

xtcVersion=0.4.4
xtcVersion=0.4.41

# NOTE: This property would not live inside your repository for a production case, but
# should be passed through a Gradle command line property "-Porg.xtclang.platform.password=<password>>",
# placed in $GRADLE_USER_HOME/gradle.properties, or used a secret in an environment variable (for example
# in GitHub runners, or other CI/CD tasks).
org.xtclang.platform.password=fethemligt

org.gradle.parallel=true
org.gradle.caching=true
12 changes: 9 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
#TODO
#https://github.com/node-gradle/gradle-node-plugin
[versions]
node = "7.0.1"
xdk = "0.4.4"
npm = "10.2.0"
yarn = "1.22.21"
xdk = "0.4.41"
tasktree = "2.1.1"

[plugins]
node = { id = "com.github.node-gradle.node", version.ref = "node" }
xtc = { id = "org.xtclang.xtc-plugin", version.ref = "xdk" }

# taskTree is a helper that we can use to view task dependencies
# for example: ./gradlew run taskTree
tasktree = { id = "com.dorongold.task-tree", version.ref = "tasktree" }

[libraries]
xdk = { group = "org.xtclang", name = "xdk", version.ref = "xdk" }

[bundles]
# No bundles so far
7 changes: 0 additions & 7 deletions kernel/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ xtcCompile {
verbose = true
}

xtcRun {
// needs a password property
val password = findProperty("org.xtclang.platform.password")
logger.lifecycle("Password: $password")

}

/*
val libDir = "${rootProject.projectDir}/lib"
Expand Down
41 changes: 24 additions & 17 deletions platformUI/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import com.github.gradle.node.yarn.task.YarnTask

node {
version = "18.17.0"
npmVersion = "10.2.0"
yarnVersion = "1.22.21"
version = libs.versions.node.get()
npmVersion = libs.versions.npm.get()
yarnVersion = libs.versions.yarn.get()
// TODO: Typically you would set download=true here to ensure that we download and use
// exactly the versions of the tools above. These would go into the .gradle cache
// directory of this subproject, and not anywhere else in the system. However,
// the node plugin will add a hidden repository to the current project if the
// download flag is enabled, and to keep things strict and simple, and also conform
// to modern Gradle best practice, we want to define repositories in one place only,
// the rootProject settings.gradle.kts file. That file currently contains a
// "repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)" entry, to ensure
// that we have full control over all the repositories required for the build, and
// that we won't have to add an identical repositories block to every build.gradle.kts
// file in every subproject.
//download = true
}

Expand All @@ -20,6 +31,7 @@ dependencies {
// TODO: Run a build scan and figure out why yarn wants to invalidate dependencies.
// TODO: Implement a parallel NPM / package-lock based approach. Yarn does not like having a package lock in the same build.
internal val gui = project.file("gui")
internal val buildDirs = arrayOf("gui/node_modules", "gui_dist", "gui/.quasar")

val compileXtc by tasks.existing {
dependsOn(yarnQuasarBuild)
Expand All @@ -34,9 +46,7 @@ sourceSets.main {
}

val clean by tasks.existing {
delete(layout.files("gui/node_modules"))
delete(layout.files("gui/dist"))
delete(layout.files("gui/.quasar"))
delete(layout.files(*buildDirs))
}

val yarnSetup by tasks.existing
Expand All @@ -45,19 +55,18 @@ val yarnAddQuasar by tasks.registering(YarnTask::class) {
dependsOn(yarnSetup)
workingDir = gui
outputs.file("node_modules")
val isQuasarGlobal = (findProperty("org.xtclang.platform.quasarGlobal")?.toString() ?: "false").toBoolean()
args = buildList {
val isQuasarGlobal = findProperty("org.xtclang.platform.quasarGlobal")?.toString() ?: "false"
add("add")
if (isQuasarGlobal.toBoolean()) {
logger.lifecycle("$name will install Quasar globally.")
if (isQuasarGlobal) {
add("global")
} else {
logger.lifecycle("$name will only install Quasar locally for project '${rootProject.name}'.")
}
add("quasar")
add("@quasar/cli")
}
doLast {

doFirst {
logger.lifecycle("Task '$name' installing Quasar (${if (isQuasarGlobal) "globally" else "locally, only for ${rootProject.name}"}.")
printTaskOutputs()
}
}
Expand All @@ -72,9 +81,7 @@ val yarnQuasarBuild by tasks.registering(YarnTask::class) {
}
}

fun Task.printTaskOutputs() {
logger.lifecycle("$name: Finished.")
outputs.files.asFileTree.forEach {
logger.lifecycle("$name: ** installed: $it")
}
internal fun Task.printTaskOutputs() {
logger.lifecycle("${project.name} Task '$name' finished.")
outputs.files.asFileTree.forEachIndexed { i, it -> logger.lifecycle("$name: ** '$name' task output $i: $it") }
}
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pluginManagement {
plugins {
val xtcVersion: String by settings
id("org.xtclang.xtc-plugin").version(xtcVersion)
id("com.github.node-gradle.node").version("7.0.1")
id("com.github.node-gradle.node").version("7.0.1") // TODO version from version catalog instead?
}
}

Expand Down

0 comments on commit 687defc

Please sign in to comment.