Skip to content

Commit fbe7822

Browse files
committed
Use zip instead of 7zip
1 parent 9d1eef1 commit fbe7822

File tree

8 files changed

+52
-115
lines changed

8 files changed

+52
-115
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,10 @@ jobs:
426426
merge-multiple: true
427427
- name: Repackage xswiftbus
428428
run: |
429-
7z x -y xswiftbus-windows-64-*.7z
430-
7z x -y xswiftbus-linux-64-*.7z
431-
7z x -y xswiftbus-macos-64-*.7z
432-
7z a -y -mx=9 xswiftbus-fat-allos-${{ needs.preBuild.outputs.version }}.7z xswiftbus
429+
unzip -o xswiftbus-windows-64-*.zip
430+
unzip -o xswiftbus-linux-64-*.zip
431+
unzip -o xswiftbus-macos-64-*.zip
432+
zip -r -9 xswiftbus-fat-allos-${{ needs.preBuild.outputs.version }}.zip xswiftbus
433433
- name: Upload xswiftbus-fat
434434
uses: actions/upload-artifact@v4
435435
with:

cmake/install.cmake

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@ set(GENERAL_FILES
77
)
88
install(FILES ${GENERAL_FILES} DESTINATION bin)
99

10-
# 7za
11-
if(SWIFT_WIN32)
12-
install(FILES ${swift_SOURCE_DIR}/third_party/externals/win32-msvc/32/bin/7za.exe DESTINATION bin)
13-
elseif(SWIFT_WIN64)
14-
install(FILES ${swift_SOURCE_DIR}/third_party/externals/win32-msvc/64/bin/7za.exe DESTINATION bin)
15-
elseif(APPLE)
16-
install(FILES ${swift_SOURCE_DIR}/third_party/externals/macx-clang/64/bin/7za DESTINATION bin)
17-
endif()
18-
1910
# Crashpad
2011
if(UNIX AND NOT APPLE)
2112
set(crashpad_handler_path ${swift_SOURCE_DIR}/third_party/externals/linux-g++/64/bin/swift_crashpad_handler)

