forked from qt-creator/qt-creator
qmake: Preserve last modification timestamps of installed files
sync-up with qmake; no effect on creator. Change-Id: I3064d29a2b8c7b009a1efbf8f00b84c079ea5417 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io> (cherry picked from qtbase/2ad7f6ddf5042d7442c97a89b083ca2853cf5721) Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io> Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
committed by
Oswald Buddenhagen
parent
6bee0b695d
commit
fe70177c17
@@ -35,8 +35,13 @@
|
|||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
# include <sys/stat.h>
|
# include <sys/stat.h>
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
|
# include <utime.h>
|
||||||
|
# include <fcntl.h>
|
||||||
|
# include <errno.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define fL1S(s) QString::fromLatin1(s)
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
using namespace QMakeInternal;
|
using namespace QMakeInternal;
|
||||||
@@ -181,4 +186,69 @@ QString IoUtils::shellQuoteWin(const QString &arg)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(PROEVALUATOR_FULL)
|
||||||
|
|
||||||
|
# if defined(Q_OS_WIN)
|
||||||
|
static QString windowsErrorCode()
|
||||||
|
{
|
||||||
|
wchar_t *string = 0;
|
||||||
|
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
|
||||||
|
NULL,
|
||||||
|
GetLastError(),
|
||||||
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||||
|
(LPWSTR)&string,
|
||||||
|
0,
|
||||||
|
NULL);
|
||||||
|
QString ret = QString::fromWCharArray(string);
|
||||||
|
LocalFree((HLOCAL)string);
|
||||||
|
return ret.trimmed();
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
|
bool IoUtils::touchFile(const QString &targetFileName, const QString &referenceFileName, QString *errorString)
|
||||||
|
{
|
||||||
|
# ifdef Q_OS_UNIX
|
||||||
|
struct stat st;
|
||||||
|
if (stat(referenceFileName.toLocal8Bit().constData(), &st)) {
|
||||||
|
*errorString = fL1S("Cannot stat() reference file %1: %2.").arg(referenceFileName, fL1S(strerror(errno)));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
# if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200809L
|
||||||
|
const struct timespec times[2] = { { 0, UTIME_NOW }, st.st_mtim };
|
||||||
|
const bool utimeError = utimensat(AT_FDCWD, targetFileName.toLocal8Bit().constData(), times, 0) < 0;
|
||||||
|
# else
|
||||||
|
struct utimbuf utb;
|
||||||
|
utb.actime = time(0);
|
||||||
|
utb.modtime = st.st_mtime;
|
||||||
|
const bool utimeError= utime(targetFileName.toLocal8Bit().constData(), &utb) < 0;
|
||||||
|
# endif
|
||||||
|
if (utimeError) {
|
||||||
|
*errorString = fL1S("Cannot touch %1: %2.").arg(targetFileName, fL1S(strerror(errno)));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
# else
|
||||||
|
HANDLE rHand = CreateFile((wchar_t*)referenceFileName.utf16(),
|
||||||
|
GENERIC_READ, FILE_SHARE_READ,
|
||||||
|
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
|
if (rHand == INVALID_HANDLE_VALUE) {
|
||||||
|
*errorString = fL1S("Cannot open reference file %1: %2").arg(referenceFileName, windowsErrorCode());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
FILETIME ft;
|
||||||
|
GetFileTime(rHand, 0, 0, &ft);
|
||||||
|
CloseHandle(rHand);
|
||||||
|
HANDLE wHand = CreateFile((wchar_t*)targetFileName.utf16(),
|
||||||
|
GENERIC_WRITE, FILE_SHARE_READ,
|
||||||
|
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
|
if (wHand == INVALID_HANDLE_VALUE) {
|
||||||
|
*errorString = fL1S("Cannot open %1: %2").arg(targetFileName, windowsErrorCode());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
SetFileTime(wHand, 0, 0, &ft);
|
||||||
|
CloseHandle(wHand);
|
||||||
|
# endif
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
@@ -60,6 +60,9 @@ public:
|
|||||||
#else
|
#else
|
||||||
{ return shellQuoteWin(arg); }
|
{ return shellQuoteWin(arg); }
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(PROEVALUATOR_FULL)
|
||||||
|
static bool touchFile(const QString &targetFileName, const QString &referenceFileName, QString *errorString);
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ProFileEvaluatorInternal
|
} // namespace ProFileEvaluatorInternal
|
||||||
|
@@ -52,9 +52,7 @@
|
|||||||
|
|
||||||
#ifdef Q_OS_UNIX
|
#ifdef Q_OS_UNIX
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <utime.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
@@ -253,23 +251,6 @@ QMakeEvaluator::getMemberArgs(const ProKey &func, int srclen, const ProStringLis
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(Q_OS_WIN) && defined(PROEVALUATOR_FULL)
|
|
||||||
static QString windowsErrorCode()
|
|
||||||
{
|
|
||||||
wchar_t *string = 0;
|
|
||||||
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
|
|
||||||
NULL,
|
|
||||||
GetLastError(),
|
|
||||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
|
||||||
(LPWSTR)&string,
|
|
||||||
0,
|
|
||||||
NULL);
|
|
||||||
QString ret = QString::fromWCharArray(string);
|
|
||||||
LocalFree((HLOCAL)string);
|
|
||||||
return ret.trimmed();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
QString
|
QString
|
||||||
QMakeEvaluator::quoteValue(const ProString &val)
|
QMakeEvaluator::quoteValue(const ProString &val)
|
||||||
{
|
{
|
||||||
@@ -1823,46 +1804,11 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
|
|||||||
#ifdef PROEVALUATOR_FULL
|
#ifdef PROEVALUATOR_FULL
|
||||||
const QString &tfn = resolvePath(args.at(0).toQString(m_tmp1));
|
const QString &tfn = resolvePath(args.at(0).toQString(m_tmp1));
|
||||||
const QString &rfn = resolvePath(args.at(1).toQString(m_tmp2));
|
const QString &rfn = resolvePath(args.at(1).toQString(m_tmp2));
|
||||||
#ifdef Q_OS_UNIX
|
QString error;
|
||||||
struct stat st;
|
if (!IoUtils::touchFile(tfn, rfn, &error)) {
|
||||||
if (stat(rfn.toLocal8Bit().constData(), &st)) {
|
evalError(error);
|
||||||
evalError(fL1S("Cannot stat() reference file %1: %2.").arg(rfn, fL1S(strerror(errno))));
|
|
||||||
return ReturnFalse;
|
return ReturnFalse;
|
||||||
}
|
}
|
||||||
#if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200809L
|
|
||||||
const struct timespec times[2] = { { 0, UTIME_NOW }, st.st_mtim };
|
|
||||||
const bool utimeError = utimensat(AT_FDCWD, tfn.toLocal8Bit().constData(), times, 0) < 0;
|
|
||||||
#else
|
|
||||||
struct utimbuf utb;
|
|
||||||
utb.actime = time(0);
|
|
||||||
utb.modtime = st.st_mtime;
|
|
||||||
const bool utimeError = utime(tfn.toLocal8Bit().constData(), &utb) < 0;
|
|
||||||
#endif
|
|
||||||
if (utimeError) {
|
|
||||||
evalError(fL1S("Cannot touch %1: %2.").arg(tfn, fL1S(strerror(errno))));
|
|
||||||
return ReturnFalse;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
HANDLE rHand = CreateFile((wchar_t*)rfn.utf16(),
|
|
||||||
GENERIC_READ, FILE_SHARE_READ,
|
|
||||||
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
||||||
if (rHand == INVALID_HANDLE_VALUE) {
|
|
||||||
evalError(fL1S("Cannot open reference file %1: %2").arg(rfn, windowsErrorCode()));
|
|
||||||
return ReturnFalse;
|
|
||||||
}
|
|
||||||
FILETIME ft;
|
|
||||||
GetFileTime(rHand, 0, 0, &ft);
|
|
||||||
CloseHandle(rHand);
|
|
||||||
HANDLE wHand = CreateFile((wchar_t*)tfn.utf16(),
|
|
||||||
GENERIC_WRITE, FILE_SHARE_READ,
|
|
||||||
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
||||||
if (wHand == INVALID_HANDLE_VALUE) {
|
|
||||||
evalError(fL1S("Cannot open %1: %2").arg(tfn, windowsErrorCode()));
|
|
||||||
return ReturnFalse;
|
|
||||||
}
|
|
||||||
SetFileTime(wHand, 0, 0, &ft);
|
|
||||||
CloseHandle(wHand);
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
return ReturnTrue;
|
return ReturnTrue;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user