Skip to content

Commit 0dd355f

Browse files
committed
Deduplicate Qt plugins deployment
1 parent babb58d commit 0dd355f

36 files changed

+389
-477
lines changed

src/deployers/BasicPluginsDeployer.cpp

+36-12
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,45 @@ using namespace linuxdeploy::plugin::qt;
1515
namespace fs = std::filesystem;
1616

1717
BasicPluginsDeployer::BasicPluginsDeployer(std::string moduleName,
18-
core::appdir::AppDir& appDir,
18+
core::appdir::AppDir &appDir,
1919
fs::path qtPluginsPath,
2020
fs::path qtLibexecsPath,
2121
fs::path installLibsPath,
2222
fs::path qtTranslationsPath,
23-
fs::path qtDataPath) : moduleName(std::move(moduleName)),
24-
appDir(appDir),
25-
qtPluginsPath(std::move(qtPluginsPath)),
26-
qtLibexecsPath(std::move(qtLibexecsPath)),
27-
qtInstallQmlPath(std::move(installLibsPath)),
28-
qtTranslationsPath(std::move(qtTranslationsPath)),
29-
qtDataPath(std::move(qtDataPath)) {}
30-
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
23+
fs::path qtDataPath)
24+
: moduleName(std::move(moduleName))
25+
, appDir(appDir)
26+
, qtPluginsPath(std::move(qtPluginsPath))
27+
, qtLibexecsPath(std::move(qtLibexecsPath))
28+
, qtInstallQmlPath(std::move(installLibsPath))
29+
, qtTranslationsPath(std::move(qtTranslationsPath))
30+
, qtDataPath(std::move(qtDataPath))
31+
{
32+
}
33+
34+
bool BasicPluginsDeployer::deploy()
35+
{
36+
// currently this is a no-op, but we might add more functionality later on,
37+
// such as some kinds of default attempts to copy data based on the moduleName
38+
39+
for (const auto &pluginName : qtPluginsToBeDeployed()) {
40+
ldLog() << "Deploying" << pluginName << "plugins" << std::endl;
41+
for (fs::directory_iterator i(qtPluginsPath / pluginName); i != fs::directory_iterator();
42+
++i) {
43+
if (!appDir.deployLibrary(*i, appDir.path() / "usr/plugins" / pluginName))
44+
return false;
45+
}
46+
}
47+
48+
return customDeploy();
49+
}
50+
51+
bool BasicPluginsDeployer::customDeploy()
52+
{
3453
return true;
3554
}
55+
56+
std::vector<std::string> BasicPluginsDeployer::qtPluginsToBeDeployed() const
57+
{
58+
return {};
59+
}

src/deployers/BasicPluginsDeployer.h

+63-43
Original file line numberDiff line numberDiff line change
@@ -10,47 +10,67 @@
1010
// local headers
1111
#include "PluginsDeployer.h"
1212

13-
1413
namespace linuxdeploy {
15-
namespace plugin {
16-
namespace qt {
17-
/**
18-
*
19-
*/
20-
class BasicPluginsDeployer : public PluginsDeployer {
21-
protected:
22-
std::string moduleName;
23-
core::appdir::AppDir& appDir;
24-
25-
// Qt data
26-
const std::filesystem::path qtPluginsPath;
27-
const std::filesystem::path qtLibexecsPath;
28-
const std::filesystem::path qtInstallQmlPath;
29-
const std::filesystem::path qtTranslationsPath;
30-
const std::filesystem::path qtDataPath;
31-
32-
public:
33-
/**
34-
* Default constructor. Constructs a basic deployer for a plugin with the given name.
35-
*
36-
* @param moduleName
37-
*/
38-
explicit BasicPluginsDeployer(std::string moduleName, core::appdir::AppDir& appDir,
39-
std::filesystem::path qtPluginsPath,
40-
std::filesystem::path qtLibexecsPath,
41-
std::filesystem::path installLibsPath,
42-
std::filesystem::path qtTranslationsPath,
43-
std::filesystem::path qtDataPath);
44-
45-
/**
46-
* Default destroyer is good enough for this class for now, but in case we need to change this we declare a virtual
47-
* one.
48-
*/
49-
virtual ~BasicPluginsDeployer() = default;
50-
51-
public:
52-
bool deploy() override;
53-
};
54-
}
55-
}
56-
}
14+
namespace plugin {
15+
namespace qt {
16+
/**
17+
*
18+
*/
19+
class BasicPluginsDeployer : public PluginsDeployer
20+
{
21+
protected:
22+
std::string moduleName;
23+
core::appdir::AppDir &appDir;
24+
25+
// Qt data
26+
const std::filesystem::path qtPluginsPath;
27+
const std::filesystem::path qtLibexecsPath;
28+
const std::filesystem::path qtInstallQmlPath;
29+
const std::filesystem::path qtTranslationsPath;
30+
const std::filesystem::path qtDataPath;
31+
32+
public:
33+
/**
34+
* Default constructor. Constructs a basic deployer for a plugin with the
35+
* given name.
36+
*
37+
* @param moduleName
38+
*/
39+
explicit BasicPluginsDeployer(std::string moduleName,
40+
core::appdir::AppDir &appDir,
41+
std::filesystem::path qtPluginsPath,
42+
std::filesystem::path qtLibexecsPath,
43+
std::filesystem::path installLibsPath,
44+
std::filesystem::path qtTranslationsPath,
45+
std::filesystem::path qtDataPath);
46+
47+
/**
48+
* Default destroyer is good enough for this class for now, but in case we
49+
* need to change this we declare a virtual one.
50+
*/
51+
virtual ~BasicPluginsDeployer() = default;
52+
53+
public:
54+
/**
55+
* This method deploys the plugins returned by \sa qtPluginsToBeDeployed()
56+
* and call \sa customDeploy() to finalize the deployment.
57+
*/
58+
bool deploy() override final;
59+
60+
protected:
61+
/**
62+
* The \sa deploy() method can deploy Qt plugins that follow the default
63+
* name and path scheme, but some modules are special so
64+
* they should write custom deployment code.
65+
*/
66+
virtual bool customDeploy();
67+
68+
/**
69+
* Returns a list of Qt plugin names that should be deployed and
70+
* follow the default name and path scheme.
71+
*/
72+
virtual std::vector<std::string> qtPluginsToBeDeployed() const;
73+
};
74+
} // namespace qt
75+
} // namespace plugin
76+
} // namespace linuxdeploy

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