installer/installbuilder/swift-externals.xml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@
3131
<allowWildcards>1</allowWildcards>
3232
<origin>../../dist/bin/*opus*.dll</origin>
3333
</distributionFile>
34-
<distributionFile>
35-
<allowWildcards>1</allowWildcards>
36-
<origin>../../dist/bin/*7za.exe</origin>
37-
</distributionFile>
3834
</distributionFileList>
3935
</folder>
4036
<folder>
@@ -50,11 +46,6 @@
5046
<destination>${installdir}/bin</destination>
5147
<name>bin_osx</name>
5248
<platforms>osx</platforms>
53-
<distributionFileList>
54-
<distributionFile>
55-
<origin>../../dist/bin/7za</origin>
56-
</distributionFile>
57-
</distributionFileList>
5849
</folder>
5950
<folder>
6051
<description>lib</description>

scripts/build.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import tarfile
1515
from lib.util import get_vs_env
1616
import utils
17+
import zipfile
1718

1819

1920
class Builder:
@@ -120,10 +121,18 @@ def package_xswiftbus(self):
120121
build_path = self._get_swift_build_path()
121122
os.chdir(build_path)
122123
os_map = {'Linux': 'linux', 'Darwin': 'macos', 'Windows': 'windows'}
123-
archive_name = '-'.join(['xswiftbus', os_map[platform.system()], self.word_size, self.version]) + '.7z'
124+
archive_name = '-'.join(['xswiftbus', os_map[platform.system()], self.word_size, self.version]) + '.zip'
124125
archive_path = path.abspath(path.join(os.pardir, archive_name))
125-
content_path = path.abspath(path.join(utils.get_swift_source_path(), 'dist', 'xswiftbus'))
126-
subprocess.check_call(['7z', 'a', '-mx=9', archive_path, content_path, "-xr!*.debug", "-xr!*.dSYM"], env=dict(os.environ))
126+
base_path = path.abspath(path.join(utils.get_swift_source_path(), 'dist'))
127+
content_path = path.join(base_path, 'xswiftbus')
128+
with zipfile.ZipFile(archive_path, 'w', compression=zipfile.ZIP_DEFLATED, compresslevel=9) as zip_file:
129+
for root, dirs, files in os.walk(content_path):
130+
for file in files:
131+
if file.endswith(".debug") or file.endswith(".dSYM"):
132+
continue
133+
content_file_path = os.path.join(root, file)
134+
arcname = os.path.join(os.path.relpath(os.path.dirname(content_file_path), base_path), file)
135+
zip_file.write(content_file_path, arcname)
127136

128137
def symbols(self, upload_symbols):
129138
"""

src/gui/components/installxswiftbuscomponent.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ namespace swift::gui::components
173173

174174
// if possible we will unzip
175175
QStringList stdOutAndError;
176-
if (CCompressUtils::zip7Uncompress(destFile.absoluteFilePath(), xSwiftBusDirectory, &stdOutAndError))
176+
if (CCompressUtils::zipUncompress(destFile.absoluteFilePath(), xSwiftBusDirectory, &stdOutAndError))
177177
{
178178
// capture values by copy!
179179
const CStatusMessage msg =

src/misc/compressutils.cpp

Lines changed: 29 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -26,86 +26,54 @@ namespace swift::misc
2626
return lengthHeader;
2727
}
2828

29-
//! Returns the platform specific 7za command
30-
QString getZip7Executable()
31-
{
32-
QString executable;
33-
if (CBuildConfig::isRunningOnMacOSPlatform())
34-
{
35-
executable += CSwiftDirectories::binDirectory();
36-
executable += '/';
37-
}
38-
executable += QStringLiteral("7za");
39-
return executable;
40-
}
41-
42-
bool CCompressUtils::zip7Uncompress(const QString &file, const QString &directory, QStringList *stdOutAndError)
29+
bool CCompressUtils::zipUncompress(const QString &file, const QString &directory, QStringList *stdOutAndError)
4330
{
4431
const QFileInfo fi(file);
4532
if (!fi.exists()) { return false; }
46-
if (!CCompressUtils::hasZip7(stdOutAndError)) { return false; }
33+
if (fi.suffix() != "zip")
34+
{
35+
if (stdOutAndError) { stdOutAndError->push_back("Not a zip file"); }
36+
return false;
37+
}
4738

4839
const bool win = CBuildConfig::isRunningOnWindowsNtPlatform();
4940
const QString d = directory.isEmpty() ? directory : win ? CFileUtils::toWindowsLocalPath(directory) : directory;
5041
const QString f = win ? CFileUtils::toWindowsLocalPath(file) : file;
5142

52-
// 7za.exe x -o"P:\Temp\XPlane" c:\Users\Foo\Downloads\xswiftbus-allos-0.8.4.802111947.7z
53-
54-
QStringList args;
55-
args << "x";
56-
args << "-aoa";
57-
if (!d.isEmpty()) { args << "-o" + d; }
58-
args << f;
59-
6043
QProcess zipProcess;
61-
zipProcess.setProgram(getZip7Executable());
62-
zipProcess.setArguments(args);
63-
return runZip7Process(&zipProcess, stdOutAndError);
64-
}
65-
66-
bool CCompressUtils::hasZip7(QStringList *stdOutAndError)
67-
{
68-
// just display info
69-
if (CBuildConfig::isRunningOnLinuxPlatform()) { return CCompressUtils::whichZip7(stdOutAndError); }
7044

71-
QStringList args;
72-
args << "i";
73-
QProcess zipProcess;
74-
zipProcess.setProgram(getZip7Executable());
75-
zipProcess.setArguments(args);
76-
return runZip7Process(&zipProcess, stdOutAndError);
77-
}
78-
79-
bool CCompressUtils::whichZip7(QStringList *stdOutAndError)
80-
{
81-
const QString cmd("which 7za");
82-
QProcess zipProcess;
83-
zipProcess.start(cmd);
84-
if (!zipProcess.waitForStarted()) { return false; }
85-
if (!zipProcess.waitForFinished()) { return false; }
86-
87-
const QString pStdout = zipProcess.readAllStandardOutput();
88-
const QString pStderr = zipProcess.readAllStandardError();
89-
if (stdOutAndError)
45+
if constexpr (CBuildConfig::isRunningOnWindowsNtPlatform())
9046
{
91-
stdOutAndError->clear();
92-
stdOutAndError->push_back(pStdout);
93-
stdOutAndError->push_back(pStderr);
47+
zipProcess.setProgram("powershell");
48+
QStringList args;
49+
args << "-Command";
50+
args << "Expand-Archive";
51+
args << "-Path" << f;
52+
if (!d.isEmpty()) { args << "-DestinationPath" << d; }
53+
args << "-Force";
54+
zipProcess.setArguments(args);
55+
}
56+
else
57+
{
58+
zipProcess.setProgram("unzip");
59+
QStringList args;
60+
args << f;
61+
if (!d.isEmpty()) { args << "-d" << d; }
62+
zipProcess.setArguments(args);
9463
}
95-
const int r = zipProcess.exitCode();
96-
return r == 0 && pStdout.contains("7za", Qt::CaseInsensitive);
64+
return runZipProcess(&zipProcess, stdOutAndError);
9765
}
9866

99-
bool CCompressUtils::runZip7Process(QProcess *zipProcess, QStringList *stdOutAndError)
67+
bool CCompressUtils::runZipProcess(QProcess *zipProcess, QStringList *stdOutAndError)
10068
{
10169
zipProcess->start();
10270

103-
// If process does not even start, e.g. because no 7za exe found.
71+
// If process does not even start, e.g. because unzip program found.
10472
if (!zipProcess->waitForStarted())
10573
{
10674
if (stdOutAndError)
10775
{
108-
stdOutAndError->push_back("7za");
76+
stdOutAndError->push_back("unzip");
10977
stdOutAndError->push_back("Command not found");
11078
}
11179
return false;
@@ -116,7 +84,7 @@ namespace swift::misc
11684
{
11785
if (stdOutAndError)
11886
{
119-
stdOutAndError->push_back("7za");
87+
stdOutAndError->push_back("unzip");
12088
stdOutAndError->push_back("Process did not finish.");
12189
}
12290
return false;
@@ -131,6 +99,6 @@ namespace swift::misc
13199
stdOutAndError->push_back(pStderr);
132100
}
133101

134-
return zipProcess->exitStatus() == QProcess::NormalExit;
102+
return zipProcess->exitStatus() == QProcess::NormalExit && zipProcess->exitCode() == 0;
135103
}
136104
} // namespace swift::misc

src/misc/compressutils.h

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,11 @@ namespace swift::misc
2525
//! \remark 4 bytes -> 32bit
2626
static QByteArray lengthHeader(qint32 size);
2727

28-
//! Unzip my using 7zip
29-
//! \remark relies on external 7zip command line
30-
static bool zip7Uncompress(const QString &file, const QString &directory,
31-
QStringList *stdOutAndError = nullptr);
32-
33-
//! External program existing?
34-
//! \remark relies on external 7zip command line
35-
static bool hasZip7(QStringList *stdOutAndError = nullptr);
36-
37-
//! Uses which to determine if 7Zip exists
38-
//! \remark for UNIX systems, using which
39-
static bool whichZip7(QStringList *stdOutAndError = nullptr);
28+
//! Unzip file
29+
static bool zipUncompress(const QString &file, const QString &directory, QStringList *stdOutAndError = nullptr);
4030

4131
private:
42-
static bool runZip7Process(QProcess *zipProcess, QStringList *stdOutAndError);
32+
static bool runZipProcess(QProcess *zipProcess, QStringList *stdOutAndError);
4333
};
4434
} // namespace swift::misc
4535

tests/misc/testcompress/testcompress.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,14 @@ namespace MiscTest
4949
tempDir.setAutoRemove(true);
5050
QVERIFY2(tempDir.isValid(), "Invalid directory");
5151

52-
const bool win = CBuildConfig::isRunningOnWindowsNtPlatform();
53-
const bool zip7Exists = CCompressUtils::hasZip7();
54-
if (!win && !zip7Exists)
55-
{
56-
QSKIP("No 7zip, skipping");
57-
return;
58-
}
59-
60-
QVERIFY2(zip7Exists, "No 7zip");
61-
6252
const QString td = tempDir.path();
63-
const QString compressedFile(
64-
CFileUtils::appendFilePaths(CSwiftDirectories::shareTestDirectory(), "countries.json.gz"));
65-
const QString unCompressedFile(CFileUtils::appendFilePaths(td, "countries.json"));
66-
const bool c = CCompressUtils::zip7Uncompress(compressedFile, td);
53+
const QString compressedFile(CFileUtils::appendFilePaths(CSwiftDirectories::shareTestDirectory(), "test.zip"));
54+
const QString unCompressedFile(CFileUtils::appendFilePaths(td, "1.txt"));
55+
const bool c = CCompressUtils::zipUncompress(compressedFile, td);
6756

6857
QVERIFY2(c, "Uncompressing failed");
6958

7059
const QFileInfo check(unCompressedFile);
71-
QVERIFY2(check.size() > 1000, "Uncompressing yielded not data");
7260
QVERIFY2(check.exists(), "Uncompressed file does not exist");
7361
QVERIFY2(check.isReadable(), "Not readable");
7462

0 commit comments

Comments
 (0)