Skip to content

Commit

Permalink
Merge pull request #10448 from marler8997/whitespaceBuildD
Browse files Browse the repository at this point in the history
Move checkwhitespace to build.d
merged-on-behalf-of: Sebastian Wilzbach <sebi.wilzbach@gmail.com>
  • Loading branch information
dlang-bot committed Oct 22, 2019
2 parents dd0afe4 + 469682f commit 9e561f4
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 24 deletions.
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)
shared bool dryRun; /// dont execute targets, just print command to be executed
Expand All @@ -34,6 +35,7 @@ immutable rootDeps = [
&runDmdUnittest,
&clean,
&dmdFrontend,
&checkwhitespace,
];

void main(string[] args)
Expand Down Expand Up @@ -288,7 +290,7 @@ alias versionFile = memoize!(function()
commandFunction = ()
{
string ver;
if (srcDir.dirName.buildPath(".git").exists)
if (dmdRepo.buildPath(".git").exists)
{
try
{
Expand All @@ -303,7 +305,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 @@ -434,6 +436,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 @@ -489,10 +535,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 @@ -640,9 +682,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

0 comments on commit 9e561f4

Please sign in to comment.