Skip to content

Commit 19f25ef

Browse files
committed
chore: new config from base config
1 parent b39afbd commit 19f25ef

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

lib/Tool/ConfigImpl.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,16 @@ ConfigImpl(
7070
llvm::StringRef workingDir_,
7171
llvm::StringRef addonsDir_,
7272
llvm::StringRef configYaml_,
73-
llvm::StringRef extraYaml_)
73+
llvm::StringRef extraYaml_,
74+
ConfigImpl const* base)
7475
{
7576
namespace fs = llvm::sys::fs;
7677
namespace path = llvm::sys::path;
7778

79+
// copy the base settings if present
80+
if(base)
81+
settings_ = base->settings_;
82+
7883
if(! files::isAbsolute(workingDir_))
7984
formatError("working path \"{}\" is not absolute", workingDir_).Throw();
8085
settings_.workingDir = files::makeDirsy(files::normalizePath(workingDir_));
@@ -187,7 +192,7 @@ createConfigFromYAML(
187192
try
188193
{
189194
auto config = std::make_shared<ConfigImpl>(
190-
workingDir, addonsDir, configYaml, extraYaml);
195+
workingDir, addonsDir, configYaml, extraYaml, nullptr);
191196
return config;
192197
}
193198
catch(Exception const& ex)
@@ -200,7 +205,8 @@ Expected<std::shared_ptr<ConfigImpl const>>
200205
loadConfigFile(
201206
std::string_view configFilePath,
202207
std::string_view addonsDir,
203-
std::string_view extraYaml)
208+
std::string_view extraYaml,
209+
std::shared_ptr<ConfigImpl const> base)
204210
{
205211
namespace fs = llvm::sys::fs;
206212
namespace path = llvm::sys::path;
@@ -222,7 +228,7 @@ loadConfigFile(
222228
try
223229
{
224230
auto config = std::make_shared<ConfigImpl>(
225-
workingDir, addonsDir, *text, extraYaml);
231+
workingDir, addonsDir, *text, extraYaml, base.get());
226232
return config;
227233
}
228234
catch(Exception const& ex)

lib/Tool/ConfigImpl.hpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class ConfigImpl
4747
FileFilter input;
4848
};
4949

50-
Settings const& settings() const noexcept
50+
Settings const&
51+
settings()const noexcept override
5152
{
5253
return settings_;
5354
}
@@ -78,7 +79,8 @@ class ConfigImpl
7879
llvm::StringRef workingDir,
7980
llvm::StringRef addonsDir,
8081
llvm::StringRef configYaml,
81-
llvm::StringRef extraYaml);
82+
llvm::StringRef extraYaml,
83+
ConfigImpl const* base);
8284

8385
ThreadPool&
8486
threadPool() const noexcept override
@@ -219,13 +221,18 @@ createConfigFromYAML(
219221
@param extraYaml An optional string containing
220222
additional valid YAML which will be parsed and
221223
applied to the existing configuration.
224+
225+
@param baseConfig An optional configuration
226+
object. If specified, its settings will be
227+
first copied before the file is loaded.
222228
*/
223229
MRDOX_DECL
224230
Expected<std::shared_ptr<ConfigImpl const>>
225231
loadConfigFile(
226232
std::string_view configFilePath,
227233
std::string_view addonsDir,
228-
std::string_view extraYaml = "");
234+
std::string_view extraYaml = "",
235+
std::shared_ptr<ConfigImpl const> base = nullptr);
229236

230237
/** Create a configuration by loading a YAML string.
231238

0 commit comments

Comments
 (0)