RCC: fix zlib compression when --no-zstd was specified
Since we had code to default to zstd as the default algorithm instead of "Best", we ended up not compressing anything. [ChangeLog][rcc] Fixed a bug that caused rcc not to compress files with any compression algorithm if the --no-zstd option was present. Fixes: QTBUG-106012 Change-Id: Ic6547f8247454b47baa8fffd170fddae429f82d2 Reviewed-by: Kai Koehne <kai.koehne@qt.io> (cherry picked from commit f12321288009119552df10df75c77228f6bac0db) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
e5a46dd1cf
commit
347c9e2b58
@ -227,12 +227,16 @@ int runRcc(int argc, char *argv[])
|
|||||||
|
|
||||||
if (parser.isSet(compressionAlgoOption))
|
if (parser.isSet(compressionAlgoOption))
|
||||||
library.setCompressionAlgorithm(RCCResourceLibrary::parseCompressionAlgorithm(parser.value(compressionAlgoOption), &errorMsg));
|
library.setCompressionAlgorithm(RCCResourceLibrary::parseCompressionAlgorithm(parser.value(compressionAlgoOption), &errorMsg));
|
||||||
if (formatVersion < 3 && library.compressionAlgorithm() == RCCResourceLibrary::CompressionAlgorithm::Zstd)
|
|
||||||
errorMsg = "Zstandard compression requires format version 3 or higher"_L1;
|
|
||||||
if (parser.isSet(nocompressOption))
|
|
||||||
library.setCompressionAlgorithm(RCCResourceLibrary::CompressionAlgorithm::None);
|
|
||||||
if (parser.isSet(noZstdOption))
|
if (parser.isSet(noZstdOption))
|
||||||
library.setNoZstd(true);
|
library.setNoZstd(true);
|
||||||
|
if (library.compressionAlgorithm() == RCCResourceLibrary::CompressionAlgorithm::Zstd) {
|
||||||
|
if (formatVersion < 3)
|
||||||
|
errorMsg = "Zstandard compression requires format version 3 or higher"_L1;
|
||||||
|
if (library.noZstd())
|
||||||
|
errorMsg = "--compression-algo=zstd and --no-zstd both specified."_L1;
|
||||||
|
}
|
||||||
|
if (parser.isSet(nocompressOption))
|
||||||
|
library.setCompressionAlgorithm(RCCResourceLibrary::CompressionAlgorithm::None);
|
||||||
if (parser.isSet(compressOption) && errorMsg.isEmpty()) {
|
if (parser.isSet(compressOption) && errorMsg.isEmpty()) {
|
||||||
int level = library.parseCompressionLevel(library.compressionAlgorithm(), parser.value(compressOption), &errorMsg);
|
int level = library.parseCompressionLevel(library.compressionAlgorithm(), parser.value(compressOption), &errorMsg);
|
||||||
library.setCompressLevel(level);
|
library.setCompressLevel(level);
|
||||||
|
@ -35,14 +35,6 @@ enum {
|
|||||||
CONSTANT_COMPRESSTHRESHOLD_DEFAULT = 70
|
CONSTANT_COMPRESSTHRESHOLD_DEFAULT = 70
|
||||||
};
|
};
|
||||||
|
|
||||||
#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
|
|
||||||
#else
|
|
||||||
# define CONSTANT_COMPRESSALGO_DEFAULT RCCResourceLibrary::CompressionAlgorithm::None
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void RCCResourceLibrary::write(const char *str, int len)
|
void RCCResourceLibrary::write(const char *str, int len)
|
||||||
{
|
{
|
||||||
int n = m_out.size();
|
int n = m_out.size();
|
||||||
@ -87,7 +79,7 @@ public:
|
|||||||
QLocale::Language language = QLocale::C,
|
QLocale::Language language = QLocale::C,
|
||||||
QLocale::Territory territory = QLocale::AnyTerritory,
|
QLocale::Territory territory = QLocale::AnyTerritory,
|
||||||
uint flags = NoFlags,
|
uint flags = NoFlags,
|
||||||
RCCResourceLibrary::CompressionAlgorithm compressAlgo = CONSTANT_COMPRESSALGO_DEFAULT,
|
RCCResourceLibrary::CompressionAlgorithm compressAlgo = RCCResourceLibrary::CompressionAlgorithm::Best,
|
||||||
int compressLevel = CONSTANT_COMPRESSLEVEL_DEFAULT,
|
int compressLevel = CONSTANT_COMPRESSLEVEL_DEFAULT,
|
||||||
int compressThreshold = CONSTANT_COMPRESSTHRESHOLD_DEFAULT,
|
int compressThreshold = CONSTANT_COMPRESSTHRESHOLD_DEFAULT,
|
||||||
bool noZstd = false);
|
bool noZstd = false);
|
||||||
@ -438,7 +430,7 @@ RCCResourceLibrary::RCCResourceLibrary(quint8 formatVersion)
|
|||||||
: m_root(nullptr),
|
: m_root(nullptr),
|
||||||
m_format(C_Code),
|
m_format(C_Code),
|
||||||
m_verbose(false),
|
m_verbose(false),
|
||||||
m_compressionAlgo(CONSTANT_COMPRESSALGO_DEFAULT),
|
m_compressionAlgo(CompressionAlgorithm::Best),
|
||||||
m_compressLevel(CONSTANT_COMPRESSLEVEL_DEFAULT),
|
m_compressLevel(CONSTANT_COMPRESSLEVEL_DEFAULT),
|
||||||
m_compressThreshold(CONSTANT_COMPRESSTHRESHOLD_DEFAULT),
|
m_compressThreshold(CONSTANT_COMPRESSTHRESHOLD_DEFAULT),
|
||||||
m_treeOffset(0),
|
m_treeOffset(0),
|
||||||
|
@ -37,6 +37,7 @@ private slots:
|
|||||||
void searchPath_data();
|
void searchPath_data();
|
||||||
void searchPath();
|
void searchPath();
|
||||||
void doubleSlashInRoot();
|
void doubleSlashInRoot();
|
||||||
|
void setLocale_data();
|
||||||
void setLocale();
|
void setLocale();
|
||||||
void lastModified();
|
void lastModified();
|
||||||
void resourcesInStaticPlugins();
|
void resourcesInStaticPlugins();
|
||||||
@ -556,13 +557,22 @@ void tst_QResourceEngine::doubleSlashInRoot()
|
|||||||
QVERIFY(QFile::exists("://secondary_root/runtime_resource/search_file.txt"));
|
QVERIFY(QFile::exists("://secondary_root/runtime_resource/search_file.txt"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QResourceEngine::setLocale_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<QString>("prefix");
|
||||||
|
QTest::newRow("built-in") << QString();
|
||||||
|
QTest::newRow("runtime") << "/runtime_resource/";
|
||||||
|
}
|
||||||
|
|
||||||
void tst_QResourceEngine::setLocale()
|
void tst_QResourceEngine::setLocale()
|
||||||
{
|
{
|
||||||
|
QFETCH(QString, prefix);
|
||||||
QLocale::setDefault(QLocale::c());
|
QLocale::setDefault(QLocale::c());
|
||||||
|
|
||||||
// default constructed QResource gets the default locale
|
// default constructed QResource gets the default locale
|
||||||
QResource resource;
|
QResource resource;
|
||||||
resource.setFileName("aliasdir/aliasdir.txt");
|
resource.setFileName(prefix + "aliasdir/aliasdir.txt");
|
||||||
|
QVERIFY(resource.isValid());
|
||||||
QCOMPARE(resource.compressionAlgorithm(), QResource::NoCompression);
|
QCOMPARE(resource.compressionAlgorithm(), QResource::NoCompression);
|
||||||
|
|
||||||
// change the default locale and make sure it doesn't affect the resource
|
// change the default locale and make sure it doesn't affect the resource
|
||||||
|
Loading…
x
Reference in New Issue
Block a user