mirror of
https://github.com/rehlds/rehlds.git
synced 2025-01-06 12:05:34 +03:00
8aac19ce00
Refactored tests
389 lines
12 KiB
Groovy
389 lines
12 KiB
Groovy
import gradlecpp.RehldsPlayTestPlugin
|
|
import gradlecpp.RehldsPlayTestTask
|
|
import gradlecpp.VelocityUtils
|
|
import org.doomedsociety.gradlecpp.GradleCppUtils
|
|
import org.doomedsociety.gradlecpp.LazyNativeDepSet
|
|
import org.doomedsociety.gradlecpp.cfg.ToolchainConfig
|
|
import org.doomedsociety.gradlecpp.cfg.ToolchainConfigUtils
|
|
import org.doomedsociety.gradlecpp.gcc.GccToolchainConfig
|
|
import org.doomedsociety.gradlecpp.msvc.EnhancedInstructionsSet
|
|
import org.doomedsociety.gradlecpp.msvc.FloatingPointModel
|
|
import org.doomedsociety.gradlecpp.msvc.MsvcToolchainConfig
|
|
import org.doomedsociety.gradlecpp.toolchain.icc.Icc
|
|
import org.doomedsociety.gradlecpp.toolchain.icc.IccCompilerPlugin
|
|
import org.gradle.language.cpp.CppSourceSet
|
|
import org.gradle.nativeplatform.NativeBinarySpec
|
|
import org.gradle.nativeplatform.NativeExecutableSpec
|
|
import org.gradle.nativeplatform.NativeLibrarySpec
|
|
import org.gradle.nativeplatform.SharedLibraryBinarySpec
|
|
import rehlds.testdemo.RehldsDemoRunner
|
|
import versioning.RehldsVersionInfo
|
|
import org.apache.commons.io.FilenameUtils
|
|
|
|
apply plugin: 'cpp'
|
|
apply plugin: IccCompilerPlugin
|
|
apply plugin: RehldsPlayTestPlugin
|
|
apply plugin: gradlecpp.CppUnitTestPlugin
|
|
|
|
repositories {
|
|
maven {
|
|
url 'http://nexus.rehlds.org/nexus/content/repositories/rehlds-releases/'
|
|
}
|
|
}
|
|
|
|
configurations {
|
|
rehlds_tests
|
|
}
|
|
|
|
dependencies {
|
|
rehlds_tests 'rehlds.testdemos:hl-phys-single1:1.1'
|
|
rehlds_tests 'rehlds.testdemos:crossfire-1-multiplayer-1:1.1'
|
|
rehlds_tests 'rehlds.testdemos:cstrike-muliplayer-1:1.1'
|
|
rehlds_tests 'rehlds.testdemos:shooting-hl-1:1.1'
|
|
}
|
|
|
|
project.ext.dep_bzip2 = project(':dep/bzip2')
|
|
project.ext.dep_cppunitlite = project(':dep/cppunitlite')
|
|
|
|
void createIntergrationTestTask(NativeBinarySpec b) {
|
|
boolean rehldsFixes = b.flavor.name.contains('rehldsFixes')
|
|
|
|
if (!(b instanceof SharedLibraryBinarySpec)) return
|
|
if (!GradleCppUtils.windows) return
|
|
if (rehldsFixes) return
|
|
|
|
def libLinkTask = GradleCppUtils.getLinkTask(b)
|
|
String unitTestTask = b.hasProperty('cppUnitTestTask') ? b.cppUnitTestTask : null
|
|
|
|
def depFiles = []
|
|
depFiles.addAll(libLinkTask.outputs.files.files)
|
|
|
|
def demoItgTestTask = project.tasks.create(b.namingScheme.getTaskName('demoItgTest'), RehldsPlayTestTask)
|
|
demoItgTestTask.with {
|
|
rehldsImageRoot = new File(project.projectDir, '_rehldsTestImg')
|
|
rehldsTestLogs = new File(this.project.buildDir, "_rehldsTestLogs/${b.name}")
|
|
testDemos = project.configurations.rehlds_tests
|
|
testFor = b
|
|
|
|
//inputs/outputs for up-to-date check
|
|
inputs.files depFiles
|
|
inputs.files testDemos.files
|
|
outputs.dir rehldsTestLogs
|
|
|
|
//dependencies on library and test executable
|
|
dependsOn libLinkTask
|
|
if (unitTestTask) {
|
|
dependsOn unitTestTask
|
|
}
|
|
|
|
postExtractAction {
|
|
def binaryOutFile = GradleCppUtils.getBinaryOutputFile(b)
|
|
GradleCppUtils.copyFile(binaryOutFile, new File(rehldsImageRoot, binaryOutFile.name), true)
|
|
}
|
|
}
|
|
|
|
b.buildTask.dependsOn demoItgTestTask
|
|
}
|
|
|
|
void setupUnitTests(NativeBinarySpec bin) {
|
|
boolean unitTestExecutable = bin.component.name.endsWith('_tests')
|
|
if (!unitTestExecutable) return
|
|
|
|
GradleCppUtils.getLinkTask(bin).doLast {
|
|
String srcPath = '' + projectDir + (GradleCppUtils.windows ? '/lib/steam_api.dll' : '/lib/linux32/libsteam_api.so')
|
|
String dstPath = bin.executableFile.parent + (GradleCppUtils.windows ? '/steam_api.dll' : '/libsteam_api.so')
|
|
GradleCppUtils.copyFile(srcPath, dstPath, true)
|
|
}
|
|
}
|
|
|
|
void postEvaluate(NativeBinarySpec b) {
|
|
|
|
// attach generateAppVersion task to all 'compile source' tasks
|
|
GradleCppUtils.getCompileTasks(b).each { Task t ->
|
|
t.dependsOn project.generateAppVersion
|
|
}
|
|
|
|
setupUnitTests(b)
|
|
createIntergrationTestTask(b)
|
|
}
|
|
|
|
void setupToolchain(NativeBinarySpec b) {
|
|
boolean unitTestExecutable = b.component.name.endsWith('_tests')
|
|
boolean swdsLib = b.name.toLowerCase().contains('swds')
|
|
boolean rehldsFixes = b.flavor.name.contains('rehldsFixes')
|
|
|
|
ToolchainConfig cfg = rootProject.createToolchainConfig(b)
|
|
cfg.projectInclude(project, '', '/public/rehlds', '/engine', '/common', '/pm_shared', '/rehlds', '/testsuite', '/hookers', '/public')
|
|
cfg.projectInclude(dep_bzip2, '/include')
|
|
|
|
if (unitTestExecutable) {
|
|
cfg.projectInclude(dep_cppunitlite, '/include')
|
|
b.lib LazyNativeDepSet.create(dep_cppunitlite, 'cppunitlite', b.buildType.name, true)
|
|
}
|
|
b.lib LazyNativeDepSet.create(dep_bzip2, 'bzip2', b.buildType.name, true)
|
|
|
|
cfg.singleDefines 'USE_BREAKPAD_HANDLER', 'DEDICATED', 'SWDS', 'REHLDS_SELF', 'REHLDS_OPT_PEDANTIC', 'REHLDS_FLIGHT_REC'
|
|
|
|
if (cfg instanceof MsvcToolchainConfig) {
|
|
cfg.compilerOptions.pchConfig = new MsvcToolchainConfig.PrecompiledHeadersConfig(
|
|
enabled: true,
|
|
pchHeader: 'precompiled.h',
|
|
pchSourceSet: 'rehlds_pch'
|
|
)
|
|
cfg.singleDefines('_CRT_SECURE_NO_WARNINGS')
|
|
if (!rehldsFixes) {
|
|
cfg.compilerOptions.floatingPointModel = FloatingPointModel.PRECISE
|
|
cfg.compilerOptions.enhancedInstructionsSet = EnhancedInstructionsSet.DISABLED
|
|
}
|
|
if (swdsLib) {
|
|
cfg.linkerOptions.randomizedBaseAddress = false
|
|
cfg.linkerOptions.baseAddress = '0x4970000'
|
|
}
|
|
cfg.projectLibpath(project, '/lib')
|
|
cfg.extraLibs 'steam_api.lib', 'psapi.lib', 'ws2_32.lib', 'kernel32.lib', 'user32.lib', 'advapi32.lib'
|
|
} else if (cfg instanceof GccToolchainConfig) {
|
|
cfg.compilerOptions.pchConfig = new GccToolchainConfig.PrecompilerHeaderOptions(
|
|
enabled: true,
|
|
pchSourceSet: 'rehlds_pch'
|
|
)
|
|
cfg.compilerOptions.languageStandard = 'c++0x'
|
|
cfg.defines([
|
|
'_stricmp': 'strcasecmp',
|
|
'_strnicmp': 'strncasecmp',
|
|
'_strdup': 'strdup',
|
|
'_unlink': 'unlink',
|
|
'_vsnprintf': 'vsnprintf',
|
|
])
|
|
cfg.compilerOptions.args '-Qoption,cpp,--treat_func_as_string_literal_cpp'
|
|
cfg.projectLibpath(project, '/lib/linux32')
|
|
cfg.extraLibs 'rt', 'dl', 'm', 'steam_api'
|
|
}
|
|
|
|
if (!unitTestExecutable && !swdsLib) {
|
|
cfg.singleDefines 'HOOK_ENGINE'
|
|
}
|
|
|
|
if (unitTestExecutable) {
|
|
cfg.singleDefines 'REHLDS_UNIT_TESTS'
|
|
}
|
|
|
|
if (rehldsFixes) {
|
|
cfg.singleDefines 'REHLDS_FIXES', 'REHLDS_CHECKS'
|
|
}
|
|
|
|
ToolchainConfigUtils.apply(project, cfg, b)
|
|
|
|
GradleCppUtils.onTasksCreated(project, 'postEvaluate', {
|
|
postEvaluate(b)
|
|
})
|
|
}
|
|
|
|
class RehldsSrc {
|
|
static void rehlds_src(def h) {
|
|
h.rehlds_src(CppSourceSet) {
|
|
source {
|
|
srcDirs "engine", "rehlds", "public", "version"
|
|
if (GradleCppUtils.windows) srcDirs "testsuite"
|
|
|
|
include "**/*.cpp"
|
|
exclude "precompiled.cpp"
|
|
exclude GradleCppUtils.windows ? "tier0/platform_linux.cpp" : "tier0/platform_win32.cpp"
|
|
exclude "interface.cpp", "rehlds/crc32c.cpp", "rehlds/sys_shared.cpp"
|
|
}
|
|
|
|
source {
|
|
srcDirs "hookers"
|
|
include "**/*.cpp"
|
|
exclude "6132_hooker.cpp", "hooker.cpp", "main.cpp", "main_swds.cpp"
|
|
if (!GradleCppUtils.windows) exclude "rehlds_debug.cpp"
|
|
}
|
|
}
|
|
}
|
|
|
|
static void rehlds_pch(def h) {
|
|
h.rehlds_pch(CppSourceSet) {
|
|
source {
|
|
srcDirs "rehlds"
|
|
include "precompiled.cpp"
|
|
}
|
|
}
|
|
}
|
|
|
|
static void rehlds_hooker_src(def h) {
|
|
h.rehlds_hooker_src(CppSourceSet) {
|
|
source {
|
|
srcDirs "hookers"
|
|
include "6132_hooker.cpp", "hooker.cpp"
|
|
}
|
|
}
|
|
}
|
|
|
|
static void rehlds_hooker_main_src(def h) {
|
|
h.rehlds_hooker_main_src(CppSourceSet) {
|
|
source {
|
|
srcDirs "hookers"
|
|
include "main.cpp"
|
|
}
|
|
}
|
|
}
|
|
|
|
static void rehlds_swds_main_src(def h) {
|
|
h.rehlds_swds_main_src(CppSourceSet) {
|
|
source {
|
|
srcDirs "hookers"
|
|
include "main_swds.cpp"
|
|
}
|
|
}
|
|
}
|
|
|
|
static void rehlds_tests_src(def h) {
|
|
h.rehlds_tests_src(CppSourceSet) {
|
|
source {
|
|
srcDir "unittests"
|
|
include "**/*.cpp"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
model {
|
|
buildTypes {
|
|
debug
|
|
release
|
|
}
|
|
|
|
platforms {
|
|
x86 {
|
|
architecture "x86"
|
|
}
|
|
}
|
|
|
|
toolChains {
|
|
visualCpp(VisualCpp) {
|
|
}
|
|
icc(Icc) {
|
|
}
|
|
}
|
|
|
|
flavors {
|
|
rehldsNofixes
|
|
rehldsFixes
|
|
}
|
|
|
|
components {
|
|
rehlds_hooker_engine(NativeLibrarySpec) {
|
|
targetPlatform 'x86'
|
|
baseName 'FileSystem_Stdio'
|
|
|
|
sources {
|
|
RehldsSrc.rehlds_pch(it)
|
|
RehldsSrc.rehlds_src(it)
|
|
RehldsSrc.rehlds_hooker_src(it)
|
|
RehldsSrc.rehlds_hooker_main_src(it)
|
|
}
|
|
|
|
binaries.all { NativeBinarySpec b -> project.setupToolchain(b) }
|
|
}
|
|
|
|
rehlds_swds_engine(NativeLibrarySpec) {
|
|
targetPlatform 'x86'
|
|
baseName GradleCppUtils.windows ? 'swds' : 'engine_i486'
|
|
|
|
sources {
|
|
RehldsSrc.rehlds_pch(it)
|
|
RehldsSrc.rehlds_src(it)
|
|
RehldsSrc.rehlds_swds_main_src(it)
|
|
}
|
|
|
|
binaries.all { NativeBinarySpec b -> project.setupToolchain(b) }
|
|
}
|
|
|
|
rehlds_hooker_engine_tests(NativeExecutableSpec) {
|
|
targetPlatform 'x86'
|
|
sources {
|
|
RehldsSrc.rehlds_pch(it)
|
|
RehldsSrc.rehlds_src(it)
|
|
RehldsSrc.rehlds_tests_src(it)
|
|
}
|
|
|
|
binaries.all { NativeBinarySpec b -> project.setupToolchain(b) }
|
|
}
|
|
|
|
rehlds_swds_engine_tests(NativeExecutableSpec) {
|
|
targetPlatform 'x86'
|
|
sources {
|
|
RehldsSrc.rehlds_pch(it)
|
|
RehldsSrc.rehlds_src(it)
|
|
RehldsSrc.rehlds_tests_src(it)
|
|
}
|
|
|
|
binaries.all { NativeBinarySpec b -> project.setupToolchain(b) }
|
|
}
|
|
}
|
|
}
|
|
|
|
task buildRelease {
|
|
dependsOn binaries.withType(SharedLibraryBinarySpec).matching { SharedLibraryBinarySpec blib ->
|
|
blib.buildable && blib.buildType.name == 'release' && !blib.name.contains('Rehlds_hooker_engine')
|
|
}
|
|
}
|
|
|
|
|
|
task prepareDevEnvTests {
|
|
def rehldsTests = new File(project.projectDir, '_dev/testDemos')
|
|
|
|
inputs.files configurations.rehlds_tests.files
|
|
outputs.dir rehldsTests
|
|
|
|
doLast {
|
|
rehldsTests.mkdirs()
|
|
configurations.rehlds_tests.files.each { File f ->
|
|
def t = zipTree(f)
|
|
copy {
|
|
into new File(rehldsTests, FilenameUtils.getBaseName(f.absolutePath))
|
|
from t
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
task prepareDevEnvEngine << {
|
|
['_dev/rehlds', '_dev/rehlds_swds'].each { engineDir ->
|
|
def rehldsImage = new File(project.projectDir, engineDir)
|
|
rehldsImage.mkdirs()
|
|
def demoRunner = new RehldsDemoRunner(project.configurations.rehlds_playtest_image.getFiles(), rehldsImage, null)
|
|
demoRunner.prepareEngine()
|
|
}
|
|
}
|
|
|
|
task prepareDevEnv {
|
|
dependsOn prepareDevEnvEngine, prepareDevEnvTests
|
|
}
|
|
|
|
tasks.clean.doLast {
|
|
project.file('version/appversion.h').delete()
|
|
}
|
|
|
|
task generateAppVersion {
|
|
RehldsVersionInfo verInfo = (RehldsVersionInfo) rootProject.rehldsVersionInfo
|
|
def tplFile = project.file('version/appversion.vm')
|
|
def renderedFile = project.file('version/appversion.h')
|
|
|
|
inputs.file tplFile
|
|
inputs.file project.file('gradle.properties')
|
|
outputs.file renderedFile
|
|
inputs.property('version', verInfo.asMavenVersion())
|
|
inputs.property('lastCommitDate', verInfo.lastCommitDate.toString())
|
|
|
|
doLast {
|
|
def templateCtx = [
|
|
verInfo : verInfo
|
|
]
|
|
|
|
def content = VelocityUtils.renderTemplate(tplFile, templateCtx)
|
|
renderedFile.delete()
|
|
renderedFile.write(content, 'utf-8')
|
|
}
|
|
}
|