Skip to content

Commit

Permalink
Deduplicate Qt plugins deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
dantti committed Jun 18, 2024
1 parent babb58d commit 245d0bd
Show file tree
Hide file tree
Showing 37 changed files with 90 additions and 239 deletions.
18 changes: 16 additions & 2 deletions src/deployers/BasicPluginsDeployer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,21 @@ BasicPluginsDeployer::BasicPluginsDeployer(std::string moduleName,
qtDataPath(std::move(qtDataPath)) {}

bool BasicPluginsDeployer::deploy() {
// currently this is a no-op, but we might add more functionality later on, such as some kinds of default
// attempts to copy data based on the moduleName
for (const auto &pluginName : qtPluginsToBeDeployed()) {
ldLog() << "Deploying" << pluginName << "plugins" << std::endl;
for (fs::directory_iterator i(qtPluginsPath / pluginName); i != fs::directory_iterator(); ++i) {
if (!appDir.deployLibrary(*i, appDir.path() / "usr/plugins" / pluginName))
return false;
}
}

return customDeploy();
}

bool BasicPluginsDeployer::customDeploy() {
return true;
}

std::vector<std::string> BasicPluginsDeployer::qtPluginsToBeDeployed() const {
return {};
}
20 changes: 19 additions & 1 deletion src/deployers/BasicPluginsDeployer.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,25 @@ namespace linuxdeploy {
virtual ~BasicPluginsDeployer() = default;

public:
bool deploy() override;
/**
* This method deploys the plugins returned by \sa qtPluginsToBeDeployed()
* and call \sa customDeploy() to finalize the deployment.
*/
bool deploy() override final;

protected:
/**
* The \sa deploy() method can deploy Qt plugins that follow the default
* name and path scheme, but some modules are special so
* they should write custom deployment code.
*/
virtual bool customDeploy();

/**
* Returns a list of Qt plugin names that should be deployed and
* follow the default name and path scheme.
*/
virtual std::vector<std::string> qtPluginsToBeDeployed() const;
};
}
}
Expand Down
17 changes: 2 additions & 15 deletions src/deployers/BearerPluginsDeployer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,6 @@
using namespace linuxdeploy::plugin::qt;
using namespace linuxdeploy::core::log;

namespace fs = std::filesystem;

bool BearerPluginsDeployer::deploy() {
// calling the default code is optional, but it won't hurt for now
if (!BasicPluginsDeployer::deploy())
return false;

ldLog() << "Deploying bearer plugins" << std::endl;

for (fs::directory_iterator i(qtPluginsPath / "bearer"); i != fs::directory_iterator(); ++i) {
if (!appDir.deployLibrary(*i, appDir.path() / "usr/plugins/bearer/"))
return false;
}

return true;
std::vector<std::string> BearerPluginsDeployer::qtPluginsToBeDeployed() const {
return {"bearer"};
}
2 changes: 1 addition & 1 deletion src/deployers/BearerPluginsDeployer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace linuxdeploy {
// we can just use the base class's constructor
using BasicPluginsDeployer::BasicPluginsDeployer;

bool deploy() override;
std::vector<std::string> qtPluginsToBeDeployed() const override;
};
}
}
Expand Down
17 changes: 2 additions & 15 deletions src/deployers/GamepadPluginsDeployer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,6 @@
using namespace linuxdeploy::plugin::qt;
using namespace linuxdeploy::core::log;

namespace fs = std::filesystem;

bool GamepadPluginsDeployer::deploy() {
// calling the default code is optional, but it won't hurt for now
if (!BasicPluginsDeployer::deploy())
return false;

ldLog() << "Deploying Gamepad plugins" << std::endl;

for (fs::directory_iterator i(qtPluginsPath / "gamepads"); i != fs::directory_iterator(); ++i) {
if (!appDir.deployLibrary(*i, appDir.path() / "usr/plugins/gamepads/"))
return false;
}

return true;
std::vector<std::string> GamepadPluginsDeployer::qtPluginsToBeDeployed() const {
return {"gamepads"};
}
2 changes: 1 addition & 1 deletion src/deployers/GamepadPluginsDeployer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace linuxdeploy {
// we can just use the base class's constructor
using BasicPluginsDeployer::BasicPluginsDeployer;

bool deploy() override;
std::vector<std::string> qtPluginsToBeDeployed() const override;
};
}
}
Expand Down
17 changes: 2 additions & 15 deletions src/deployers/LocationPluginsDeployer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,6 @@
using namespace linuxdeploy::plugin::qt;
using namespace linuxdeploy::core::log;

namespace fs = std::filesystem;

