diff options
Diffstat (limited to 'libbuild2/script')
-rw-r--r-- | libbuild2/script/parser.hxx | 2 | ||||
-rw-r--r-- | libbuild2/script/run.cxx | 43 | ||||
-rw-r--r-- | libbuild2/script/script.hxx | 15 |
3 files changed, 35 insertions, 25 deletions
diff --git a/libbuild2/script/parser.hxx b/libbuild2/script/parser.hxx index d47f88e..a63ecde 100644 --- a/libbuild2/script/parser.hxx +++ b/libbuild2/script/parser.hxx @@ -40,6 +40,8 @@ namespace build2 token_type assign_kind, const path_name&); // For diagnostics. + using build2::parser::apply_value_attributes; + // Commonly used parsing functions. Issue diagnostics and throw failed // in case of an error. // diff --git a/libbuild2/script/run.cxx b/libbuild2/script/run.cxx index a48421c..64286fd 100644 --- a/libbuild2/script/run.cxx +++ b/libbuild2/script/run.cxx @@ -53,6 +53,18 @@ namespace build2 return r; } + // Return the environment temporary directory, creating it if it doesn't + // exist. + // + static inline const dir_path& + temp_dir (environment& env) + { + if (env.temp_dir.empty ()) + env.create_temp_dir (); + + return env.temp_dir; + } + // Normalize a path. Also make the relative path absolute using the // specified directory unless it is already absolute. // @@ -207,13 +219,16 @@ namespace build2 return r; } - // Return true if a path is not under the script temporary directory or - // this directory will not be removed on failure. + // Return true if the script temporary directory is not created yet (and + // so cannot contain any path), a path is not under the temporary + // directory or this directory will not be removed on failure. // static inline bool avail_on_failure (const path& p, const environment& env) { - return env.temp_dir_keep || !p.sub (env.temp_dir); + return env.temp_dir.empty () || + env.temp_dir_keep || + !p.sub (env.temp_dir); } // Check if the script command output matches the expected result @@ -849,26 +864,10 @@ namespace build2 cin.close (); - // If there is an error in the attributes string, our diagnostics - // will look like this: - // - // <attributes>:1:1 error: unknown value attribute x - // script:10:1 info: while parsing attributes '[x]' - // - // Note that the attributes parsing error is the only reason for a - // failure. - // - auto df = make_diag_frame ( - [ats, &ll](const diag_record& dr) - { - assert (ats != nullptr); - - dr << info (ll) << "while parsing attributes '" << *ats << "'"; - }); - env.set_variable (move (vname), move (ns), - ats != nullptr ? *ats : empty_string); + ats != nullptr ? *ats : empty_string, + ll); } catch (const io_error& e) { @@ -1042,7 +1041,7 @@ namespace build2 if (ci > 0) p += "-" + to_string (ci); - return normalize (move (p), env.temp_dir, ll); + return normalize (move (p), temp_dir (env), ll); }; // If this is the first pipeline command, then open stdin descriptor diff --git a/libbuild2/script/script.hxx b/libbuild2/script/script.hxx index b887df6..b80c44a 100644 --- a/libbuild2/script/script.hxx +++ b/libbuild2/script/script.hxx @@ -373,7 +373,9 @@ namespace build2 const dir_name_view sandbox_dir; // Used by the script running machinery to create special files in it. - // Must be an absolute path. + // Must be an absolute path, unless empty. Can be empty until the + // create_temp_dir() function call, which can be used for the create-on- + // demand strategy implementation. // const dir_path& temp_dir; @@ -454,10 +456,17 @@ namespace build2 public: // Set variable value with optional (non-empty) attributes. // - // Note: see also parser::lookup_variable(). + virtual void + set_variable (string&& name, + names&&, + const string& attrs, + const location&) = 0; + + // Create the temporary directory and set the temp_dir reference target + // to its path. Must only be called if temp_dir is empty. // virtual void - set_variable (string&& name, names&&, const string& attrs) = 0; + create_temp_dir () = 0; public: virtual |