summaryrefslogtreecommitdiffstats
path: root/src/tools/rcc
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/rcc')
-rw-r--r--src/tools/rcc/main.cpp58
-rw-r--r--src/tools/rcc/rcc.cpp7
-rw-r--r--src/tools/rcc/rcc.h1
3 files changed, 61 insertions, 5 deletions
diff --git a/src/tools/rcc/main.cpp b/src/tools/rcc/main.cpp
index 0eb6766b5a..ac87e48e39 100644
--- a/src/tools/rcc/main.cpp
+++ b/src/tools/rcc/main.cpp
@@ -99,6 +99,37 @@ int createProject(const QString &outFileName)
return 0;
}
+// Escapes a path for use in a Depfile (Makefile syntax)
+QString makefileEscape(const QString &filepath)
+{
+ // Always use forward slashes
+ QString result = QDir::cleanPath(filepath);
+ // Spaces are escaped with a backslash
+ result.replace(QLatin1Char(' '), QLatin1String("\\ "));
+ // Pipes are escaped with a backslash
+ result.replace(QLatin1Char('|'), QLatin1String("\\|"));
+ // Dollars are escaped with a dollar
+ result.replace(QLatin1Char('$'), QLatin1String("$$"));
+
+ return result;
+}
+
+void writeDepFile(QIODevice &iodev, const QStringList &depsList, const QString &targetName)
+{
+ QTextStream out(&iodev);
+ out << qPrintable(makefileEscape(targetName));
+ out << QLatin1Char(':');
+
+ // Write depfile
+ for (int i = 0; i < depsList.size(); ++i) {
+ out << QLatin1Char(' ');
+
+ out << qPrintable(makefileEscape(depsList.at(i)));
+ }
+
+ out << QLatin1Char('\n');
+}
+
int runRcc(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
@@ -176,6 +207,10 @@ int runRcc(int argc, char *argv[])
QStringLiteral("Only output a mapping of resource paths to file system paths defined in the .qrc file, do not generate code."));
parser.addOption(mapOption);
+ QCommandLineOption depFileOption(QStringList{QStringLiteral("d"), QStringLiteral("depfile")},
+ QStringLiteral("Write a depfile with the .qrc dependencies to <file>."), QStringLiteral("file"));
+ parser.addOption(depFileOption);
+
QCommandLineOption projectOption(QStringLiteral("project"), QStringLiteral("Output a resource file containing all files from the current directory."));
parser.addOption(projectOption);
@@ -266,6 +301,7 @@ int runRcc(int argc, char *argv[])
QString outFilename = parser.value(outputOption);
QString tempFilename = parser.value(tempOption);
+ QString depFilename = parser.value(depFileOption);
if (projectRequested) {
return createProject(outFilename);
@@ -352,6 +388,28 @@ int runRcc(int argc, char *argv[])
return 0;
}
+ // Write depfile
+ if (!depFilename.isEmpty()) {
+ QFile depout;
+ depout.setFileName(depFilename);
+
+ if (outFilename.isEmpty() || outFilename == QLatin1String("-")) {
+ const QString msg = QString::fromUtf8("Unable to write depfile when outputting to stdout!\n");
+ errorDevice.write(msg.toUtf8());
+ return 1;
+ }
+
+ if (!depout.open(QIODevice::WriteOnly | QIODevice::Text)) {
+ const QString msg = QString::fromUtf8("Unable to open depfile %1 for writing: %2\n")
+ .arg(depout.fileName(), depout.errorString());
+ errorDevice.write(msg.toUtf8());
+ return 1;
+ }
+
+ writeDepFile(depout, library.dataFiles(), outFilename);
+ depout.close();
+ }
+
QFile temp;
if (!tempFilename.isEmpty()) {
temp.setFileName(tempFilename);
diff --git a/src/tools/rcc/rcc.cpp b/src/tools/rcc/rcc.cpp
index 08fb6fca5f..9acbce25ff 100644
--- a/src/tools/rcc/rcc.cpp
+++ b/src/tools/rcc/rcc.cpp
@@ -59,7 +59,7 @@ enum {
CONSTANT_COMPRESSTHRESHOLD_DEFAULT = 70
};
-#if QT_CONFIG(zstd)
+#if QT_CONFIG(zstd) && QT_VERSION >= QT_VERSION_CHECK(6,0,0)
# define CONSTANT_COMPRESSALGO_DEFAULT RCCResourceLibrary::CompressionAlgorithm::Zstd
#elif !defined(QT_NO_COMPRESS)
# define CONSTANT_COMPRESSALGO_DEFAULT RCCResourceLibrary::CompressionAlgorithm::Zlib
@@ -67,11 +67,8 @@ enum {
# define CONSTANT_COMPRESSALGO_DEFAULT RCCResourceLibrary::CompressionAlgorithm::None
#endif
-#define writeString(s) write(s, sizeof(s))
-
void RCCResourceLibrary::write(const char *str, int len)
{
- --len; // trailing \0 on string literals...
int n = m_out.size();
m_out.resize(n + len);
memcpy(m_out.data() + n, str, len);
@@ -983,7 +980,7 @@ void RCCResourceLibrary::writeDecimal(int value)
Q_ASSERT(m_format != RCCResourceLibrary::Binary);
char buf[std::numeric_limits<int>::digits10 + 2];
int n = snprintf(buf, sizeof(buf), "%d", value);
- write(buf, n + 1); // write() takes a size including terminating NUL
+ write(buf, n);
}
static const char hexDigits[] = "0123456789abcdef";
diff --git a/src/tools/rcc/rcc.h b/src/tools/rcc/rcc.h
index b301355e4f..190c37a1f6 100644
--- a/src/tools/rcc/rcc.h
+++ b/src/tools/rcc/rcc.h
@@ -143,6 +143,7 @@ private:
void writeChar(char c) { m_out.append(c); }
void writeByteArray(const QByteArray &);
void write(const char *, int len);
+ void writeString(const char *s) { write(s, static_cast<int>(strlen(s))); }
#if QT_CONFIG(zstd)
ZSTD_CCtx *m_zstdCCtx;