mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 13:10:12 +03:00
Move d_do_test unittest build+run from Makefile to run.d
AFAICT, the last piece missing from run.d to fully replace the compiler/test/Makefile.
This commit is contained in:
parent
cae656cb89
commit
d0ccbea626
2 changed files with 65 additions and 64 deletions
|
@ -107,22 +107,13 @@ ifeq ($(HOST_DMD),)
|
|||
endif
|
||||
endif
|
||||
|
||||
# Required version for -lowmem
|
||||
LOW_MEM_MIN_VERSION = v2.086.0
|
||||
VERSION = $(filter v2.%, $(shell $(HOST_DMD) --version 2>/dev/null))
|
||||
RUN_FLAGS = -g -i -Itools -version=NoMain
|
||||
|
||||
ifeq ($(VERSION),)
|
||||
# dmd was not found in $PATH
|
||||
USE_GENERATED=1
|
||||
endif
|
||||
|
||||
# Detect whether the host dmd satisfies MIN_VERSION
|
||||
ifeq ($(LOW_MEM_MIN_VERSION), $(firstword $(sort $(LOW_MEM_MIN_VERSION) $(VERSION))))
|
||||
# dmd found in $PATH is too old
|
||||
RUN_FLAGS := $(RUN_FLAGS) -lowmem
|
||||
endif
|
||||
|
||||
ifneq ($(USE_GENERATED),)
|
||||
# Use the generated dmd instead of the host compiler
|
||||
HOST_DMD=$(DMD)
|
||||
|
@ -218,17 +209,7 @@ start_all_tests: $(RUNNER)
|
|||
@echo "Running all tests"
|
||||
$(EXECUTE_RUNNER) all
|
||||
|
||||
$(RESULTS_DIR)/d_do_test$(EXE): tools/d_do_test.d tools/sanitize_json.d $(RESULTS_DIR)/.created
|
||||
@echo "Building d_do_test tool"
|
||||
@echo "OS: '$(OS)'"
|
||||
@echo "MODEL: '$(MODEL)'"
|
||||
@echo "PIC: '$(PIC_FLAG)'"
|
||||
$(RUN_HOST_DMD) $(MODEL_FLAG) $(PIC_FLAG) $(RUN_FLAGS) -unittest -run $<
|
||||
$(RUN_HOST_DMD) $(MODEL_FLAG) $(PIC_FLAG) $(RUN_FLAGS) -od$(RESULTS_DIR) -of$@ $<
|
||||
|
||||
# Build d_do_test here to run it's unittests
|
||||
# TODO: Migrate this to run.d
|
||||
$(RUNNER): run.d $(RESULTS_DIR)/d_do_test$(EXE)
|
||||
$(RUNNER): run.d
|
||||
$(RUN_HOST_DMD) $(MODEL_FLAG) $(PIC_FLAG) -g -od$(RESULTS_DIR) -of$(RUNNER) -i -release $<
|
||||
|
||||
# run.d is not reentrant because each invocation might attempt to build the required tools
|
||||
|
|
|
@ -48,24 +48,29 @@ immutable slowRunnableTests = [
|
|||
|
||||
enum toolsDir = testPath("tools");
|
||||
|
||||
enum TestTools
|
||||
{
|
||||
unitTestRunner = TestTool("unit_test_runner", [toolsDir.buildPath("paths")]),
|
||||
testRunner = TestTool("d_do_test", ["-I" ~ toolsDir, "-i", "-version=NoMain"]),
|
||||
jsonSanitizer = TestTool("sanitize_json"),
|
||||
dshellPrebuilt = TestTool("dshell_prebuilt", null, Yes.linksWithTests),
|
||||
}
|
||||
enum TestTool unitTestRunner = { name: "unit_test_runner", extraArgs: [toolsDir.buildPath("paths")] };
|
||||
enum TestTool testRunner = { name: "d_do_test", extraArgs: ["-I" ~ toolsDir, "-i", "-version=NoMain"] };
|
||||
enum TestTool testRunnerUnittests = { name: "d_do_test-ut",
|
||||
customSourceFile: toolsDir.buildPath("d_do_test.d"),
|
||||
extraArgs: testRunner.extraArgs ~ ["-g", "-unittest"],
|
||||
runAfterBuild: true };
|
||||
enum TestTool jsonSanitizer = { name: "sanitize_json" };
|
||||
enum TestTool dshellPrebuilt = { name: "dshell_prebuilt", linksWithTests: true };
|
||||
|
||||
immutable struct TestTool
|
||||
{
|
||||
/// The name of the tool.
|
||||
string name;
|
||||
|
||||
string customSourceFile;
|
||||
|
||||
/// Extra arguments that should be supplied to the compiler when compiling the tool.
|
||||
string[] extraArgs;
|
||||
|
||||
/// Indicates the tool is a binary that links with tests
|
||||
Flag!"linksWithTests" linksWithTests;
|
||||
bool linksWithTests;
|
||||
|
||||
bool runAfterBuild;
|
||||
|
||||
alias name this;
|
||||
}
|
||||
|
@ -144,11 +149,11 @@ Options:
|
|||
|
||||
if (runUnitTests)
|
||||
{
|
||||
ensureToolsExists(env, TestTools.unitTestRunner);
|
||||
ensureToolsExists(env, unitTestRunner);
|
||||
return spawnProcess(unitTestRunnerCommand ~ args, env, Config.none, scriptDir).wait();
|
||||
}
|
||||
|
||||
ensureToolsExists(env, EnumMembers!TestTools);
|
||||
ensureToolsExists(env, unitTestRunner, testRunner, testRunnerUnittests, jsonSanitizer, dshellPrebuilt);
|
||||
|
||||
if (args == ["tools"])
|
||||
return 0;
|
||||
|
@ -265,55 +270,70 @@ void ensureToolsExists(const string[string] env, const TestTool[] tools ...)
|
|||
foreach (tool; tools.parallel(1))
|
||||
{
|
||||
string targetBin;
|
||||
string sourceFile;
|
||||
string sourceFile = tool.customSourceFile;
|
||||
if (tool.linksWithTests)
|
||||
{
|
||||
targetBin = resultsDir.buildPath(tool).objName;
|
||||
sourceFile = toolsDir.buildPath(tool, tool ~ ".d");
|
||||
if (sourceFile is null)
|
||||
sourceFile = toolsDir.buildPath(tool, tool ~ ".d");
|
||||
}
|
||||
else
|
||||
{
|
||||
targetBin = resultsDir.buildPath(tool).exeName;
|
||||
sourceFile = toolsDir.buildPath(tool ~ ".d");
|
||||
if (sourceFile is null)
|
||||
sourceFile = toolsDir.buildPath(tool ~ ".d");
|
||||
}
|
||||
if (targetBin.timeLastModified.ifThrown(SysTime.init) >= sourceFile.timeLastModified)
|
||||
{
|
||||
log("%s is already up-to-date", tool);
|
||||
continue;
|
||||
}
|
||||
|
||||
string[] buildCommand;
|
||||
bool overrideEnv;
|
||||
if (tool.linksWithTests)
|
||||
{
|
||||
// This will compile the dshell library thus needs the actual
|
||||
// DMD compiler under test
|
||||
buildCommand = [
|
||||
env["DMD"],
|
||||
"-conf=",
|
||||
"-m"~env["MODEL"],
|
||||
"-of" ~ targetBin,
|
||||
"-c",
|
||||
sourceFile
|
||||
] ~ getPicFlags(env);
|
||||
overrideEnv = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] command;
|
||||
bool overrideEnv;
|
||||
if (tool.linksWithTests)
|
||||
{
|
||||
// This will compile the dshell library thus needs the actual
|
||||
// DMD compiler under test
|
||||
command = [
|
||||
env["DMD"],
|
||||
"-conf=",
|
||||
"-m"~env["MODEL"],
|
||||
"-of" ~ targetBin,
|
||||
"-c",
|
||||
sourceFile
|
||||
] ~ getPicFlags(env);
|
||||
overrideEnv = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
string model = env["MODEL"];
|
||||
if (model == "32omf") model = "32";
|
||||
string model = env["MODEL"];
|
||||
if (model == "32omf") model = "32";
|
||||
|
||||
command = [
|
||||
hostDMD,
|
||||
"-m"~model,
|
||||
"-of"~targetBin,
|
||||
sourceFile
|
||||
] ~ getPicFlags(env) ~ tool.extraArgs;
|
||||
}
|
||||
buildCommand = [
|
||||
hostDMD,
|
||||
"-m"~model,
|
||||
"-of"~targetBin,
|
||||
sourceFile
|
||||
] ~ getPicFlags(env) ~ tool.extraArgs;
|
||||
}
|
||||
|
||||
writefln("Executing: %-(%s %)", command);
|
||||
writefln("Executing: %-(%s %)", buildCommand);
|
||||
stdout.flush();
|
||||
if (spawnProcess(buildCommand, overrideEnv ? env : null).wait)
|
||||
{
|
||||
stderr.writefln("failed to build '%s'", targetBin);
|
||||
atomicOp!"+="(failCount, 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tool.runAfterBuild)
|
||||
{
|
||||
writefln("Executing: %s", targetBin);
|
||||
stdout.flush();
|
||||
if (spawnProcess(command, overrideEnv ? env : null).wait)
|
||||
if (spawnProcess([targetBin], null).wait)
|
||||
{
|
||||
stderr.writefln("failed to build '%s'", targetBin);
|
||||
stderr.writefln("'%s' failed", targetBin);
|
||||
atomicOp!"+="(failCount, 1);
|
||||
}
|
||||
}
|
||||
|
@ -386,7 +406,7 @@ Target[] predefinedTargets(string[] targets)
|
|||
Target target = {
|
||||
filename: filename,
|
||||
args: [
|
||||
resultsDir.buildPath(TestTools.testRunner.name.exeName),
|
||||
resultsDir.buildPath(testRunner.name.exeName),
|
||||
Target.normalizedTestName(filename)
|
||||
]
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue