Skip to content

Commit d00970d

Browse files
committed
Deduplicate Qt plugins deployment
1 parent babb58d commit d00970d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+486
-497
lines changed

src/deployers/BasicPluginsDeployer.cpp

+21-3
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,26 @@ BasicPluginsDeployer::BasicPluginsDeployer(std::string moduleName,
2828
qtTranslationsPath(std::move(qtTranslationsPath)),
2929
qtDataPath(std::move(qtDataPath)) {}
3030

31-
bool BasicPluginsDeployer::deploy() {
32-
// currently this is a no-op, but we might add more functionality later on, such as some kinds of default
33-
// attempts to copy data based on the moduleName
31+
bool BasicPluginsDeployer::deploy()
32+
{
33+
for (const auto &pluginName : qtPluginsToBeDeployed()) {
34+
ldLog() << "Deploying" << pluginName << "plugins" << std::endl;
35+
for (fs::directory_iterator i(qtPluginsPath / pluginName); i != fs::directory_iterator();
36+
++i) {
37+
if (!appDir.deployLibrary(*i, appDir.path() / "usr/plugins" / pluginName))
38+
return false;
39+
}
40+
}
41+
42+
return customDeploy();
43+
}
44+
45+
bool BasicPluginsDeployer::customDeploy()
46+
{
3447
return true;
3548
}
49+
50+
std::vector<std::string> BasicPluginsDeployer::qtPluginsToBeDeployed() const
51+
{
52+
return {};
53+
}

src/deployers/BasicPluginsDeployer.h

+19-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,25 @@ namespace linuxdeploy {
4949
virtual ~BasicPluginsDeployer() = default;
5050

5151
public:
52-
bool deploy() override;
52+
/**
53+
* This method deploys the plugins returned by \sa qtPluginsToBeDeployed()
54+
* and call \sa customDeploy() to finalize the deployment.
55+
*/
56+
bool deploy() override final;
57+
58+
protected:
59+
/**
60+
* The \sa deploy() method can deploy Qt plugins that follow the default
61+
* name and path scheme, but some modules are special so
62+
* they should write custom deployment code.
63+
*/
64+
virtual bool customDeploy();
65+
66+
/**
67+
* Returns a list of Qt plugin names that should be deployed and
68+
* follow the default name and path scheme.
69+
*/
70+
virtual std::vector<std::string> qtPluginsToBeDeployed() const;
5371
};
5472
}
5573
}

src/deployers/BearerPluginsDeployer.cpp

+3-15
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,7 @@
1010
using namespace linuxdeploy::plugin::qt;
1111
using namespace linuxdeploy::core::log;
1212

13-
namespace fs = std::filesystem;
14-
15-
bool BearerPluginsDeployer::deploy() {
16-
// calling the default code is optional, but it won't hurt for now
17-
if (!BasicPluginsDeployer::deploy())
18-
return false;
19-
20-
ldLog() << "Deploying bearer plugins" << std::endl;
21-
22-
for (fs::directory_iterator i(qtPluginsPath / "bearer"); i != fs::directory_iterator(); ++i) {
23-
if (!appDir.deployLibrary(*i, appDir.path() / "usr/plugins/bearer/"))
24-
return false;
25-
}
26-
27-
return true;
13+
std::vector<std::string> BearerPluginsDeployer::qtPluginsToBeDeployed() const
14+
{
15+
return {"bearer"};
2816
}

src/deployers/BearerPluginsDeployer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace linuxdeploy {
1010
// we can just use the base class's constructor
1111
using BasicPluginsDeployer::BasicPluginsDeployer;
1212

13-
bool deploy() override;
13+
std::vector<std::string> qtPluginsToBeDeployed() const override;
1414
};
1515
}
1616
}

src/deployers/GamepadPluginsDeployer.cpp

+3-15
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,7 @@
1010
using namespace linuxdeploy::plugin::qt;
1111
using namespace linuxdeploy::core::log;
1212

