summaryrefslogtreecommitdiffstats
path: root/qmake/main.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2017-02-24 16:22:53 +0100
committerSimon Hausmann <simon.hausmann@qt.io>2017-04-12 15:50:51 +0000
commit2ad7f6ddf5042d7442c97a89b083ca2853cf5721 (patch)
tree55eb85622019b54f09d01d96d608744c4c512efb /qmake/main.cpp
parent7f29367c09d069958e0e9fb539ee88df04877b7e (diff)
Preserve last modification timestamps of installed files
On non-windows platforms, we use the "-p" parameter of install(1) to preserve the last modification timestamps of files. On Windows the use of copy does not preserve them. As a cross-platform solution, this patch introduces a simple built-in install command in qmake to copy files. Task-number: QTBUG-59004 Change-Id: I3064d29a2b8c7b009a1efbf8f00b84c079ea5417 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
Diffstat (limited to 'qmake/main.cpp')
-rw-r--r--qmake/main.cpp57
1 files changed, 56 insertions, 1 deletions
diff --git a/qmake/main.cpp b/qmake/main.cpp
index 6d7e023b41..0b0b5ff128 100644
--- a/qmake/main.cpp
+++ b/qmake/main.cpp
@@ -47,6 +47,8 @@
# include <qt_windows.h>
#endif
+using namespace QMakeInternal;
+
QT_BEGIN_NAMESPACE
#ifdef Q_OS_WIN
@@ -232,20 +234,73 @@ static int doLink(int argc, char **argv)
return 0;
}
+#endif
+
+static int installFile(const QString &source, const QString &targetFileOrDirectory)
+{
+ QFile sourceFile(source);
+
+ QString target(targetFileOrDirectory);
+ if (QFileInfo(target).isDir())
+ target += QDir::separator() + QFileInfo(sourceFile.fileName()).fileName();
+
+ if (QFile::exists(target))
+ QFile::remove(target);
+
+ QDir::root().mkpath(QFileInfo(target).absolutePath());
+
+ if (!sourceFile.copy(target)) {
+ fprintf(stderr, "Error copying %s to %s: %s\n", source.toLatin1().constData(), qPrintable(target), qPrintable(sourceFile.errorString()));
+ return 3;
+ }
+ // Copy file times
+ QString error;
+ if (!IoUtils::touchFile(target, sourceFile.fileName(), &error)) {
+ fprintf(stderr, "%s", qPrintable(error));
+ return 3;
+ }
+ return 0;
+}
+
+static int doQInstall(int argc, char **argv)
+{
+ if (argc != 3) {
+ fprintf(stderr, "Error: this qinstall command requires exactly three arguments (type, source, destination)\n");
+ return 3;
+ }
+
+ const QString source = QString::fromLocal8Bit(argv[1]);
+ const QString target = QString::fromLocal8Bit(argv[2]);
+
+ if (!strcmp(argv[0], "file"))
+ return installFile(source, target);
+
+ fprintf(stderr, "Error: Unsupported qinstall command type %s\n", argv[0]);
+ return 3;
+}
+
+
static int doInstall(int argc, char **argv)
{
if (!argc) {
fprintf(stderr, "Error: -install requires further arguments\n");
return 3;
}
+#ifdef Q_OS_WIN
if (!strcmp(argv[0], "sed"))
return doSed(argc - 1, argv + 1);
if (!strcmp(argv[0], "ln"))
return doLink(argc - 1, argv + 1);
+#endif
+ if (!strcmp(argv[0], "qinstall"))
+ return doQInstall(argc - 1, argv + 1);
fprintf(stderr, "Error: unrecognized -install subcommand '%s'\n", argv[0]);
return 3;
}
+
+#ifdef Q_OS_WIN
+
static int dumpMacros(const wchar_t *cmdline)
{
// from http://stackoverflow.com/questions/3665537/how-to-find-out-cl-exes-built-in-macros
@@ -300,11 +355,11 @@ int runQMake(int argc, char **argv)
// This is particularly important for things like QtCreator and scripted builds.
setvbuf(stdout, (char *)NULL, _IONBF, 0);
-#ifdef Q_OS_WIN
// Workaround for inferior/missing command line tools on Windows: make our own!
if (argc >= 2 && !strcmp(argv[1], "-install"))
return doInstall(argc - 2, argv + 2);
+#ifdef Q_OS_WIN
{
// Support running as Visual C++'s compiler
const wchar_t *cmdline = _wgetenv(L"MSC_CMD_FLAGS");