Fix compilers seeing empty input due to file system races (#4708). Part 2.

This commit is contained in:
Wilson Snyder 2023-11-22 05:18:13 -05:00
parent 1986e62477
commit fae7f11222
3 changed files with 18 additions and 12 deletions

View File

@ -305,14 +305,6 @@ void V3Os::filesystemFlush(const string& dirname) {
if (fd > 0) ::close(fd);
}
#else
{
// Linux kernel may not reread from NFS unless timestamp modified
struct timeval tv;
gettimeofday(&tv, NULL);
const int err = utimes(dirname.c_str(), &tv);
// Not an error
if (err != 0) UINFO(1, "-Info: File not statable: " << dirname << endl);
}
// Faster to just try both rather than check if a file is a dir.
if (DIR* const dirp = opendir(dirname.c_str())) { // LCOV_EXCL_BR_LINE
closedir(dirp); // LCOV_EXCL_LINE
@ -322,6 +314,19 @@ void V3Os::filesystemFlush(const string& dirname) {
#endif
}
void V3Os::filesystemFlushBuildDir(const string& dirname) {
// Attempt to force out written directory, for NFS like file systems.
#ifndef _MSC_VER
// Linux kernel may not reread from NFS unless timestamp modified
struct timeval tv;
gettimeofday(&tv, NULL);
const int err = utimes(dirname.c_str(), &tv);
// Not an error
if (err != 0) UINFO(1, "-Info: File not utimed: " << dirname << endl);
#endif
filesystemFlush(dirname);
}
void V3Os::unlinkRegexp(const string& dir, const string& regexp) {
#ifdef _MSC_VER
try {

View File

@ -64,6 +64,7 @@ public:
// METHODS (directory utilities)
static void createDir(const string& dirname);
static void filesystemFlush(const string& dirname);
static void filesystemFlushBuildDir(const string& dirname);
static void unlinkRegexp(const string& dir, const string& regexp);
// METHODS (random)

View File

@ -719,8 +719,8 @@ static void verilate(const string& argString) {
argString);
}
V3Os::filesystemFlush(v3Global.opt.makeDir());
if (v3Global.opt.hierTop()) V3Os::filesystemFlush(v3Global.opt.hierTopDataDir());
V3Os::filesystemFlushBuildDir(v3Global.opt.makeDir());
if (v3Global.opt.hierTop()) V3Os::filesystemFlushBuildDir(v3Global.opt.hierTopDataDir());
// Final writing shouldn't throw warnings, but...
V3Error::abortIfWarnings();
@ -752,7 +752,7 @@ static void execBuildJob() {
UINFO(1, "Start Build\n");
const string cmdStr = buildMakeCmd(v3Global.opt.prefix() + ".mk", "");
V3Os::filesystemFlush(v3Global.opt.hierTopDataDir());
V3Os::filesystemFlushBuildDir(v3Global.opt.hierTopDataDir());
const int exit_code = V3Os::system(cmdStr);
if (exit_code != 0) {
v3error(cmdStr << " exited with " << exit_code << std::endl);
@ -765,7 +765,7 @@ static void execHierVerilation() {
const string makefile = v3Global.opt.prefix() + "_hier.mk ";
const string target = v3Global.opt.build() ? " hier_build" : " hier_verilation";
const string cmdStr = buildMakeCmd(makefile, target);
V3Os::filesystemFlush(v3Global.opt.hierTopDataDir());
V3Os::filesystemFlushBuildDir(v3Global.opt.hierTopDataDir());
const int exit_code = V3Os::system(cmdStr);
if (exit_code != 0) {
v3error(cmdStr << " exited with " << exit_code << std::endl);