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 13, 2024
1 parent babb58d commit 80d9946
Show file tree
Hide file tree
Showing 36 changed files with 386 additions and 477 deletions.
45 changes: 33 additions & 12 deletions src/deployers/BasicPluginsDeployer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,42 @@ using namespace linuxdeploy::plugin::qt;
namespace fs = std::filesystem;

BasicPluginsDeployer::BasicPluginsDeployer(std::string moduleName,
core::appdir::AppDir& appDir,
core::appdir::AppDir &appDir,
fs::path qtPluginsPath,
fs::path qtLibexecsPath,
fs::path installLibsPath,
fs::path qtTranslationsPath,
fs::path qtDataPath) : moduleName(std::move(moduleName)),
appDir(appDir),
qtPluginsPath(std::move(qtPluginsPath)),
qtLibexecsPath(std::move(qtLibexecsPath)),
qtInstallQmlPath(std::move(installLibsPath)),
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
fs::path qtDataPath)
: moduleName(std::move(moduleName))
, appDir(appDir)
, qtPluginsPath(std::move(qtPluginsPath))
, qtLibexecsPath(std::move(qtLibexecsPath))
, qtInstallQmlPath(std::move(installLibsPath))
, qtTranslationsPath(std::move(qtTranslationsPath))
, qtDataPath(std::move(qtDataPath))
{
}

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 {};
}
106 changes: 63 additions & 43 deletions src/deployers/BasicPluginsDeployer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,67 @@
// local headers
#include "PluginsDeployer.h"


namespace linuxdeploy {
namespace plugin {
namespace qt {
/**
*
*/
class BasicPluginsDeployer : public PluginsDeployer {
protected:
std::string moduleName;
core::appdir::AppDir& appDir;

// Qt data
const std::filesystem::path qtPluginsPath;
const std::filesystem::path qtLibexecsPath;
const std::filesystem::path qtInstallQmlPath;
const std::filesystem::path qtTranslationsPath;
const std::filesystem::path qtDataPath;

public:
/**
* Default constructor. Constructs a basic deployer for a plugin with the given name.
*
* @param moduleName
*/
explicit BasicPluginsDeployer(std::string moduleName, core::appdir::AppDir& appDir,
std::filesystem::path qtPluginsPath,
std::filesystem::path qtLibexecsPath,
std::filesystem::path installLibsPath,
std::filesystem::path qtTranslationsPath,
std::filesystem::path qtDataPath);

/**
* Default destroyer is good enough for this class for now, but in case we need to change this we declare a virtual
* one.
*/
virtual ~BasicPluginsDeployer() = default;

public:
bool deploy() override;
};
}
}
}
namespace plugin {
namespace qt {
/**
*
*/
class BasicPluginsDeployer : public PluginsDeployer
{
protected:
std::string moduleName;
core::appdir::AppDir &appDir;

// Qt data
const std::filesystem::path qtPluginsPath;
const std::filesystem::path qtLibexecsPath;
const std::filesystem::path qtInstallQmlPath;
const std::filesystem::path qtTranslationsPath;
const std::filesystem::path qtDataPath;

public:
/**
* Default constructor. Constructs a basic deployer for a plugin with the
* given name.
*
* @param moduleName
*/
explicit BasicPluginsDeployer(std::string moduleName,
core::appdir::AppDir &appDir,
std::filesystem::path qtPluginsPath,
std::filesystem::path qtLibexecsPath,
std::filesystem::path installLibsPath,
std::filesystem::path qtTranslationsPath,
std::filesystem::path qtDataPath);

/**
* Default destroyer is good enough for this class for now, but in case we
* need to change this we declare a virtual one.
*/
virtual ~BasicPluginsDeployer() = default;

public:
/**
* 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;
};
} // namespace qt
} // namespace plugin
} // namespace linuxdeploy
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"};
}
23 changes: 12 additions & 11 deletions src/deployers/BearerPluginsDeployer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
#include "BasicPluginsDeployer.h"

namespace linuxdeploy {
namespace plugin {
namespace qt {
class BearerPluginsDeployer : public BasicPluginsDeployer {
public:
// we can just use the base class's constructor
using BasicPluginsDeployer::BasicPluginsDeployer;
namespace plugin {
namespace qt {
class BearerPluginsDeployer : 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;
};
} // namespace qt
} // namespace plugin
} // namespace linuxdeploy
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"};
}
23 changes: 12 additions & 11 deletions src/deployers/GamepadPluginsDeployer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
#include "BasicPluginsDeployer.h"

namespace linuxdeploy {
namespace plugin {
namespace qt {
class GamepadPluginsDeployer : public BasicPluginsDeployer {
public:
// we can just use the base class's constructor
using BasicPluginsDeployer::BasicPluginsDeployer;
namespace plugin {
namespace qt {
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;
};
} // namespace qt
} // namespace plugin
} // namespace linuxdeploy
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"};
}
23 changes: 12 additions & 11 deletions src/deployers/LocationPluginsDeployer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
#include "BasicPluginsDeployer.h"

namespace linuxdeploy {
namespace plugin {
namespace qt {
class LocationPluginsDeployer : public BasicPluginsDeployer {
public:
// we can just use the base class's constructor
using BasicPluginsDeployer::BasicPluginsDeployer;
namespace plugin {
namespace qt {
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;
};
} // namespace qt
} // namespace plugin
} // namespace linuxdeploy
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"};
}
23 changes: 12 additions & 11 deletions src/deployers/Multimedia5PluginsDeployer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
#include "BasicPluginsDeployer.h"

namespace linuxdeploy {
namespace plugin {
namespace qt {
class Multimedia5PluginsDeployer : public BasicPluginsDeployer {
public:
// we can just use the base class's constructor
using BasicPluginsDeployer::BasicPluginsDeployer;
namespace plugin {
namespace qt {
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;
};
} // namespace qt
} // namespace plugin
} // namespace linuxdeploy
Loading

0 comments on commit 80d9946

Please sign in to comment.