+12-11
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
#include "BasicPluginsDeployer.h"
44

55
namespace linuxdeploy {
6-
namespace plugin {
7-
namespace qt {
8-
class BearerPluginsDeployer : public BasicPluginsDeployer {
9-
public:
10-
// we can just use the base class's constructor
11-
using BasicPluginsDeployer::BasicPluginsDeployer;
6+
namespace plugin {
7+
namespace qt {
8+
class BearerPluginsDeployer : public BasicPluginsDeployer
9+
{
10+
public:
11+
// we can just use the base class's constructor
12+
using BasicPluginsDeployer::BasicPluginsDeployer;
1213

13-
bool deploy() override;
14-
};
15-
}
16-
}
17-
}
14+
std::vector<std::string> qtPluginsToBeDeployed() const override;
15+
};
16+
} // namespace qt
17+
} // namespace plugin
18+
} // namespace linuxdeploy

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

+12-11
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
#include "BasicPluginsDeployer.h"
44

55
namespace linuxdeploy {
6-
namespace plugin {
7-
namespace qt {
8-
class GamepadPluginsDeployer : public BasicPluginsDeployer {
9-
public:
10-
// we can just use the base class's constructor
11-
using BasicPluginsDeployer::BasicPluginsDeployer;
6+
namespace plugin {
7+
namespace qt {
8+
class GamepadPluginsDeployer : public BasicPluginsDeployer
9+
{
10+
public:
11+
// we can just use the base class's constructor
12+
using BasicPluginsDeployer::BasicPluginsDeployer;
1213

13-
bool deploy() override;
14-
};
15-
}
16-
}
17-
}
14+
std::vector<std::string> qtPluginsToBeDeployed() const override;
15+
};
16+
} // namespace qt
17+
} // namespace plugin
18+
} // namespace linuxdeploy

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

+12-11
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
#include "BasicPluginsDeployer.h"
44

55
namespace linuxdeploy {
6-
namespace plugin {
7-
namespace qt {
8-
class LocationPluginsDeployer : public BasicPluginsDeployer {
9-
public:
10-
// we can just use the base class's constructor
11-
using BasicPluginsDeployer::BasicPluginsDeployer;
6+
namespace plugin {
7+
namespace qt {
8+
class LocationPluginsDeployer : public BasicPluginsDeployer
9+
{
10+
public:
11+
// we can just use the base class's constructor
12+
using BasicPluginsDeployer::BasicPluginsDeployer;
1213

13-
bool deploy() override;
14-
};
15-
}
16-
}
17-
}
14+
std::vector<std::string> qtPluginsToBeDeployed() const override;
15+
};
16+
} // namespace qt
17+
} // namespace plugin
18+
} // namespace linuxdeploy

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

+12-11
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
#include "BasicPluginsDeployer.h"
44

55
namespace linuxdeploy {
6-
namespace plugin {
7-
namespace qt {
8-
class Multimedia5PluginsDeployer : public BasicPluginsDeployer {
9-
public:
10-
// we can just use the base class's constructor
11-
using BasicPluginsDeployer::BasicPluginsDeployer;
6+
namespace plugin {
7+
namespace qt {
8+
class Multimedia5PluginsDeployer : public BasicPluginsDeployer
9+
{
10+
public:
11+
// we can just use the base class's constructor
12+
using BasicPluginsDeployer::BasicPluginsDeployer;
1213

13-
bool deploy() override;
14-
};
15-
}
16-
}
17-
}
14+
std::vector<std::string> qtPluginsToBeDeployed() const override;
15+
};
16+
} // namespace qt
17+
} // namespace plugin
18+
} // namespace linuxdeploy

0 commit comments

Comments
 (0)