Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module experiment - build harness #87

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f9b305f
Auto-include build.gradle from Core module
oniatus Jan 2, 2017
2a7a16c
Small cleanup
oniatus Jan 2, 2017
ed6644e
Merge PR #2727 by @oniatus - auto-include Core's build.gradle for mod…
Cervator Jan 17, 2017
9ce582c
Major Gradle overhaul - bunch of stuff done, stable again but more to…
Cervator Jan 26, 2017
0defbe3
Minor cleanup.
Cervator Jan 28, 2017
4ea0ddc
Changes I forgot to commit back when I remembered what they were! I t…
Cervator Oct 30, 2017
7fca9da
Ooooone more thing. Or two more things. Prep the prepareStuff task be…
Cervator Oct 30, 2017
9510913
minor version bump for scala
bbarker Oct 30, 2017
329a749
Remove build.gradle stuff for modules from the utility script
Cervator Oct 31, 2017
7b0e30a
Add the telemetry dependency stuff completed during GSOC - that code …
Cervator Oct 31, 2017
9499a0d
More remembered things: while the new & faster resolution stuff works…
Cervator Oct 31, 2017
56a744f
Actually don't depend on the telemetry stuff yet, just make sure Grad…
Cervator Oct 31, 2017
5544f86
Assortment of tweaks to make things work better, committed before I m…
Cervator Nov 1, 2017
78bd1c9
Collapse the old config dir into the existing Gradle dir - no changes…
Cervator Nov 2, 2017
3945d89
Adjustments for the demise of the config dir
Cervator Nov 2, 2017
a1bc52b
Move templates into the gradle dir too
Cervator Nov 2, 2017
23ca1e8
Checkpoint - more moving stuff around plus start on the harness.
Cervator Nov 3, 2017
eff4c37
Move the shared/include stuff in the new module system into /gradle a…
Cervator Nov 3, 2017
7cabfe1
Tweaks for moved files, build harness looking decent
Cervator Nov 3, 2017
bcfb9d5
Quick ugly hacks that seemed to be enough to get the build harness wo…
Cervator Nov 4, 2017
957d8f3
Experimental fix to unit testing starting out of the Gradle cache.
Cervator Nov 4, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ extensions
!/modules/Core
!/modules/CoreSampleGameplay
!/modules/BuilderSampleGameplay
!/modules/subprojects.gradle
!/modules/*.gradle
/meta/*
!/meta/subprojects.gradle
/libs/*
!/libs/subprojects.gradle

# Ignore Gradle and some transient project config files (template versions available under /templates)
# Ignore Gradle and some transient project config files (template versions available under /gradle/templates)
build/
/gradle.properties
/override.cfg

# Ignore IntelliJ - could use "/**/*.iml" to catch all .iml files, but that requires a somewhat recent Git version
/out/
out/
modules/Core/Core.iml
modules/CoreSampleGameplay/CoreSampleGameplay.iml
modules/BuilderSampleGameplay/BuilderSampleGameplay.iml
Expand Down Expand Up @@ -90,7 +90,7 @@ entityDump.txt

# Ignore stuff we extract for use with Terasology
/natives/
config/metrics/
gradle/metrics/


# Ignore weird stuff that might be obsolete
164 changes: 59 additions & 105 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
// Separate build file for structure heavy stuff like using Git to fetch other repos to embed within the project
apply from: 'config/gradle/utility.gradle'
apply from: 'config/gradle/ide.gradle'

// Needed for extending the "clean" task to also delete custom stuff defined here like natives
apply plugin: 'base'

// For generating IntelliJ project files
apply plugin: 'idea'

// The root project should not be an eclipse project. It keeps eclipse (4.2) from finding the sub-projects.
//apply plugin: 'eclipse'

// Git plugin details at https://github.com/ajoberstar/gradle-git
import org.ajoberstar.gradle.git.tasks.*
apply plugin: 'project-report'

