mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 06:45:37 +08:00
feat: Use zip instead of 7zip
This commit is contained in:
8
.github/workflows/build.yml
vendored
8
.github/workflows/build.yml
vendored
@@ -426,10 +426,10 @@ jobs:
|
||||
merge-multiple: true
|
||||
- name: Repackage xswiftbus
|
||||
run: |
|
||||
7z x -y xswiftbus-windows-64-*.7z
|
||||
7z x -y xswiftbus-linux-64-*.7z
|
||||
7z x -y xswiftbus-macos-64-*.7z
|
||||
7z a -y -mx=9 xswiftbus-fat-allos-${{ needs.preBuild.outputs.version }}.7z xswiftbus
|
||||
unzip -o xswiftbus-windows-64-*.zip
|
||||
unzip -o xswiftbus-linux-64-*.zip
|
||||
unzip -o xswiftbus-macos-64-*.zip
|
||||
zip -r -9 xswiftbus-fat-allos-${{ needs.preBuild.outputs.version }}.zip xswiftbus
|
||||
- name: Upload xswiftbus-fat
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
|
||||
@@ -7,15 +7,6 @@ set(GENERAL_FILES
|
||||
)
|
||||
install(FILES ${GENERAL_FILES} DESTINATION bin)
|
||||
|
||||
# 7za
|
||||
if(SWIFT_WIN32)
|
||||
install(FILES ${swift_SOURCE_DIR}/third_party/externals/win32-msvc/32/bin/7za.exe DESTINATION bin)
|
||||
elseif(SWIFT_WIN64)
|
||||
install(FILES ${swift_SOURCE_DIR}/third_party/externals/win32-msvc/64/bin/7za.exe DESTINATION bin)
|
||||
elseif(APPLE)
|
||||
install(FILES ${swift_SOURCE_DIR}/third_party/externals/macx-clang/64/bin/7za DESTINATION bin)
|
||||
endif()
|
||||
|
||||
# Crashpad
|
||||
if(UNIX AND NOT APPLE)
|
||||
set(crashpad_handler_path ${swift_SOURCE_DIR}/third_party/externals/linux-g++/64/bin/swift_crashpad_handler)
|
||||
|
||||
@@ -31,10 +31,6 @@
|
||||
<allowWildcards>1</allowWildcards>
|
||||
<origin>../../dist/bin/*opus*.dll</origin>
|
||||
</distributionFile>
|
||||
<distributionFile>
|
||||
<allowWildcards>1</allowWildcards>
|
||||
<origin>../../dist/bin/*7za.exe</origin>
|
||||
</distributionFile>
|
||||
</distributionFileList>
|
||||
</folder>
|
||||
<folder>
|
||||
@@ -50,11 +46,6 @@
|
||||
<destination>${installdir}/bin</destination>
|
||||
<name>bin_osx</name>
|
||||
<platforms>osx</platforms>
|
||||
<distributionFileList>
|
||||
<distributionFile>
|
||||
<origin>../../dist/bin/7za</origin>
|
||||
</distributionFile>
|
||||
</distributionFileList>
|
||||
</folder>
|
||||
<folder>
|
||||
<description>lib</description>
|
||||
|
||||
@@ -14,6 +14,7 @@ import datastore
|
||||
import tarfile
|
||||
from lib.util import get_vs_env
|
||||
import utils
|
||||
import zipfile
|
||||
|
||||
|
||||
class Builder:
|
||||
@@ -120,10 +121,19 @@ class Builder:
|
||||
build_path = self._get_swift_build_path()
|
||||
os.chdir(build_path)
|
||||
os_map = {'Linux': 'linux', 'Darwin': 'macos', 'Windows': 'windows'}
|
||||
archive_name = '-'.join(['xswiftbus', os_map[platform.system()], self.word_size, self.version]) + '.7z'
|
||||
archive_name = '-'.join(['xswiftbus', os_map[platform.system()], self.word_size, self.version]) + '.zip'
|
||||
archive_path = path.abspath(path.join(os.pardir, archive_name))
|
||||
content_path = path.abspath(path.join(utils.get_swift_source_path(), 'dist', 'xswiftbus'))
|
||||
subprocess.check_call(['7z', 'a', '-mx=9', archive_path, content_path, "-xr!*.debug", "-xr!*.dSYM"], env=dict(os.environ))
|
||||
base_path = path.abspath(path.join(utils.get_swift_source_path(), 'dist'))
|
||||
content_path = path.join(base_path, 'xswiftbus')
|
||||
with zipfile.ZipFile(archive_path, 'w', compression=zipfile.ZIP_DEFLATED, compresslevel=9) as zip_file:
|
||||
for root, dirs, files in os.walk(content_path):
|
||||
dirs[:] = [d for d in dirs if not d.endswith('.debug') and not d.endswith(".dSYM")]
|
||||
for file in files:
|
||||
if file.endswith(".debug") or file.endswith(".dSYM"):
|
||||
continue
|
||||
content_file_path = os.path.join(root, file)
|
||||
arcname = os.path.join(os.path.relpath(os.path.dirname(content_file_path), base_path), file)
|
||||
zip_file.write(content_file_path, arcname)
|
||||
|
||||
def symbols(self, upload_symbols):
|
||||
"""
|
||||
|
||||
@@ -173,7 +173,7 @@ namespace swift::gui::components
|
||||
|
||||
// if possible we will unzip
|
||||
QStringList stdOutAndError;
|
||||
if (CCompressUtils::zip7Uncompress(destFile.absoluteFilePath(), xSwiftBusDirectory, &stdOutAndError))
|
||||
if (CCompressUtils::zipUncompress(destFile.absoluteFilePath(), xSwiftBusDirectory, &stdOutAndError))
|
||||
{
|
||||
// capture values by copy!
|
||||
const CStatusMessage msg =
|
||||
|
||||
@@ -26,86 +26,54 @@ namespace swift::misc
|
||||
return lengthHeader;
|
||||
}
|
||||
|
||||
//! Returns the platform specific 7za command
|
||||
QString getZip7Executable()
|
||||
{
|
||||
QString executable;
|
||||
if (CBuildConfig::isRunningOnMacOSPlatform())
|
||||
{
|
||||
executable += CSwiftDirectories::binDirectory();
|
||||
executable += '/';
|
||||
}
|
||||
executable += QStringLiteral("7za");
|
||||
return executable;
|
||||
}
|
||||
|
||||
bool CCompressUtils::zip7Uncompress(const QString &file, const QString &directory, QStringList *stdOutAndError)
|
||||
bool CCompressUtils::zipUncompress(const QString &file, const QString &directory, QStringList *stdOutAndError)
|
||||
{
|
||||
const QFileInfo fi(file);
|
||||
if (!fi.exists()) { return false; }
|
||||
if (!CCompressUtils::hasZip7(stdOutAndError)) { return false; }
|
||||
if (fi.suffix() != "zip")
|
||||
{
|
||||
if (stdOutAndError) { stdOutAndError->push_back("Not a zip file"); }
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool win = CBuildConfig::isRunningOnWindowsNtPlatform();
|
||||
const QString d = directory.isEmpty() ? directory : win ? CFileUtils::toWindowsLocalPath(directory) : directory;
|
||||
const QString f = win ? CFileUtils::toWindowsLocalPath(file) : file;
|
||||
|
||||
// 7za.exe x -o"P:\Temp\XPlane" c:\Users\Foo\Downloads\xswiftbus-allos-0.8.4.802111947.7z
|
||||
|
||||
QStringList args;
|
||||
args << "x";
|
||||
args << "-aoa";
|
||||
if (!d.isEmpty()) { args << "-o" + d; }
|
||||
args << f;
|
||||
|
||||
QProcess zipProcess;
|
||||
zipProcess.setProgram(getZip7Executable());
|
||||
zipProcess.setArguments(args);
|
||||
return runZip7Process(&zipProcess, stdOutAndError);
|
||||
}
|
||||
|
||||
bool CCompressUtils::hasZip7(QStringList *stdOutAndError)
|
||||
{
|
||||
// just display info
|
||||
if (CBuildConfig::isRunningOnLinuxPlatform()) { return CCompressUtils::whichZip7(stdOutAndError); }
|
||||
|
||||
QStringList args;
|
||||
args << "i";
|
||||
QProcess zipProcess;
|
||||
zipProcess.setProgram(getZip7Executable());
|
||||
zipProcess.setArguments(args);
|
||||
return runZip7Process(&zipProcess, stdOutAndError);
|
||||
}
|
||||
|
||||
bool CCompressUtils::whichZip7(QStringList *stdOutAndError)
|
||||
{
|
||||
const QString cmd("which 7za");
|
||||
QProcess zipProcess;
|
||||
zipProcess.start(cmd);
|
||||
if (!zipProcess.waitForStarted()) { return false; }
|
||||
if (!zipProcess.waitForFinished()) { return false; }
|
||||
|
||||
const QString pStdout = zipProcess.readAllStandardOutput();
|
||||
const QString pStderr = zipProcess.readAllStandardError();
|
||||
if (stdOutAndError)
|
||||
if constexpr (CBuildConfig::isRunningOnWindowsNtPlatform())
|
||||
{
|
||||
stdOutAndError->clear();
|
||||
stdOutAndError->push_back(pStdout);
|
||||
stdOutAndError->push_back(pStderr);
|
||||
zipProcess.setProgram("powershell");
|
||||
QStringList args;
|
||||
args << "-Command";
|
||||
args << "Expand-Archive";
|
||||
args << "-Path" << f;
|
||||
if (!d.isEmpty()) { args << "-DestinationPath" << d; }
|
||||
args << "-Force";
|
||||
zipProcess.setArguments(args);
|
||||
}
|
||||
const int r = zipProcess.exitCode();
|
||||
return r == 0 && pStdout.contains("7za", Qt::CaseInsensitive);
|
||||
else
|
||||
{
|
||||
zipProcess.setProgram("unzip");
|
||||
QStringList args;
|
||||
args << f;
|
||||
if (!d.isEmpty()) { args << "-d" << d; }
|
||||
zipProcess.setArguments(args);
|
||||
}
|
||||
return runZipProcess(&zipProcess, stdOutAndError);
|
||||
}
|
||||
|
||||
bool CCompressUtils::runZip7Process(QProcess *zipProcess, QStringList *stdOutAndError)
|
||||
bool CCompressUtils::runZipProcess(QProcess *zipProcess, QStringList *stdOutAndError)
|
||||
{
|
||||
zipProcess->start();
|
||||
|
||||
// If process does not even start, e.g. because no 7za exe found.
|
||||
// If process does not even start, e.g. because unzip program found.
|
||||
if (!zipProcess->waitForStarted())
|
||||
{
|
||||
if (stdOutAndError)
|
||||
{
|
||||
stdOutAndError->push_back("7za");
|
||||
stdOutAndError->push_back("unzip");
|
||||
stdOutAndError->push_back("Command not found");
|
||||
}
|
||||
return false;
|
||||
@@ -116,7 +84,7 @@ namespace swift::misc
|
||||
{
|
||||
if (stdOutAndError)
|
||||
{
|
||||
stdOutAndError->push_back("7za");
|
||||
stdOutAndError->push_back("unzip");
|
||||
stdOutAndError->push_back("Process did not finish.");
|
||||
}
|
||||
return false;
|
||||
@@ -131,6 +99,6 @@ namespace swift::misc
|
||||
stdOutAndError->push_back(pStderr);
|
||||
}
|
||||
|
||||
return zipProcess->exitStatus() == QProcess::NormalExit;
|
||||
return zipProcess->exitStatus() == QProcess::NormalExit && zipProcess->exitCode() == 0;
|
||||
}
|
||||
} // namespace swift::misc
|
||||
|
||||
@@ -25,21 +25,11 @@ namespace swift::misc
|
||||
//! \remark 4 bytes -> 32bit
|
||||
static QByteArray lengthHeader(qint32 size);
|
||||
|
||||
//! Unzip my using 7zip
|
||||
//! \remark relies on external 7zip command line
|
||||
static bool zip7Uncompress(const QString &file, const QString &directory,
|
||||
QStringList *stdOutAndError = nullptr);
|
||||
|
||||
//! External program existing?
|
||||
//! \remark relies on external 7zip command line
|
||||
static bool hasZip7(QStringList *stdOutAndError = nullptr);
|
||||
|
||||
//! Uses which to determine if 7Zip exists
|
||||
//! \remark for UNIX systems, using which
|
||||
static bool whichZip7(QStringList *stdOutAndError = nullptr);
|
||||
//! Unzip file
|
||||
static bool zipUncompress(const QString &file, const QString &directory, QStringList *stdOutAndError = nullptr);
|
||||
|
||||
private:
|
||||
static bool runZip7Process(QProcess *zipProcess, QStringList *stdOutAndError);
|
||||
static bool runZipProcess(QProcess *zipProcess, QStringList *stdOutAndError);
|
||||
};
|
||||
} // namespace swift::misc
|
||||
|
||||
|
||||
@@ -49,26 +49,14 @@ namespace MiscTest
|
||||
tempDir.setAutoRemove(true);
|
||||
QVERIFY2(tempDir.isValid(), "Invalid directory");
|
||||
|
||||
const bool win = CBuildConfig::isRunningOnWindowsNtPlatform();
|
||||
const bool zip7Exists = CCompressUtils::hasZip7();
|
||||
if (!win && !zip7Exists)
|
||||
{
|
||||
QSKIP("No 7zip, skipping");
|
||||
return;
|
||||
}
|
||||
|
||||
QVERIFY2(zip7Exists, "No 7zip");
|
||||
|
||||
const QString td = tempDir.path();
|
||||
const QString compressedFile(
|
||||
CFileUtils::appendFilePaths(CSwiftDirectories::shareTestDirectory(), "countries.json.gz"));
|
||||
const QString unCompressedFile(CFileUtils::appendFilePaths(td, "countries.json"));
|
||||
const bool c = CCompressUtils::zip7Uncompress(compressedFile, td);
|
||||
const QString compressedFile(CFileUtils::appendFilePaths(CSwiftDirectories::shareTestDirectory(), "test.zip"));
|
||||
const QString unCompressedFile(CFileUtils::appendFilePaths(td, "1.txt"));
|
||||
const bool c = CCompressUtils::zipUncompress(compressedFile, td);
|
||||
|
||||
QVERIFY2(c, "Uncompressing failed");
|
||||
|
||||
const QFileInfo check(unCompressedFile);
|
||||
QVERIFY2(check.size() > 1000, "Uncompressing yielded not data");
|
||||
QVERIFY2(check.exists(), "Uncompressed file does not exist");
|
||||
QVERIFY2(check.isReadable(), "Not readable");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user