From bebf2036c929089f8e654aa93919e199e3d106b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Sat, 25 Jul 2020 13:00:24 +0200 Subject: [PATCH 1/2] lookup mob.ini in parent folders and make prefix relative to .ini containing it --- src/conf.cpp | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/conf.cpp b/src/conf.cpp index f7a84c3..7a0c32c 100644 --- a/src/conf.cpp +++ b/src/conf.cpp @@ -980,13 +980,19 @@ std::vector find_inis( { MOB_ASSERT(!master.empty()); - const auto in_cwd = fs::current_path() / master_ini_filename(); - if (fs::exists(in_cwd) && !fs::equivalent(in_cwd, master)) - { - if (verbose) - u8cout << "also found in cwd " << path_to_utf8(in_cwd) << "\n"; + auto cwd = fs::current_path(); - v.push_back({"cwd", fs::canonical(in_cwd)}); + while (!cwd.empty()) { + const auto in_cwd = cwd / master_ini_filename(); + if (fs::exists(in_cwd) && !fs::equivalent(in_cwd, master)) + { + if (verbose) + u8cout << "also found in cwd " << path_to_utf8(in_cwd) << "\n"; + + v.push_back({ "cwd", fs::canonical(in_cwd) }); + break; + } + cwd = cwd.parent_path(); } } @@ -1070,10 +1076,18 @@ void init_options( { MOB_ASSERT(!inis.empty()); + // Keep track of the INI that contained a prefix: + fs::path ini_prefix; bool add = true; for (auto&& ini : inis) { + // Check if the prefix is set by this ini file: + fs::path cprefix = add ? fs::path{} : paths::prefix(); parse_ini(ini, add); + + if (paths::prefix() != cprefix) + ini_prefix = ini; + add = false; } @@ -1085,6 +1099,11 @@ void init_options( { const auto po = parse_option(o); + if (po.section == "paths" && po.key == "prefix") + { + ini_prefix = ""; + } + if (po.task.empty()) { conf::set_global(po.section, po.key, po.value); @@ -1142,7 +1161,7 @@ void init_options( this_env::append_to_path(conf::path_by_name("qt_bin")); if (!paths::prefix().empty()) - make_canonical_path("prefix", fs::current_path(), ""); + make_canonical_path("prefix", ini_prefix.empty() ? fs::current_path() : ini_prefix.parent_path(), ""); make_canonical_path("cache", paths::prefix(), "downloads"); make_canonical_path("build", paths::prefix(), "build"); From 5b946cd7984023aa69ae9efad3d1804680f4005f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Tue, 1 Sep 2020 19:53:10 +0200 Subject: [PATCH 2/2] Create mob.ini in build directory when not present --- src/commands.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/commands.cpp b/src/commands.cpp index 9cfd0ac..63581a5 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -502,6 +502,17 @@ int build_command::do_run() { try { + // Create a mob.ini in the build folder. + if (!exists(paths::prefix())) { + create_directory(paths::prefix()); + } + auto prefix_ini = paths::prefix() / "mob.ini"; + if (!exists(prefix_ini)) + { + std::ofstream out(prefix_ini); + out << "[paths]\n" << "prefix = .\n"; + } + run_all_tasks(); if (do_timings)