summaryrefslogtreecommitdiffstats
path: root/qmake/main.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@theqtcompany.com>2015-06-03 10:23:56 +0200
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-06-03 10:23:56 +0200
commite2f66f921594b7be4af4a058c959557489e86879 (patch)
treecc44931708b57bd5a761906797c7dee0360d1d6b /qmake/main.cpp
parent933bf178aab88ab5df8a68cbf02611d6d8744b1b (diff)
parent754efa57d89c62d1796e01b407e9222e67450f52 (diff)
Merge remote-tracking branch 'origin/5.5' into dev
Conflicts: src/corelib/global/qnamespace.qdoc src/corelib/io/qwindowspipereader.cpp src/corelib/io/qwindowspipereader_p.h src/corelib/statemachine/qstatemachine.cpp src/corelib/statemachine/qstatemachine_p.h src/plugins/platforms/xcb/qxcbconnection.h tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp tests/auto/tools/qmake/tst_qmake.cpp tests/manual/touch/main.cpp Change-Id: I917d694890e79ee3da7d65134b5b085e23e0dd62
Diffstat (limited to 'qmake/main.cpp')
-rw-r--r--qmake/main.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/qmake/main.cpp b/qmake/main.cpp
index 27969932bc..bde537dcca 100644
--- a/qmake/main.cpp
+++ b/qmake/main.cpp
@@ -163,6 +163,75 @@ static int doSed(int argc, char **argv)
return 0;
}
+static int doLink(int argc, char **argv)
+{
+ bool isSymlink = false;
+ bool force = false;
+ QList<const char *> inFiles;
+ for (int i = 0; i < argc; i++) {
+ if (!strcmp(argv[i], "-s")) {
+ isSymlink = true;
+ } else if (!strcmp(argv[i], "-f")) {
+ force = true;
+ } else if (argv[i][0] == '-') {
+ fprintf(stderr, "Error: unrecognized ln option '%s'\n", argv[i]);
+ return 3;
+ } else {
+ inFiles << argv[i];
+ }
+ }
+ if (inFiles.size() != 2) {
+ fprintf(stderr, "Error: this ln requires exactly two file arguments\n");
+ return 3;
+ }
+ if (!isSymlink) {
+ fprintf(stderr, "Error: this ln supports faking symlinks only\n");
+ return 3;
+ }
+ QString target = QString::fromLocal8Bit(inFiles[0]);
+ QString linkname = QString::fromLocal8Bit(inFiles[1]);
+
+ QDir destdir;
+ QFileInfo tfi(target);
+ QFileInfo lfi(linkname);
+ if (lfi.isDir()) {
+ destdir.setPath(linkname);
+ lfi.setFile(destdir, tfi.fileName());
+ } else {
+ destdir.setPath(lfi.path());
+ }
+ if (!destdir.exists()) {
+ fprintf(stderr, "Error: destination directory %s does not exist\n", qPrintable(destdir.path()));
+ return 1;
+ }
+ tfi.setFile(destdir.absoluteFilePath(tfi.filePath()));
+ if (!tfi.exists()) {
+ fprintf(stderr, "Error: this ln does not support symlinking non-existing targets\n");
+ return 3;
+ }
+ if (tfi.isDir()) {
+ fprintf(stderr, "Error: this ln does not support symlinking directories\n");
+ return 3;
+ }
+ if (lfi.exists()) {
+ if (!force) {
+ fprintf(stderr, "Error: %s exists\n", qPrintable(lfi.filePath()));
+ return 1;
+ }
+ if (!QFile::remove(lfi.filePath())) {
+ fprintf(stderr, "Error: cannot overwrite %s\n", qPrintable(lfi.filePath()));
+ return 1;
+ }
+ }
+ if (!QFile::copy(tfi.filePath(), lfi.filePath())) {
+ fprintf(stderr, "Error: cannot copy %s to %s\n",
+ qPrintable(tfi.filePath()), qPrintable(lfi.filePath()));
+ return 1;
+ }
+
+ return 0;
+}
+
static int doInstall(int argc, char **argv)
{
if (!argc) {
@@ -171,6 +240,8 @@ static int doInstall(int argc, char **argv)
}
if (!strcmp(argv[0], "sed"))
return doSed(argc - 1, argv + 1);
+ if (!strcmp(argv[0], "ln"))
+ return doLink(argc - 1, argv + 1);
fprintf(stderr, "Error: unrecognized -install subcommand '%s'\n", argv[0]);
return 3;
}