13-
namespace fs = std::filesystem;
14-
15-
bool GamepadPluginsDeployer::deploy() {
16-
// calling the default code is optional, but it won't hurt for now
17-
if (!BasicPluginsDeployer::deploy())
18-
return false;
19-
20-
ldLog() << "Deploying Gamepad plugins" << std::endl;
21-
22-
for (fs::directory_iterator i(qtPluginsPath / "gamepads"); i != fs::directory_iterator(); ++i) {
23-
if (!appDir.deployLibrary(*i, appDir.path() / "usr/plugins/gamepads/"))
24-
return false;
25-
}
26-
27-
return true;
13+
std::vector<std::string> GamepadPluginsDeployer::qtPluginsToBeDeployed() const
14+
{
15+
return {"gamepads"};
2816
}

src/deployers/GamepadPluginsDeployer.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
namespace linuxdeploy {
66
namespace plugin {
77
namespace qt {
8-
class GamepadPluginsDeployer : public BasicPluginsDeployer {
8+
class GamepadPluginsDeployer : public BasicPluginsDeployer
9+
{
910
public:
1011
// we can just use the base class's constructor
1112
using BasicPluginsDeployer::BasicPluginsDeployer;
1213

13-
bool deploy() override;
14+
std::vector<std::string> qtPluginsToBeDeployed() const override;
1415
};
1516
}
1617
}

src/deployers/LocationPluginsDeployer.cpp

+3-15
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,7 @@
1010
using namespace linuxdeploy::plugin::qt;
1111
using namespace linuxdeploy::core::log;
1212

13-
namespace fs = std::filesystem;
14-
15-
bool LocationPluginsDeployer::deploy() {
16-
// calling the default code is optional, but it won't hurt for now
17-
if (!BasicPluginsDeployer::deploy())
18-
return false;
19-
20-
ldLog() << "Deploying Location plugins" << std::endl;
21-
22-
for (fs::directory_iterator i(qtPluginsPath / "geoservices"); i != fs::directory_iterator(); ++i) {
23-
if (!appDir.deployLibrary(*i, appDir.path() / "usr/plugins/geoservices/"))
24-
return false;
25-
}
26-
27-
return true;
13+
std::vector<std::string> LocationPluginsDeployer::qtPluginsToBeDeployed() const
14+
{
15+
return {"geoservices"};
2816
}

src/deployers/LocationPluginsDeployer.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
namespace linuxdeploy {
66
namespace plugin {
77
namespace qt {
8-
class LocationPluginsDeployer : public BasicPluginsDeployer {
8+
class LocationPluginsDeployer : public BasicPluginsDeployer
9+
{
910
public:
1011
// we can just use the base class's constructor
1112
using BasicPluginsDeployer::BasicPluginsDeployer;
1213

13-
bool deploy() override;
14+
std::vector<std::string> qtPluginsToBeDeployed() const override;
1415
};
1516
}
1617
}

src/deployers/Multimedia5PluginsDeployer.cpp

+3-22
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,7 @@
1010
using namespace linuxdeploy::plugin::qt;
1111
using namespace linuxdeploy::core::log;
1212

13-
namespace fs = std::filesystem;
14-
15-
bool Multimedia5PluginsDeployer::deploy() {
16-
// calling the default code is optional, but it won't hurt for now
17-
if (!BasicPluginsDeployer::deploy())
18-
return false;
19-
20-
ldLog() << "Deploying mediaservice plugins" << std::endl;
21-
22-
for (fs::directory_iterator i(qtPluginsPath / "mediaservice"); i != fs::directory_iterator(); ++i) {
23-
if (!appDir.deployLibrary(*i, appDir.path() / "usr/plugins/mediaservice/"))
24-
return false;
25-
}
26-
27-
ldLog() << "Deploying audio plugins" << std::endl;
28-
29-
for (fs::directory_iterator i(qtPluginsPath / "audio"); i != fs::directory_iterator(); ++i) {
30-
if (!appDir.deployLibrary(*i, appDir.path() / "usr/plugins/audio/"))
31-
return false;
32-
}
33-
34-
return true;
13+
std::vector<std::string> Multimedia5PluginsDeployer::qtPluginsToBeDeployed() const
14+
{
15+
return {"mediaservice", "audio"};
3516
}

src/deployers/Multimedia5PluginsDeployer.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
namespace linuxdeploy {
66
namespace plugin {
77
namespace qt {
8-
class Multimedia5PluginsDeployer : public BasicPluginsDeployer {
8+
class Multimedia5PluginsDeployer : public BasicPluginsDeployer
9+
{
910
public:
1011
// we can just use the base class's constructor
1112
using BasicPluginsDeployer::BasicPluginsDeployer;
1213

13-
bool deploy() override;
14+
std::vector<std::string> qtPluginsToBeDeployed() const override;
1415
};
1516
}
1617
}

src/deployers/Multimedia6PluginsDeployer.cpp

+4-13
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,12 @@ using namespace linuxdeploy::core::log;
1212

1313
namespace fs = std::filesystem;
1414

15-
bool Multimedia6PluginsDeployer::deploy() {
16-
// calling the default code is optional, but it won't hurt for now
17-
if (!BasicPluginsDeployer::deploy())
18-
return false;
19-
15+
std::vector<std::string> Multimedia6PluginsDeployer::qtPluginsToBeDeployed() const
16+
{
2017
if (fs::exists(qtPluginsPath / "multimedia")) {
21-
ldLog() << "Deploying multimedia plugins" << std::endl;
22-
23-
for (fs::directory_iterator i(qtPluginsPath / "multimedia"); i != fs::directory_iterator(); ++i) {
24-
if (!appDir.deployLibrary(*i, appDir.path() / "usr/plugins/multimedia/"))
25-
return false;
26-
}
18+
return {"multimedia"};
2719
} else {
2820
ldLog() << LD_WARNING << "Missing Qt 6 multimedia plugins, skipping." << std::endl;
21+
return {};
2922
}
30-
31-
return true;
3223
}

src/deployers/Multimedia6PluginsDeployer.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
namespace linuxdeploy {
66
namespace plugin {
77
namespace qt {
8-
class Multimedia6PluginsDeployer : public BasicPluginsDeployer {
8+
class Multimedia6PluginsDeployer : public BasicPluginsDeployer
9+
{
910
public:
1011
// we can just use the base class's constructor
1112
using BasicPluginsDeployer::BasicPluginsDeployer;
1213

13-
bool deploy() override;
14+
std::vector<std::string> qtPluginsToBeDeployed() const override;
1415
};
1516
}
1617
}

src/deployers/PlatformPluginsDeployer.cpp

+26-26
Original file line numberDiff line numberDiff line change
@@ -13,47 +13,39 @@ using namespace linuxdeploy::core::log;
1313

1414
namespace fs = std::filesystem;
1515

16-
bool PlatformPluginsDeployer::deploy() {
17-
// calling the default code is optional, but it won't hurt for now
18-
if (!BasicPluginsDeployer::deploy())
19-
return false;
20-
16+
bool PlatformPluginsDeployer::customDeploy()
17+
{
2118
ldLog() << "Deploying platform plugins" << std::endl;
2219

2320
// always deploy default platform
24-
if (!appDir.deployLibrary(qtPluginsPath / "platforms/libqxcb.so", appDir.path() / "usr/plugins/platforms/"))
21+
if (!appDir.deployLibrary(qtPluginsPath / "platforms/libqxcb.so",
22+
appDir.path() / "usr/plugins/platforms/"))
2523
return false;
2624

2725
// deploy extra platform plugins, if any
28-
const auto* const platformPluginsFromEnvData = getenv("EXTRA_PLATFORM_PLUGINS");
26+
const auto *const platformPluginsFromEnvData = getenv("EXTRA_PLATFORM_PLUGINS");
2927
if (platformPluginsFromEnvData != nullptr) {
30-
for (const auto& platformToDeploy : linuxdeploy::util::split(std::string(platformPluginsFromEnvData), ';')) {
28+
for (const auto &platformToDeploy :
29+
linuxdeploy::util::split(std::string(platformPluginsFromEnvData), ';')) {
3130
ldLog() << "Deploying extra platform plugin: " << platformToDeploy << std::endl;
32-
if (!appDir.deployLibrary(qtPluginsPath / "platforms" / platformToDeploy, appDir.path() / "usr/plugins/platforms/"))
31+
if (!appDir.deployLibrary(qtPluginsPath / "platforms" / platformToDeploy,
32+
appDir.path() / "usr/plugins/platforms/"))
3333
return false;
3434
}
35-
}
36-
37-
for (fs::directory_iterator i(qtPluginsPath / "platforminputcontexts"); i != fs::directory_iterator(); ++i) {
38-
if (!appDir.deployLibrary(*i, appDir.path() / "usr/plugins/platforminputcontexts/"))
39-
return false;
4035
}
4136

42-
for (fs::directory_iterator i(qtPluginsPath / "imageformats"); i != fs::directory_iterator(); ++i) {
43-
if (!appDir.deployLibrary(*i, appDir.path() / "usr/plugins/imageformats/"))
44-
return false;
45-
}
46-
47-
// TODO: platform themes -- https://github.com/probonopd/linuxdeployqt/issues/236
37+
// TODO: platform themes --
38+
// https://github.com/probonopd/linuxdeployqt/issues/236
4839

4940
const fs::path platformThemesPath = qtPluginsPath / "platformthemes";
50-
const fs::path stylesPath = qtPluginsPath / "styles";
41+
const fs::path stylesPath = qtPluginsPath / "styles";
5142

5243
const fs::path platformThemesDestination = appDir.path() / "usr/plugins/platformthemes/";
53-
const fs::path stylesDestination = appDir.path() / "usr/plugins/styles/";
44+
const fs::path stylesDestination = appDir.path() / "usr/plugins/styles/";
5445

5546
if (getenv("DEPLOY_PLATFORM_THEMES") != nullptr) {
56-
ldLog() << LD_WARNING << "Deploying all platform themes and styles [experimental feature]" << std::endl;
47+
ldLog() << LD_WARNING << "Deploying all platform themes and styles [experimental feature]"
48+
<< std::endl;
5749

5850
if (fs::is_directory(platformThemesPath))
5951
for (fs::directory_iterator i(platformThemesPath); i != fs::directory_iterator(); ++i)
@@ -70,15 +62,23 @@ bool PlatformPluginsDeployer::deploy() {
7062
const auto libqxdgPath = platformThemesPath / "libqxdgdesktopportal.so";
7163

7264
for (const auto &file : {libqxdgPath}) {
73-
// we need to check whether the files exist at least, otherwise the deferred deployment operation fails
65+
// we need to check whether the files exist at least, otherwise the
66+
// deferred deployment operation fails
7467
if (fs::is_regular_file(file)) {
75-
ldLog() << "Attempting to deploy" << file.filename() << "found at path" << file.parent_path() << std::endl;
68+
ldLog() << "Attempting to deploy" << file.filename() << "found at path"
69+
<< file.parent_path() << std::endl;
7670
appDir.deployFile(file, platformThemesDestination);
7771
} else {
78-
ldLog() << "Could not find" << file.filename() << "on system, skipping deployment" << std::endl;
72+
ldLog() << "Could not find" << file.filename() << "on system, skipping deployment"
73+
<< std::endl;
7974
}
8075
}
8176
}
8277

8378
return true;
8479
}
80+
81+
std::vector<std::string> PlatformPluginsDeployer::qtPluginsToBeDeployed() const
82+
{
83+
return {"platforminputcontexts", "imageformats"};
84+
}

src/deployers/PlatformPluginsDeployer.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
namespace linuxdeploy {
66
namespace plugin {
77
namespace qt {
8-
class PlatformPluginsDeployer : public BasicPluginsDeployer {
8+
class PlatformPluginsDeployer : public BasicPluginsDeployer
9+
{
910
public:
1011
// we can just use the base class's constructor
1112
using BasicPluginsDeployer::BasicPluginsDeployer;
1213

13-
bool deploy() override;
14+
bool customDeploy() override;
15+
std::vector<std::string> qtPluginsToBeDeployed() const override;
1416
};
1517
}
1618
}

src/deployers/PluginsDeployer.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ namespace linuxdeploy {
88
/**
99
* Interface for deployer classes.
1010
*/
11-
class PluginsDeployer {
11+
class PluginsDeployer
12+
{
1213
public:
1314
virtual bool deploy() = 0;
1415
};

0 commit comments

Comments
 (0)