aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoremixa-d <85313564+emixa-d@users.noreply.github.com>2021-10-06 22:19:41 +0000
committerGitHub <noreply@github.com>2021-10-07 00:19:41 +0200
commit9fab5d594cab4c0a027f0aecf356382f3a37c1de (patch)
treea5bed4dfac50fcd76464dfb2010713fa4265e5e2 /src
parent53e126ac49807d066328377c7c06352b0fc1a380 (diff)
downloadminetest-9fab5d594cab4c0a027f0aecf356382f3a37c1de.tar.gz
minetest-9fab5d594cab4c0a027f0aecf356382f3a37c1de.tar.bz2
minetest-9fab5d594cab4c0a027f0aecf356382f3a37c1de.zip
Add "MINETEST_MOD_PATH" environment variable (#11515)
This adds an environment variable MINETEST_MOD_PATH. When it exists, Minetest will look there for mods in addition to ~/.minetest/mods/.
Diffstat (limited to 'src')
-rw-r--r--src/content/subgames.cpp14
-rw-r--r--src/content/subgames.h2
-rw-r--r--src/script/lua_api/l_mainmenu.cpp17
-rw-r--r--src/script/lua_api/l_mainmenu.h2
-rw-r--r--src/unittest/CMakeLists.txt1
-rw-r--r--src/unittest/test_config.h.in1
-rw-r--r--src/unittest/test_mod/test_mod/init.lua1
-rw-r--r--src/unittest/test_mod/test_mod/mod.conf2
-rw-r--r--src/unittest/test_servermodmanager.cpp21
9 files changed, 61 insertions, 0 deletions
diff --git a/src/content/subgames.cpp b/src/content/subgames.cpp
index e9dc609b0..30447c838 100644
--- a/src/content/subgames.cpp
+++ b/src/content/subgames.cpp
@@ -113,6 +113,10 @@ SubgameSpec findSubgame(const std::string &id)
if (user != share || user_game)
mods_paths.insert(user + DIR_DELIM + "mods");
+ for (const std::string &mod_path : getEnvModPaths()) {
+ mods_paths.insert(mod_path);
+ }
+
// Get meta
std::string conf_path = game_path + DIR_DELIM + "game.conf";
Settings conf;
@@ -384,3 +388,13 @@ void loadGameConfAndInitWorld(const std::string &path, const std::string &name,
if (new_game_settings)
delete game_settings;
}
+
+std::vector<std::string> getEnvModPaths()
+{
+ const char *c_mod_path = getenv("MINETEST_MOD_PATH");
+ std::vector<std::string> paths;
+ Strfnd search_paths(c_mod_path ? c_mod_path : "");
+ while (!search_paths.at_end())
+ paths.push_back(search_paths.next(PATH_DELIM));
+ return paths;
+}
diff --git a/src/content/subgames.h b/src/content/subgames.h
index 60392639b..4a50803e8 100644
--- a/src/content/subgames.h
+++ b/src/content/subgames.h
@@ -58,6 +58,8 @@ SubgameSpec findWorldSubgame(const std::string &world_path);
std::set<std::string> getAvailableGameIds();
std::vector<SubgameSpec> getAvailableGames();
+// Get the list of paths to mods in the environment variable $MINETEST_MOD_PATH
+std::vector<std::string> getEnvModPaths();
bool getWorldExists(const std::string &world_path);
//! Try to get the displayed name of a world
diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp
index 6e9a5c34f..57fddc0be 100644
--- a/src/script/lua_api/l_mainmenu.cpp
+++ b/src/script/lua_api/l_mainmenu.cpp
@@ -503,6 +503,21 @@ int ModApiMainMenu::l_get_modpath(lua_State *L)
}
/******************************************************************************/
+int ModApiMainMenu::l_get_modpaths(lua_State *L)
+{
+ int index = 1;
+ lua_newtable(L);
+ ModApiMainMenu::l_get_modpath(L);
+ lua_rawseti(L, -2, index);
+ for (const std::string &component : getEnvModPaths()) {
+ index++;
+ lua_pushstring(L, component.c_str());
+ lua_rawseti(L, -2, index);
+ }
+ return 1;
+}
+
+/******************************************************************************/
int ModApiMainMenu::l_get_clientmodpath(lua_State *L)
{
std::string modpath = fs::RemoveRelativePathComponents(
@@ -856,6 +871,7 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
API_FCT(get_mapgen_names);
API_FCT(get_user_path);
API_FCT(get_modpath);
+ API_FCT(get_modpaths);
API_FCT(get_clientmodpath);
API_FCT(get_gamepath);
API_FCT(get_texturepath);
@@ -889,6 +905,7 @@ void ModApiMainMenu::InitializeAsync(lua_State *L, int top)
API_FCT(get_mapgen_names);
API_FCT(get_user_path);
API_FCT(get_modpath);
+ API_FCT(get_modpaths);
API_FCT(get_clientmodpath);
API_FCT(get_gamepath);
API_FCT(get_texturepath);
diff --git a/src/script/lua_api/l_mainmenu.h b/src/script/lua_api/l_mainmenu.h
index ec2d20da2..781185425 100644
--- a/src/script/lua_api/l_mainmenu.h
+++ b/src/script/lua_api/l_mainmenu.h
@@ -112,6 +112,8 @@ private:
static int l_get_modpath(lua_State *L);
+ static int l_get_modpaths(lua_State *L);
+
static int l_get_clientmodpath(lua_State *L);
static int l_get_gamepath(lua_State *L);
diff --git a/src/unittest/CMakeLists.txt b/src/unittest/CMakeLists.txt
index 5703b8906..52f870901 100644
--- a/src/unittest/CMakeLists.txt
+++ b/src/unittest/CMakeLists.txt
@@ -44,6 +44,7 @@ set (UNITTEST_CLIENT_SRCS
set (TEST_WORLDDIR ${CMAKE_CURRENT_SOURCE_DIR}/test_world)
set (TEST_SUBGAME_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../games/devtest)
+set (TEST_MOD_PATH ${CMAKE_CURRENT_SOURCE_DIR}/test_mod)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/test_config.h.in"
diff --git a/src/unittest/test_config.h.in b/src/unittest/test_config.h.in
index 36850b00d..50d2398e4 100644
--- a/src/unittest/test_config.h.in
+++ b/src/unittest/test_config.h.in
@@ -4,3 +4,4 @@
#define TEST_WORLDDIR "@TEST_WORLDDIR@"
#define TEST_SUBGAME_PATH "@TEST_SUBGAME_PATH@"
+#define TEST_MOD_PATH "@TEST_MOD_PATH@"
diff --git a/src/unittest/test_mod/test_mod/init.lua b/src/unittest/test_mod/test_mod/init.lua
new file mode 100644
index 000000000..724a863f5
--- /dev/null
+++ b/src/unittest/test_mod/test_mod/init.lua
@@ -0,0 +1 @@
+-- deliberately empty
diff --git a/src/unittest/test_mod/test_mod/mod.conf b/src/unittest/test_mod/test_mod/mod.conf
new file mode 100644
index 000000000..56c64b2d8
--- /dev/null
+++ b/src/unittest/test_mod/test_mod/mod.conf
@@ -0,0 +1,2 @@
+name = test_mod
+description = A mod doing nothing, to test if MINETEST_MOD_PATH is recognised
diff --git a/src/unittest/test_servermodmanager.cpp b/src/unittest/test_servermodmanager.cpp
index e3edb0c32..4c473d8b5 100644
--- a/src/unittest/test_servermodmanager.cpp
+++ b/src/unittest/test_servermodmanager.cpp
@@ -48,14 +48,20 @@ static TestServerModManager g_test_instance;
void TestServerModManager::runTests(IGameDef *gamedef)
{
const char *saved_env_mt_subgame_path = getenv("MINETEST_SUBGAME_PATH");
+ const char *saved_env_mt_mod_path = getenv("MINETEST_MOD_PATH");
#ifdef WIN32
{
std::string subgame_path("MINETEST_SUBGAME_PATH=");
subgame_path.append(TEST_SUBGAME_PATH);
_putenv(subgame_path.c_str());
+
+ std::string mod_path("MINETEST_MOD_PATH=");
+ mod_path.append(TEST_MOD_PATH);
+ _putenv(mod_path.c_str());
}
#else
setenv("MINETEST_SUBGAME_PATH", TEST_SUBGAME_PATH, 1);
+ setenv("MINETEST_MOD_PATH", TEST_MOD_PATH, 1);
#endif
TEST(testCreation);
@@ -75,12 +81,21 @@ void TestServerModManager::runTests(IGameDef *gamedef)
if (saved_env_mt_subgame_path)
subgame_path.append(saved_env_mt_subgame_path);
_putenv(subgame_path.c_str());
+
+ std::string mod_path("MINETEST_MOD_PATH=");
+ if (saved_env_mt_mod_path)
+ mod_path.append(saved_env_mt_mod_path);
+ _putenv(mod_path.c_str());
}
#else
if (saved_env_mt_subgame_path)
setenv("MINETEST_SUBGAME_PATH", saved_env_mt_subgame_path, 1);
else
unsetenv("MINETEST_SUBGAME_PATH");
+ if (saved_env_mt_mod_path)
+ setenv("MINETEST_MOD_PATH", saved_env_mt_mod_path, 1);
+ else
+ unsetenv("MINETEST_MOD_PATH");
#endif
}
@@ -89,6 +104,7 @@ void TestServerModManager::testCreation()
std::string path = std::string(TEST_WORLDDIR) + DIR_DELIM + "world.mt";
Settings world_config;
world_config.set("gameid", "devtest");
+ world_config.set("load_mod_test_mod", "true");
UASSERTEQ(bool, world_config.updateConfigFile(path.c_str()), true);
ServerModManager sm(TEST_WORLDDIR);
}
@@ -119,16 +135,21 @@ void TestServerModManager::testGetMods()
UASSERTEQ(bool, mods.empty(), false);
// Ensure we found basenodes mod (part of devtest)
+ // and test_mod (for testing MINETEST_MOD_PATH).
bool default_found = false;
+ bool test_mod_found = false;
for (const auto &m : mods) {
if (m.name == "basenodes")
default_found = true;
+ if (m.name == "test_mod")
+ test_mod_found = true;
// Verify if paths are not empty
UASSERTEQ(bool, m.path.empty(), false);
}
UASSERTEQ(bool, default_found, true);
+ UASSERTEQ(bool, test_mod_found, true);
}
void TestServerModManager::testGetModspec()