bool LocationPluginsDeployer::deploy() {
// calling the default code is optional, but it won't hurt for now
if (!BasicPluginsDeployer::deploy())
return false;

ldLog() << "Deploying Location plugins" << std::endl;

for (fs::directory_iterator i(qtPluginsPath / "geoservices"); i != fs::directory_iterator(); ++i) {
if (!appDir.deployLibrary(*i, appDir.path() / "usr/plugins/geoservices/"))
return false;
}

return true;
std::vector<std::string> LocationPluginsDeployer::qtPluginsToBeDeployed() const {
return {"geoservices"};
}
2 changes: 1 addition & 1 deletion src/deployers/LocationPluginsDeployer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace linuxdeploy {
// we can just use the base class's constructor
using BasicPluginsDeployer::BasicPluginsDeployer;

bool deploy() override;
std::vector<std::string> qtPluginsToBeDeployed() const override;
};
}
}
Expand Down
24 changes: 2 additions & 22 deletions src/deployers/Multimedia5PluginsDeployer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,6 @@
using namespace linuxdeploy::plugin::qt;
using namespace linuxdeploy::core::log;

namespace fs = std::filesystem;

bool Multimedia5PluginsDeployer::deploy() {
// calling the default code is optional, but it won't hurt for now
if (!BasicPluginsDeployer::deploy())
return false;

ldLog() << "Deploying mediaservice plugins" << std::endl;

for (fs::directory_iterator i(qtPluginsPath / "mediaservice"); i != fs::directory_iterator(); ++i) {
if (!appDir.deployLibrary(*i, appDir.path() / "usr/plugins/mediaservice/"))
return false;
}

ldLog() << "Deploying audio plugins" << std::endl;

for (fs::directory_iterator i(qtPluginsPath / "audio"); i != fs::directory_iterator(); ++i) {
if (!appDir.deployLibrary(*i, appDir.path() / "usr/plugins/audio/"))
return false;
}

return true;
std::vector<std::string> Multimedia5PluginsDeployer::qtPluginsToBeDeployed() const {
return {"mediaservice", "audio"};
}
2 changes: 1 addition & 1 deletion src/deployers/Multimedia5PluginsDeployer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace linuxdeploy {
// we can just use the base class's constructor
using BasicPluginsDeployer::BasicPluginsDeployer;

bool deploy() override;
std::vector<std::string> qtPluginsToBeDeployed() const override;
};
}
}
Expand Down
16 changes: 3 additions & 13 deletions src/deployers/Multimedia6PluginsDeployer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,11 @@ using namespace linuxdeploy::core::log;

namespace fs = std::filesystem;

bool Multimedia6PluginsDeployer::deploy() {
// calling the default code is optional, but it won't hurt for now
if (!BasicPluginsDeployer::deploy())
return false;

std::vector<std::string> Multimedia6PluginsDeployer::qtPluginsToBeDeployed() const {
if (fs::exists(qtPluginsPath / "multimedia")) {
ldLog() << "Deploying multimedia plugins" << std::endl;

for (fs::directory_iterator i(qtPluginsPath / "multimedia"); i != fs::directory_iterator(); ++i) {
if (!appDir.deployLibrary(*i, appDir.path() / "usr/plugins/multimedia/"))
return false;
}
return {"multimedia"};
} else {
ldLog() << LD_WARNING << "Missing Qt 6 multimedia plugins, skipping." << std::endl;
return {};
}

return true;
}
2 changes: 1 addition & 1 deletion src/deployers/Multimedia6PluginsDeployer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace linuxdeploy {
// we can just use the base class's constructor
using BasicPluginsDeployer::BasicPluginsDeployer;

bool deploy() override;
std::vector<std::string> qtPluginsToBeDeployed() const override;
};
}
}
Expand Down
20 changes: 5 additions & 15 deletions src/deployers/PlatformPluginsDeployer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ using namespace linuxdeploy::core::log;

namespace fs = std::filesystem;

bool PlatformPluginsDeployer::deploy() {
// calling the default code is optional, but it won't hurt for now
if (!BasicPluginsDeployer::deploy())
return false;

bool PlatformPluginsDeployer::customDeploy() {
ldLog() << "Deploying platform plugins" << std::endl;

// always deploy default platform
Expand All @@ -32,16 +28,6 @@ bool PlatformPluginsDeployer::deploy() {
if (!appDir.deployLibrary(qtPluginsPath / "platforms" / platformToDeploy, appDir.path() / "usr/plugins/platforms/"))
return false;
}
}

for (fs::directory_iterator i(qtPluginsPath / "platforminputcontexts"); i != fs::directory_iterator(); ++i) {
if (!appDir.deployLibrary(*i, appDir.path() / "usr/plugins/platforminputcontexts/"))
return false;
}

for (fs::directory_iterator i(qtPluginsPath / "imageformats"); i != fs::directory_iterator(); ++i) {
if (!appDir.deployLibrary(*i, appDir.path() / "usr/plugins/imageformats/"))
return false;
}

// TODO: platform themes -- https://github.com/probonopd/linuxdeployqt/issues/236
Expand Down Expand Up @@ -82,3 +68,7 @@ bool PlatformPluginsDeployer::deploy() {

return true;
}

std::vector<std::string> PlatformPluginsDeployer::qtPluginsToBeDeployed() const {
return {"platforminputcontexts", "imageformats"};
}
3 changes: 2 additions & 1 deletion src/deployers/PlatformPluginsDeployer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ namespace linuxdeploy {
// we can just use the base class's constructor
using BasicPluginsDeployer::BasicPluginsDeployer;

bool deploy() override;
bool customDeploy() override;
std::vector<std::string> qtPluginsToBeDeployed() const override;
};
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/deployers/PluginsDeployerFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ std::vector<std::shared_ptr<PluginsDeployer>> PluginsDeployerFactory::getDeploye
}