// Dependencies needed for what our Gradle scripts themselves use. It cannot be included via an external Gradle file :-(
buildscript {
Expand Down Expand Up @@ -41,8 +30,8 @@ assert org.gradle.api.JavaVersion.current().isJava8Compatible()
// Declare "extra properties" (variables) for the project (and subs) - a Gradle thing that makes them special.
ext {
dirNatives = 'natives'
dirConfigMetrics = 'config/metrics'
templatesDir = 'templates'
dirConfigMetrics = 'gradle/metrics'
templatesDir = 'gradle/templates'

// Lib dir for use in manifest entries etc (like in :engine). A separate "libsDir" exists, auto-created by Gradle
subDirLibs = 'libs'
Expand All @@ -58,7 +47,12 @@ repositories {

// MovingBlocks Artifactory instance for libs not readily available elsewhere plus our own libs
maven {
url "http://artifactory.terasology.org/artifactory/virtual-repo-live"
if (rootProject.hasProperty("artifactoryResolveRepo")) {
url "http://artifactory.terasology.org/artifactory/$artifactoryResolveRepo"
println "Changing root RESOLVE repo to $artifactoryResolveRepo"
} else {
url "http://artifactory.terasology.org/artifactory/virtual-repo-live"
}
}
}

Expand Down Expand Up @@ -130,38 +124,9 @@ task extractConfig (type: Copy) {
into "$rootDir/$dirConfigMetrics"
}

// Helper that returns a list of all local Terasology module projects
def terasologyModules() {
subprojects.findAll {it.parent.name == 'modules'}
}

// Helper that replaces the build.gradle under every module with a fresh copy from the Core module
task refreshModuleGradle << {
File replacementGradle = new File(rootDir, 'modules/Core/build.gradle')
terasologyModules().each {
if (it.name != 'Core') {
File targetFile = new File(rootDir, "modules/" + it.name + "/build.gradle")
targetFile.delete()
targetFile << replacementGradle.text
}
}
}

// Helpers that do magic things after having dependencies attached below
task moduleClasses
task moduleJars

// This magically makes everything work - without this the desired module projects returned have no tasks :-(
gradle.projectsEvaluated {
// Note how "classes" may indirectly trigger "jar" for module dependencies of modules (module compile dependency)
moduleClasses.dependsOn(terasologyModules().classes)

// This makes it work for a full jar task
moduleJars.dependsOn(terasologyModules().jar)
}

// This is a TEMPORARY tweak to make "changing" dependencies always ('0') check for newer snapshots available
// TODO: Remove this when versioning and promotion works fully, then we shouldn't care about snapshots normally anyway
// For some reason this can stay here, yet had to be removed from everywhere else for Gradle 3.3
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
Expand All @@ -183,12 +148,17 @@ task protobufCompileLinux(type:Exec) {
commandLine 'protobuf/compiler/protoc', '--proto_path=engine/src/main/protobuf', '--java_out', 'engine/src/main/java', "engine/src/main/protobuf/EntityData.proto", "engine/src/main/protobuf/NetMessage.proto"
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// General IDE customization //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// These tasks are written in a way that makes them execute always, outside Gradle's regular workflow of calculating what needs to be done //
// If they were written as Copy tasks and such they'd only work during the execution phase for a run that included them on the task graph //
// That's how it was done in the frequent 'gradlew idea' days where any change impacting project structure needed a rerun + IDE restart //
// With Gradle import / linking enabled instead we can use IDE integration to avoid a restart but don't have an explicit task to chain to //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


// TODO: Convert the natives, config, and IDE setup to be tasks like this one
task copyInMissingTemplates {
description = "Copies in placeholders from the /templates dir to project root if not present yet"
description = "Copies in placeholders from the /gradle/templates dir to project root if not present yet"
File gradlePropsFile = new File(rootDir, 'gradle.properties')
File OverrideCfgFile = new File(rootDir, 'override.cfg')
if (!gradlePropsFile.exists()) {
Expand All @@ -199,64 +169,48 @@ task copyInMissingTemplates {
}
}

// Make sure the IDE prep includes extraction of natives
ideaModule.dependsOn extractNatives
ideaModule.dependsOn copyInMissingTemplates

// For IntelliJ add a bunch of excluded directories
idea {

// Exclude Eclipse dirs
// TODO: Update this as Eclipse bin dirs now generate in several deeper spots rather than at top-level
module.excludeDirs += file('bin')
module.excludeDirs += file('.settings')
// TODO: Add a single file exclude for facades/PC/Terasology.launch ?

// Exclude special dirs
module.excludeDirs += file('natives')
module.excludeDirs += file('protobuf')

// Exclude output dirs
module.excludeDirs += file('logs')
module.excludeDirs += file('saves')
module.excludeDirs += file('screenshots')
module.excludeDirs += file('terasology-server')
module.excludeDirs += file('terasology-2ndclient')

module.downloadSources = true

project {
// Set JDK
jdkName = '1.8'
wildcards -= '!?*.groovy'

ipr {
withXml { xmlProvider ->
// Apply a bunch of tweaks to IntelliJ config - all defined in ide.gradle
// Part reason for separate file was in case a module needs to define something it cannot do so in a project block
def iprNode = xmlProvider.asNode()
ideaActivateCheckstyle(iprNode)
ideaActivateCopyright(iprNode)
ideaActivateAnnotations(iprNode)
ideaActivateGit(iprNode)
ideaActivateGradle(iprNode)
}

// Sets sourceCompatibility within IntelliJ (without this root build having the Java plugin applied)
whenMerged {project ->
project.jdk.languageLevel = 'JDK_1_8'
}
}
// TODO: Consider making this stuff excluded from clean, then offer a fullClean for the rare time that may be needed
// That would allow a `gradlew clean` without having to rerun this at all, everything would still work fine (with rebuild)
task prepareStuff {
dependsOn extractNatives
dependsOn extractConfig
dependsOn copyInMissingTemplates
}

task harnessTheBuild (type: Zip) {
description = "Prepares all build files and supporting stuff needed to build modules solo"
dependsOn extractNatives
dependsOn extractConfig

from ('modules') {
include 'build.gradle'
}

// Tweaks to the .iws
workspace.iws.withXml { xmlProvider ->
def iwsNode = xmlProvider.asNode()
ideaMakeAutomatically(iwsNode)
ideaRunConfig(iwsNode)
from ('gradle') {
include '*.gradle'
include 'wrapper/**/*'
include 'metrics/**/*'
include 'templates/**/*'
into 'gradle'
}

from 'gradlew'
from 'gradlew.bat'
from 'groovyw'
from 'groovyw.bat'
from 'module.groovy'

archiveName = "TerasologyHarness.zip"
}

cleanIdea.doLast {
new File('Terasology.iws').delete()
}
afterEvaluate {
// This pops up way too early - after this particular file has been evaluated? Module config logging follows
// Really need a hook to trigger a task's execution phase on any project evaluation
// Difficulty: IntelliJ uses a special entry point (likely Eclipse as well) that just evaluates somehow
//println 'After evaluate (TODO: Trying to find a good point to hook in a prep task)'
}

gradle.afterProject {
// This triggers *a lot* - after every project is evaluated. So similar to allProjects.afterEvaluate?
//println 'After project (TODO: Trying to find a good point to hook in a prep task)'
}
Loading