Skip to content

Commit 072e577

Browse files
committed
engine: Add interpolation for ${THIS_STACKFILE_DIR} and -FILE
1 parent 154828f commit 072e577

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

engine/src/main_stack.cpp

+19-9
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include <cloe/utility/std_extensions.hpp> // for split_string
3333
#include <cloe/utility/xdg.hpp> // for merge_config
34+
#include <fable/environment.hpp> // for Environment
3435
#include <fable/utility.hpp> // for pretty_print, read_conf_from_file
3536

3637
#include "plugins/nop_controller.hpp" // for NopFactory
@@ -41,14 +42,24 @@
4142

4243
namespace cloe {
4344

45+
Conf read_conf(const StackOptions& opt, const std::string& filepath) {
46+
if (!opt.interpolate_vars) {
47+
return fable::read_conf(filepath);
48+
}
49+
50+
// Prepare environment with extra variables:
51+
fable::Environment env(*opt.environment);
52+
if (!filepath.empty() && filepath != "-") {
53+
std::string dirpath = boost::filesystem::canonical(filepath).parent_path().native();
54+
env.set("THIS_STACKFILE_FILE", filepath);
55+
env.set("THIS_STACKFILE_DIR", dirpath);
56+
}
57+
return fable::read_conf_with_interpolation(filepath, &env);
58+
}
59+
4460
void merge_stack(const StackOptions& opt, Stack& s, const std::string& filepath) {
4561
auto merge = [&]() {
46-
Conf c;
47-
if (opt.interpolate_vars) {
48-
c = fable::read_conf_with_interpolation(filepath, opt.environment.get());
49-
} else {
50-
c = fable::read_conf(filepath);
51-
}
62+
Conf c = read_conf(opt, filepath);
5263

5364
if (opt.no_hooks) {
5465
// Removing hooks from the config allows the stack to validate even if
@@ -95,9 +106,8 @@ Stack new_stack(const StackOptions& opt) {
95106
};
96107
interpolate_path(s.engine.registry_path);
97108
interpolate_path(s.engine.output_path);
98-
s.set_conf_reader([&opt](const std::string& filepath) -> cloe::Conf {
99-
return fable::read_conf_with_interpolation(filepath, opt.environment.get());
100-
});
109+
s.set_conf_reader(
110+
[&opt](const std::string& filepath) -> cloe::Conf { return read_conf(opt, filepath); });
101111
}
102112

103113
// Insert ignored sections

engine/src/stack.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
namespace fs = boost::filesystem;
3535

3636
#include <cloe/utility/std_extensions.hpp> // for join_vector
37-
#include <fable/utility.hpp> // for read_conf_with_interpolation
3837

3938
namespace cloe {
4039

0 commit comments

Comments
 (0)