1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-24 06:03:28 +00:00

Some minor build system improvements

- Correctly handle Git commands failing. We need an actual default
   value, not just null!

 - Use run/ and build/tmp/ for temporary test locations, not
   /test-files.
This commit is contained in:
Jonathan Coates 2022-10-24 19:21:08 +01:00
parent f4e542b4db
commit 8171578e80
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
7 changed files with 69 additions and 34 deletions

1
.gitignore vendored
View File

@ -11,7 +11,6 @@
# Runtime directories
/run
/run-*
/test-files
*.ipr
*.iws

View File

@ -77,14 +77,14 @@ minecraft {
}
val testClient by registering {
workingDirectory(project.file("test-files/client"))
workingDirectory(file("run/testClient"))
parent(client.get())
mods.register("cctest") { source(sourceSets["testMod"]) }
}
val testServer by registering {
workingDirectory(project.file("test-files/server"))
workingDirectory(file("run/testServer"))
parent(server.get())
property("cctest.run", "true")
@ -165,7 +165,7 @@ val luaJavadoc by tasks.registering(Javadoc::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
source(sourceSets.main.get().java)
setDestinationDir(project.buildDir.resolve("docs/luaJavadoc"))
setDestinationDir(buildDir.resolve("docs/luaJavadoc"))
classpath = sourceSets.main.get().compileClasspath
options.docletpath = configurations["cctJavadoc"].files.toList()
@ -296,6 +296,10 @@ val docWebsite by tasks.registering(Copy::class) {
// Check tasks
tasks.test {
systemProperty("cct.test-files", buildDir.resolve("tmp/test-files").absolutePath)
}
val lintLua by tasks.registering(IlluaminateExec::class) {
group = JavaBasePlugin.VERIFICATION_GROUP
description = "Lint Lua (and Lua docs) with illuaminate"
@ -321,7 +325,7 @@ val setupRunGametest by tasks.registering(Copy::class) {
include("eula.txt")
include("server.properties")
}
into("test-files/server")
into("run/testServer")
}
val runGametest by tasks.registering(JavaExec::class) {
@ -354,7 +358,7 @@ val publishCurseForge by tasks.registering(TaskPublishCurseForge::class) {
group = PublishingPlugin.PUBLISH_TASK_GROUP
description = "Upload artifacts to CurseForge"
apiToken = project.findProperty("curseForgeApiKey") ?: ""
apiToken = findProperty("curseForgeApiKey") ?: ""
enabled = apiToken != ""
val mainFile = upload("282001", tasks.shadowJar)
@ -368,7 +372,7 @@ val publishCurseForge by tasks.registering(TaskPublishCurseForge::class) {
tasks.publish { dependsOn(publishCurseForge) }
modrinth {
token.set(project.findProperty("modrinthApiKey") as String? ?: "")
token.set(findProperty("modrinthApiKey") as String? ?: "")
projectId.set("gu7yAYhd")
versionNumber.set("$mcVersion-$modVersion")
versionName.set(modVersion)
@ -377,13 +381,13 @@ modrinth {
gameVersions.add(mcVersion)
changelog.set("Release notes can be found on the [GitHub repository](https://github.com/cc-tweaked/CC-Tweaked/releases/tag/v$mcVersion-$modVersion).")
syncBodyFrom.set(project.provider { file("doc/mod-page.md").readText() })
syncBodyFrom.set(provider { file("doc/mod-page.md").readText() })
}
tasks.publish { dependsOn(tasks.modrinth) }
githubRelease {
token(project.findProperty("githubApiKey") as String? ?: "")
token(findProperty("githubApiKey") as String? ?: "")
owner.set("cc-tweaked")
repo.set("CC-Tweaked")
targetCommitish.set(cct.gitBranch)
@ -391,14 +395,12 @@ githubRelease {
tagName.set("v$mcVersion-$modVersion")
releaseName.set("[$mcVersion] $modVersion")
body.set(
project.provider(
{
"## " + file("src/main/resources/data/computercraft/lua/rom/help/whatsnew.md")
.readLines()
.takeWhile { it != "Type \"help changelog\" to see the full version history." }
.joinToString("\n").trim()
},
),
provider {
"## " + file("src/main/resources/data/computercraft/lua/rom/help/whatsnew.md")
.readLines()
.takeWhile { it != "Type \"help changelog\" to see the full version history." }
.joinToString("\n").trim()
},
)
prerelease.set(!isStable)
}

View File

@ -25,17 +25,17 @@ abstract class CCTweakedExtension(
private val fs: FileSystemOperations,
) {
/** Get the hash of the latest git commit. */
val gitHash: Provider<String> = gitProvider(project) {
val gitHash: Provider<String> = gitProvider(project, "<no git hash>") {
ProcessHelpers.captureOut("git", "-C", project.projectDir.absolutePath, "rev-parse", "HEAD")
}
/** Get the current git branch. */
val gitBranch: Provider<String> = gitProvider(project) {
val gitBranch: Provider<String> = gitProvider(project, "<no git branch>") {
ProcessHelpers.captureOut("git", "-C", project.projectDir.absolutePath, "rev-parse", "--abbrev-ref", "HEAD")
}
/** Get a list of all contributors to the project. */
val gitContributors: Provider<List<String>> = gitProvider(project) {
val gitContributors: Provider<List<String>> = gitProvider(project, listOf()) {
val authors: Set<String> = HashSet(
ProcessHelpers.captureLines(
"git", "-C", project.projectDir.absolutePath, "log",
@ -110,13 +110,13 @@ fun jacoco(task: NamedDomainObjectProvider<JavaExec>) {
"GitHub", "Daniel Ratcliffe", "Weblate",
)
private fun <T> gitProvider(project: Project, supplier: () -> T): Provider<T> {
private fun <T> gitProvider(project: Project, default: T, supplier: () -> T): Provider<T> {
return project.provider {
try {
supplier()
} catch (e: IOException) {
project.logger.error("Cannot read Git Repository", e)
null
project.logger.error("Cannot read Git repository: ${e.message}")
default
}
}
}

View File

@ -20,6 +20,7 @@
import dan200.computercraft.core.terminal.Terminal;
import dan200.computercraft.shared.peripheral.modem.ModemState;
import dan200.computercraft.shared.peripheral.modem.wireless.WirelessModemPeripheral;
import dan200.computercraft.support.TestFiles;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.World;
import org.apache.logging.log4j.LogManager;
@ -31,13 +32,13 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.nio.channels.Channels;
import java.nio.channels.WritableByteChannel;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
@ -50,18 +51,18 @@
/**
* Loads tests from {@code test-rom/spec} and executes them.
*
* <p>
* This spins up a new computer and runs the {@code mcfly.lua} script. This will then load all files in the {@code spec}
* directory and register them with {@code cct_test.start}.
*
* <p>
* From the test names, we generate a tree of {@link DynamicNode}s which queue an event and wait for
* {@code cct_test.submit} to be called. McFly pulls these events, executes the tests and then calls the submit method.
*
* <p>
* Once all tests are done, we invoke {@code cct_test.finish} in order to mark everything as complete.
*/
public class ComputerTestDelegate
{
private static final File REPORT_PATH = new File( "test-files/luacov.report.out" );
private static final Path REPORT_PATH = TestFiles.get( "luacov.report.out" );
private static final Logger LOG = LogManager.getLogger( ComputerTestDelegate.class );
@ -96,10 +97,10 @@ public void before() throws IOException
{
ComputerCraft.logComputerErrors = true;
if( REPORT_PATH.delete() ) ComputerCraft.log.info( "Deleted previous coverage report." );
if( Files.deleteIfExists( REPORT_PATH ) ) ComputerCraft.log.info( "Deleted previous coverage report." );
Terminal term = new Terminal( 80, 100, true );
IWritableMount mount = new FileMount( new File( "test-files/mount" ), 10_000_000 );
IWritableMount mount = new FileMount( TestFiles.get( "mount" ).toFile(), 10_000_000 );
// Remove any existing files
List<String> children = new ArrayList<>();
@ -161,8 +162,8 @@ public void after() throws InterruptedException, IOException
if( finishedWith != null )
{
REPORT_PATH.getParentFile().mkdirs();
try( BufferedWriter writer = Files.newBufferedWriter( REPORT_PATH.toPath() ) )
Files.createDirectories( REPORT_PATH.getParent() );
try( BufferedWriter writer = Files.newBufferedWriter( REPORT_PATH ) )
{
new LuaCoverage( finishedWith ).write( writer );
}

View File

@ -10,6 +10,7 @@
import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.core.apis.ObjectWrapper;
import dan200.computercraft.core.apis.handles.EncodedWritableHandle;
import dan200.computercraft.support.TestFiles;
import org.junit.jupiter.api.Test;
import java.io.BufferedWriter;
@ -22,7 +23,7 @@
public class FileSystemTest
{
private static final File ROOT = new File( "test-files/filesystem" );
private static final File ROOT = TestFiles.get( "filesystem" ).toFile();
private static final long CAPACITY = 1000000;
private static FileSystem mkFs() throws FileSystemException

View File

@ -7,6 +7,7 @@
import com.google.common.io.ByteStreams;
import dan200.computercraft.api.filesystem.IMount;
import dan200.computercraft.support.TestFiles;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@ -27,7 +28,7 @@
public class JarMountTest
{
private static final File ZIP_FILE = new File( "test-files/jar-mount.zip" );
private static final File ZIP_FILE = TestFiles.get( "jar-mount.zip" ).toFile();
private static final FileTime MODIFY_TIME = FileTime.from( Instant.EPOCH.plus( 2, ChronoUnit.DAYS ) );

View File

@ -0,0 +1,31 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.support;
import java.nio.file.Path;
import java.nio.file.Paths;
/**
* Location for temporary test files.
*/
public final class TestFiles
{
private static final Path ROOT = Paths.get( System.getProperty( "cct.test-files", "build/tmp/testFiles" ) );
private TestFiles()
{
}
public static Path get()
{
return ROOT;
}
public static Path get( String path )
{
return ROOT.resolve( path );
}
}