if (moduleName == "multimedia") {
if (qtMajorVersion < 6) {
if (qtMajorVersion < 6) {
return {getInstance<Multimedia5PluginsDeployer>(moduleName)};
} else {
} else {
return {getInstance<Multimedia6PluginsDeployer>(moduleName)};
}
}
Expand Down
17 changes: 2 additions & 15 deletions src/deployers/PositioningPluginsDeployer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,6 @@
using namespace linuxdeploy::plugin::qt;
using namespace linuxdeploy::core::log;

namespace fs = std::filesystem;

bool PositioningPluginsDeployer::deploy() {
// calling the default code is optional, but it won't hurt for now
if (!BasicPluginsDeployer::deploy())
return false;

ldLog() << "Deploying positioning plugins" << std::endl;

for (fs::directory_iterator i(qtPluginsPath / "position"); i != fs::directory_iterator(); ++i) {
if (!appDir.deployLibrary(*i, appDir.path() / "usr/plugins/position/"))
return false;
}

return true;
std::vector<std::string> PositioningPluginsDeployer::qtPluginsToBeDeployed() const {
return {"position"};
}
2 changes: 1 addition & 1 deletion src/deployers/PositioningPluginsDeployer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace linuxdeploy {
// we can just use the base class's constructor
using BasicPluginsDeployer::BasicPluginsDeployer;

bool deploy() override;
std::vector<std::string> qtPluginsToBeDeployed() const override;
};
}
}
Expand Down
17 changes: 2 additions & 15 deletions src/deployers/PrintSupportPluginsDeployer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,6 @@
using namespace linuxdeploy::plugin::qt;
using namespace linuxdeploy::core::log;

namespace fs = std::filesystem;

bool PrintSupportPluginsDeployer::deploy() {
// calling the default code is optional, but it won't hurt for now
if (!BasicPluginsDeployer::deploy())
return false;

ldLog() << "Deploying printsupport plugins" << std::endl;

for (fs::directory_iterator i(qtPluginsPath / "printsupport"); i != fs::directory_iterator(); ++i) {
if (!appDir.deployLibrary(*i, appDir.path() / "usr/plugins/printsupport/"))
return false;
}

return true;
std::vector<std::string> PrintSupportPluginsDeployer::qtPluginsToBeDeployed() const {
return {"printsupport"};
}
2 changes: 1 addition & 1 deletion src/deployers/PrintSupportPluginsDeployer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace linuxdeploy {
// we can just use the base class's constructor
using BasicPluginsDeployer::BasicPluginsDeployer;

bool deploy() override;
std::vector<std::string> qtPluginsToBeDeployed() const override;
};
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/deployers/QmlPluginsDeployer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ using namespace linuxdeploy::plugin::qt;

namespace fs = std::filesystem;

bool QmlPluginsDeployer::deploy() {
// calling the default code is optional, but it won't hurt for now
if (!BasicPluginsDeployer::deploy())
return false;

bool QmlPluginsDeployer::customDeploy() {
try {
deployQml(appDir, qtInstallQmlPath);
} catch (const QmlImportScannerError &) {
Expand Down
2 changes: 1 addition & 1 deletion src/deployers/QmlPluginsDeployer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace linuxdeploy {
// we can just use the base class's constructor
using BasicPluginsDeployer::BasicPluginsDeployer;

bool deploy() override;
bool customDeploy() override;
};
}
}
Expand Down
22 changes: 2 additions & 20 deletions src/deployers/Qt3DPluginsDeployer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,6 @@
using namespace linuxdeploy::plugin::qt;
using namespace linuxdeploy::core::log;

namespace fs = std::filesystem;

bool Qt3DPluginsDeployer::deploy() {
// calling the default code is optional, but it won't hurt for now
if (!BasicPluginsDeployer::deploy())
return false;

ldLog() << "Deploying Qt 3D plugins" << std::endl;

for (fs::directory_iterator i(qtPluginsPath / "geometryloaders"); i != fs::directory_iterator(); ++i) {
if (!appDir.deployLibrary(*i, appDir.path() / "usr/plugins/geometryloaders/"))
return false;
}

for (fs::directory_iterator i(qtPluginsPath / "sceneparsers"); i != fs::directory_iterator(); ++i) {
if (!appDir.deployLibrary(*i, appDir.path() / "usr/plugins/sceneparsers/"))
return false;
}

return true;
std::vector<std::string> Qt3DPluginsDeployer::qtPluginsToBeDeployed() const {
return {"geometryloaders", "sceneparsers"};
}
2 changes: 1 addition & 1 deletion src/deployers/Qt3DPluginsDeployer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace linuxdeploy {
// we can just use the base class's constructor
using BasicPluginsDeployer::BasicPluginsDeployer;

bool deploy() override;
std::vector<std::string> qtPluginsToBeDeployed() const override;
};
}
}
Expand Down
Loading

0 comments on commit 245d0bd

Please sign in to comment.