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

Move checkwhitespace to build.d #10448

Merged
merged 1 commit into from Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 50 additions & 7 deletions src/build.d
Expand Up @@ -20,6 +20,7 @@ import core.stdc.stdlib : exit;

const thisBuildScript = __FILE_FULL_PATH__;
const srcDir = thisBuildScript.dirName.buildNormalizedPath;
const dmdRepo = srcDir.dirName;
shared bool verbose; // output verbose logging
shared bool force; // always build everything (ignores timestamp checking)

Expand All @@ -33,6 +34,7 @@ immutable rootDeps = [
&runDmdUnittest,
&clean,
&dmdFrontend,
&checkwhitespace,
];

void main(string[] args)
Expand Down Expand Up @@ -286,7 +288,7 @@ alias versionFile = memoize!(function()
{
"(TX) VERSION".writeln;
string ver;
if (srcDir.dirName.buildPath(".git").exists)
if (dmdRepo.buildPath(".git").exists)
{
try
{
Expand All @@ -301,7 +303,7 @@ alias versionFile = memoize!(function()
}
// version fallback
if (ver.length == 0)
ver = srcDir.dirName.buildPath("VERSION").readText;
ver = dmdRepo.buildPath("VERSION").readText;
updateIfChanged(target, ver);
};
}
Expand Down Expand Up @@ -432,6 +434,50 @@ alias clean = memoize!(function()
return new DependencyRef(dep);
});

alias toolsRepo = memoize!(function()
{
Dependency dep;
with (dep)
{
commandFunction = ()
{
if (!env["TOOLS_DIR"].exists)
{
writefln("cloning tools repo to '%s'...", env["TOOLS_DIR"]);
run(["git", "clone", "--depth=1", env["GIT_HOME"] ~ "/tools", env["TOOLS_DIR"]]);
}
};
}
return new DependencyRef(dep);
});

alias checkwhitespace = memoize!(function()
{
Dependency dep;
with (dep)
{
name = "checkwhitespace";
description = "Checks for trailing whitespace and tabs";
deps = [toolsRepo];
commandFunction = ()
{
const cmdPrefix = [env["HOST_DMD_RUN"], "-run", env["TOOLS_DIR"].buildPath("checkwhitespace.d")];
const allSources = srcDir.dirEntries("*.{d,h,di}", SpanMode.depth).map!(e => e.name).array;
writefln("Checking whitespace on %s files...", allSources.length);
auto chunkLength = allSources.length;
version (Win32)
chunkLength = 80; // avoid command-line limit on win32
foreach (nextSources; allSources.chunks(chunkLength).parallel(1))
{
const nextCommand = cmdPrefix ~ nextSources;
writeln(nextCommand.join(" "));
run(nextCommand);
}
};
}
return new DependencyRef(dep);
});

/**
Goes through the target list and replaces short-hand targets with their expanded version.
Special targets:
Expand Down Expand Up @@ -487,10 +533,6 @@ LtargetsLoop:
"TODO: build-examples".writeln; // TODO
break;

case "checkwhitespace":
"TODO: checkwhitespace".writeln; // TODO
break;

case "html":
"TODO: html".writeln; // TODO
break;
Expand Down Expand Up @@ -638,9 +680,10 @@ void parseEnvironment()
env["C"] = d.buildPath("backend");
env["ROOT"] = d.buildPath("root");
env["EX"] = srcDir.buildPath("examples");
auto generated = env["GENERATED"] = srcDir.dirName.buildPath("generated");
auto generated = env["GENERATED"] = dmdRepo.buildPath("generated");
auto g = env["G"] = generated.buildPath(os, build, model);
mkdirRecurse(g);
env.getDefault("TOOLS_DIR", dmdRepo.dirName.buildPath("tools"));

if (env.get("HOST_DMD", null).length == 0)
{
Expand Down
10 changes: 2 additions & 8 deletions src/posix.mak
Expand Up @@ -77,9 +77,6 @@ else
override PIC:=
endif

GIT_HOME=https://github.com/dlang
TOOLS_DIR=../../tools

INSTALL_DIR=../../install
SYSCONFDIR=/etc
TMP?=/tmp
Expand Down Expand Up @@ -517,11 +514,8 @@ install: all $(DMD_MAN_PAGE)

######################################################

checkwhitespace: $(HOST_DMD_PATH) $(TOOLS_DIR)/checkwhitespace.d
CC="$(HOST_CXX)" $(HOST_DMD_RUN) -run $(TOOLS_DIR)/checkwhitespace.d $(SRC) $(GLUE_SRC) $(ROOT_SRCS)

$(TOOLS_DIR)/checkwhitespace.d:
git clone --depth=1 ${GIT_HOME}/tools $(TOOLS_DIR)
checkwhitespace: $(GENERATED)/build
$(RUN_BUILD) $@

######################################################
# DScanner
Expand Down
11 changes: 2 additions & 9 deletions src/win32.mak
Expand Up @@ -75,9 +75,6 @@ G = $(GEN)\$(OS)\$(BUILD)\$(MODEL)

##### Tools

GIT_HOME=https://github.com/dlang
TOOLS_DIR=..\..\tools

# D compiler (set with env variable)
#HOST_DC=dmd
# Make program
Expand Down Expand Up @@ -367,12 +364,8 @@ pvs:
# $(PVS) --cfg PVS-Studio.cfg --cl-params /I$(ROOT) /Tp $(ROOTSRCC) --source-file $(ROOTSRCC)
# $(PVS) --cfg PVS-Studio.cfg --cl-params /I$C /Tp $(BACKSRC) --source-file $(BACKSRC)

checkwhitespace: $(TOOLS_DIR)\checkwhitespace.d
$(HOST_DC) -run $(TOOLS_DIR)\checkwhitespace $(SRCS) $(GLUESRC) $(ROOTSRC) $(BACKSRC)

# Extra test here, wine attempts to execute git even if file already exists
$(TOOLS_DIR)\checkwhitespace.d:
if not exist $(TOOLS_DIR)\checkwhitespace.d git clone --depth=1 $(GIT_HOME)/tools $(TOOLS_DIR)
checkwhitespace: $(GEN)\build.exe
$(RUN_BUILD) $@

######################################################

Expand Down