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 d00970d
Show file tree
Hide file tree
Showing 49 changed files with 486 additions and 497 deletions.
24 changes: 21 additions & 3 deletions src/deployers/BasicPluginsDeployer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,26 @@ BasicPluginsDeployer::BasicPluginsDeployer(std::string moduleName,
qtTranslationsPath(std::move(qtTranslationsPath)),
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
bool BasicPluginsDeployer::deploy()
{
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
18 changes: 3 additions & 15 deletions src/deployers/BearerPluginsDeployer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,7 @@
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
18 changes: 3 additions & 15 deletions src/deployers/GamepadPluginsDeployer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,7 @@
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"};
}
5 changes: 3 additions & 2 deletions src/deployers/GamepadPluginsDeployer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
namespace linuxdeploy {
namespace plugin {
namespace qt {
class GamepadPluginsDeployer : public BasicPluginsDeployer {
class GamepadPluginsDeployer : public BasicPluginsDeployer
{
public:
// we can just use the base class's constructor
using BasicPluginsDeployer::BasicPluginsDeployer;

bool deploy() override;
std::vector<std::string> qtPluginsToBeDeployed() const override;
};
}
}
Expand Down
18 changes: 3 additions & 15 deletions src/deployers/LocationPluginsDeployer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,7 @@
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"};
}
5 changes: 3 additions & 2 deletions src/deployers/LocationPluginsDeployer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
namespace linuxdeploy {
namespace plugin {
namespace qt {
class LocationPluginsDeployer : public BasicPluginsDeployer {
class LocationPluginsDeployer : public BasicPluginsDeployer
{
public:
// we can just use the base class's constructor
using BasicPluginsDeployer::BasicPluginsDeployer;

bool deploy() override;
std::vector<std::string> qtPluginsToBeDeployed() const override;
};
}
}
Expand Down
25 changes: 3 additions & 22 deletions src/deployers/Multimedia5PluginsDeployer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,7 @@
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"};
}
5 changes: 3 additions & 2 deletions src/deployers/Multimedia5PluginsDeployer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
namespace linuxdeploy {
namespace plugin {
namespace qt {
class Multimedia5PluginsDeployer : public BasicPluginsDeployer {
class Multimedia5PluginsDeployer : public BasicPluginsDeployer
{
public:
// 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: 4 additions & 13 deletions src/deployers/Multimedia6PluginsDeployer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,12 @@ 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;
}
5 changes: 3 additions & 2 deletions src/deployers/Multimedia6PluginsDeployer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
namespace linuxdeploy {
namespace plugin {
namespace qt {
class Multimedia6PluginsDeployer : public BasicPluginsDeployer {
class Multimedia6PluginsDeployer : public BasicPluginsDeployer
{
public:
// we can just use the base class's constructor
using BasicPluginsDeployer::BasicPluginsDeployer;

bool deploy() override;
std::vector<std::string> qtPluginsToBeDeployed() const override;
};
}
}
Expand Down
52 changes: 26 additions & 26 deletions src/deployers/PlatformPluginsDeployer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,39 @@ 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
if (!appDir.deployLibrary(qtPluginsPath / "platforms/libqxcb.so", appDir.path() / "usr/plugins/platforms/"))
if (!appDir.deployLibrary(qtPluginsPath / "platforms/libqxcb.so",
appDir.path() / "usr/plugins/platforms/"))
return false;

// deploy extra platform plugins, if any
const auto* const platformPluginsFromEnvData = getenv("EXTRA_PLATFORM_PLUGINS");
const auto *const platformPluginsFromEnvData = getenv("EXTRA_PLATFORM_PLUGINS");
if (platformPluginsFromEnvData != nullptr) {
for (const auto& platformToDeploy : linuxdeploy::util::split(std::string(platformPluginsFromEnvData), ';')) {
for (const auto &platformToDeploy :
linuxdeploy::util::split(std::string(platformPluginsFromEnvData), ';')) {
ldLog() << "Deploying extra platform plugin: " << platformToDeploy << std::endl;
if (!appDir.deployLibrary(qtPluginsPath / "platforms" / platformToDeploy, appDir.path() / "usr/plugins/platforms/"))
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
// TODO: platform themes --
// https://github.com/probonopd/linuxdeployqt/issues/236

const fs::path platformThemesPath = qtPluginsPath / "platformthemes";
const fs::path stylesPath = qtPluginsPath / "styles";
const fs::path stylesPath = qtPluginsPath / "styles";

const fs::path platformThemesDestination = appDir.path() / "usr/plugins/platformthemes/";
const fs::path stylesDestination = appDir.path() / "usr/plugins/styles/";
const fs::path stylesDestination = appDir.path() / "usr/plugins/styles/";

if (getenv("DEPLOY_PLATFORM_THEMES") != nullptr) {
ldLog() << LD_WARNING << "Deploying all platform themes and styles [experimental feature]" << std::endl;
ldLog() << LD_WARNING << "Deploying all platform themes and styles [experimental feature]"
<< std::endl;

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

for (const auto &file : {libqxdgPath}) {
// we need to check whether the files exist at least, otherwise the deferred deployment operation fails
// we need to check whether the files exist at least, otherwise the
// deferred deployment operation fails
if (fs::is_regular_file(file)) {
ldLog() << "Attempting to deploy" << file.filename() << "found at path" << file.parent_path() << std::endl;
ldLog() << "Attempting to deploy" << file.filename() << "found at path"
<< file.parent_path() << std::endl;
appDir.deployFile(file, platformThemesDestination);
} else {
ldLog() << "Could not find" << file.filename() << "on system, skipping deployment" << std::endl;
ldLog() << "Could not find" << file.filename() << "on system, skipping deployment"
<< std::endl;
}
}
}

return true;
}

std::vector<std::string> PlatformPluginsDeployer::qtPluginsToBeDeployed() const
{
return {"platforminputcontexts", "imageformats"};
}
6 changes: 4 additions & 2 deletions src/deployers/PlatformPluginsDeployer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
namespace linuxdeploy {
namespace plugin {
namespace qt {
class PlatformPluginsDeployer : public BasicPluginsDeployer {
class PlatformPluginsDeployer : public BasicPluginsDeployer
{
public:
// 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
3 changes: 2 additions & 1 deletion src/deployers/PluginsDeployer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ namespace linuxdeploy {
/**
* Interface for deployer classes.
*/
class PluginsDeployer {
class PluginsDeployer
{
public:
virtual bool deploy() = 0;
};
Expand Down
Loading

0 comments on commit d00970d

Please sign in to comment.