aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/build/script
diff options
context:
space:
mode:
Diffstat (limited to 'libbuild2/build/script')
-rw-r--r--libbuild2/build/script/builtin-options.cxx83
-rw-r--r--libbuild2/build/script/builtin-options.hxx35
-rw-r--r--libbuild2/build/script/builtin-options.ixx102
-rw-r--r--libbuild2/build/script/builtin.cli30
-rw-r--r--libbuild2/build/script/parser.cxx214
-rw-r--r--libbuild2/build/script/parser.hxx60
-rw-r--r--libbuild2/build/script/script.hxx3
7 files changed, 368 insertions, 159 deletions
diff --git a/libbuild2/build/script/builtin-options.cxx b/libbuild2/build/script/builtin-options.cxx
index cf99b12..f66fe47 100644
--- a/libbuild2/build/script/builtin-options.cxx
+++ b/libbuild2/build/script/builtin-options.cxx
@@ -397,11 +397,11 @@ namespace build2
{
namespace script
{
- // depdb_dep_options
+ // depdb_dyndep_options
//
- depdb_dep_options::
- depdb_dep_options ()
+ depdb_dyndep_options::
+ depdb_dyndep_options ()
: file_ (),
file_specified_ (false),
format_ (),
@@ -410,12 +410,14 @@ namespace build2
what_specified_ (false),
include_path_ (),
include_path_specified_ (false),
- default_prereq_type_ (),
- default_prereq_type_specified_ (false)
+ default_type_ (),
+ default_type_specified_ (false),
+ cwd_ (),
+ cwd_specified_ (false)
{
}
- bool depdb_dep_options::
+ bool depdb_dyndep_options::
parse (int& argc,
char** argv,
bool erase,
@@ -427,7 +429,7 @@ namespace build2
return r;
}
- bool depdb_dep_options::
+ bool depdb_dyndep_options::
parse (int start,
int& argc,
char** argv,
@@ -440,7 +442,7 @@ namespace build2
return r;
}
- bool depdb_dep_options::
+ bool depdb_dyndep_options::
parse (int& argc,
char** argv,
int& end,
@@ -454,7 +456,7 @@ namespace build2
return r;
}
- bool depdb_dep_options::
+ bool depdb_dyndep_options::
parse (int start,
int& argc,
char** argv,
@@ -469,7 +471,7 @@ namespace build2
return r;
}
- bool depdb_dep_options::
+ bool depdb_dyndep_options::
parse (::build2::build::script::cli::scanner& s,
::build2::build::script::cli::unknown_mode opt,
::build2::build::script::cli::unknown_mode arg)
@@ -479,44 +481,47 @@ namespace build2
}
typedef
- std::map<std::string, void (*) (depdb_dep_options&, ::build2::build::script::cli::scanner&)>
- _cli_depdb_dep_options_map;
+ std::map<std::string, void (*) (depdb_dyndep_options&, ::build2::build::script::cli::scanner&)>
+ _cli_depdb_dyndep_options_map;
- static _cli_depdb_dep_options_map _cli_depdb_dep_options_map_;
+ static _cli_depdb_dyndep_options_map _cli_depdb_dyndep_options_map_;
- struct _cli_depdb_dep_options_map_init
+ struct _cli_depdb_dyndep_options_map_init
{
- _cli_depdb_dep_options_map_init ()
- {
- _cli_depdb_dep_options_map_["--file"] =
- &::build2::build::script::cli::thunk< depdb_dep_options, path, &depdb_dep_options::file_,
- &depdb_dep_options::file_specified_ >;
- _cli_depdb_dep_options_map_["--format"] =
- &::build2::build::script::cli::thunk< depdb_dep_options, string, &depdb_dep_options::format_,
- &depdb_dep_options::format_specified_ >;
- _cli_depdb_dep_options_map_["--what"] =
- &::build2::build::script::cli::thunk< depdb_dep_options, string, &depdb_dep_options::what_,
- &depdb_dep_options::what_specified_ >;
- _cli_depdb_dep_options_map_["--include-path"] =
- &::build2::build::script::cli::thunk< depdb_dep_options, dir_paths, &depdb_dep_options::include_path_,
- &depdb_dep_options::include_path_specified_ >;
- _cli_depdb_dep_options_map_["-I"] =
- &::build2::build::script::cli::thunk< depdb_dep_options, dir_paths, &depdb_dep_options::include_path_,
- &depdb_dep_options::include_path_specified_ >;
- _cli_depdb_dep_options_map_["--default-prereq-type"] =
- &::build2::build::script::cli::thunk< depdb_dep_options, string, &depdb_dep_options::default_prereq_type_,
- &depdb_dep_options::default_prereq_type_specified_ >;
+ _cli_depdb_dyndep_options_map_init ()
+ {
+ _cli_depdb_dyndep_options_map_["--file"] =
+ &::build2::build::script::cli::thunk< depdb_dyndep_options, path, &depdb_dyndep_options::file_,
+ &depdb_dyndep_options::file_specified_ >;
+ _cli_depdb_dyndep_options_map_["--format"] =
+ &::build2::build::script::cli::thunk< depdb_dyndep_options, string, &depdb_dyndep_options::format_,
+ &depdb_dyndep_options::format_specified_ >;
+ _cli_depdb_dyndep_options_map_["--what"] =
+ &::build2::build::script::cli::thunk< depdb_dyndep_options, string, &depdb_dyndep_options::what_,
+ &depdb_dyndep_options::what_specified_ >;
+ _cli_depdb_dyndep_options_map_["--include-path"] =
+ &::build2::build::script::cli::thunk< depdb_dyndep_options, dir_paths, &depdb_dyndep_options::include_path_,
+ &depdb_dyndep_options::include_path_specified_ >;
+ _cli_depdb_dyndep_options_map_["-I"] =
+ &::build2::build::script::cli::thunk< depdb_dyndep_options, dir_paths, &depdb_dyndep_options::include_path_,
+ &depdb_dyndep_options::include_path_specified_ >;
+ _cli_depdb_dyndep_options_map_["--default-type"] =
+ &::build2::build::script::cli::thunk< depdb_dyndep_options, string, &depdb_dyndep_options::default_type_,
+ &depdb_dyndep_options::default_type_specified_ >;
+ _cli_depdb_dyndep_options_map_["--cwd"] =
+ &::build2::build::script::cli::thunk< depdb_dyndep_options, dir_path, &depdb_dyndep_options::cwd_,
+ &depdb_dyndep_options::cwd_specified_ >;
}
};
- static _cli_depdb_dep_options_map_init _cli_depdb_dep_options_map_init_;
+ static _cli_depdb_dyndep_options_map_init _cli_depdb_dyndep_options_map_init_;
- bool depdb_dep_options::
+ bool depdb_dyndep_options::
_parse (const char* o, ::build2::build::script::cli::scanner& s)
{
- _cli_depdb_dep_options_map::const_iterator i (_cli_depdb_dep_options_map_.find (o));
+ _cli_depdb_dyndep_options_map::const_iterator i (_cli_depdb_dyndep_options_map_.find (o));
- if (i != _cli_depdb_dep_options_map_.end ())
+ if (i != _cli_depdb_dyndep_options_map_.end ())
{
(*(i->second)) (*this, s);
return true;
@@ -525,7 +530,7 @@ namespace build2
return false;
}
- bool depdb_dep_options::
+ bool depdb_dyndep_options::
_parse (::build2::build::script::cli::scanner& s,
::build2::build::script::cli::unknown_mode opt_mode,
::build2::build::script::cli::unknown_mode arg_mode)
diff --git a/libbuild2/build/script/builtin-options.hxx b/libbuild2/build/script/builtin-options.hxx
index 85d67b9..15119f4 100644
--- a/libbuild2/build/script/builtin-options.hxx
+++ b/libbuild2/build/script/builtin-options.hxx
@@ -297,10 +297,10 @@ namespace build2
{
namespace script
{
- class depdb_dep_options
+ class depdb_dyndep_options
{
public:
- depdb_dep_options ();
+ depdb_dyndep_options ();
// Return true if anything has been parsed.
//
@@ -404,19 +404,34 @@ namespace build2
include_path_specified (bool);
const string&
- default_prereq_type () const;
+ default_type () const;
string&
- default_prereq_type ();
+ default_type ();
void
- default_prereq_type (const string&);
+ default_type (const string&);
bool
- default_prereq_type_specified () const;
+ default_type_specified () const;
void
- default_prereq_type_specified (bool);
+ default_type_specified (bool);
+
+ const dir_path&
+ cwd () const;
+
+ dir_path&
+ cwd ();
+
+ void
+ cwd (const dir_path&);
+
+ bool
+ cwd_specified () const;
+
+ void
+ cwd_specified (bool);
// Implementation details.
//
@@ -439,8 +454,10 @@ namespace build2
bool what_specified_;
dir_paths include_path_;
bool include_path_specified_;
- string default_prereq_type_;
- bool default_prereq_type_specified_;
+ string default_type_;
+ bool default_type_specified_;
+ dir_path cwd_;
+ bool cwd_specified_;
};
}
}
diff --git a/libbuild2/build/script/builtin-options.ixx b/libbuild2/build/script/builtin-options.ixx
index 06575c8..c6266d0 100644
--- a/libbuild2/build/script/builtin-options.ixx
+++ b/libbuild2/build/script/builtin-options.ixx
@@ -176,157 +176,187 @@ namespace build2
{
namespace script
{
- // depdb_dep_options
+ // depdb_dyndep_options
//
- inline const path& depdb_dep_options::
+ inline const path& depdb_dyndep_options::
file () const
{
return this->file_;
}
- inline path& depdb_dep_options::
+ inline path& depdb_dyndep_options::
file ()
{
return this->file_;
}
- inline void depdb_dep_options::
+ inline void depdb_dyndep_options::
file (const path& x)
{
this->file_ = x;
}
- inline bool depdb_dep_options::
+ inline bool depdb_dyndep_options::
file_specified () const
{
return this->file_specified_;
}
- inline void depdb_dep_options::
+ inline void depdb_dyndep_options::
file_specified (bool x)
{
this->file_specified_ = x;
}
- inline const string& depdb_dep_options::
+ inline const string& depdb_dyndep_options::
format () const
{
return this->format_;
}
- inline string& depdb_dep_options::
+ inline string& depdb_dyndep_options::
format ()
{
return this->format_;
}
- inline void depdb_dep_options::
+ inline void depdb_dyndep_options::
format (const string& x)
{
this->format_ = x;
}
- inline bool depdb_dep_options::
+ inline bool depdb_dyndep_options::
format_specified () const
{
return this->format_specified_;
}
- inline void depdb_dep_options::
+ inline void depdb_dyndep_options::
format_specified (bool x)
{
this->format_specified_ = x;
}
- inline const string& depdb_dep_options::
+ inline const string& depdb_dyndep_options::
what () const
{
return this->what_;
}
- inline string& depdb_dep_options::
+ inline string& depdb_dyndep_options::
what ()
{
return this->what_;
}
- inline void depdb_dep_options::
+ inline void depdb_dyndep_options::
what (const string& x)
{
this->what_ = x;
}
- inline bool depdb_dep_options::
+ inline bool depdb_dyndep_options::
what_specified () const
{
return this->what_specified_;
}
- inline void depdb_dep_options::
+ inline void depdb_dyndep_options::
what_specified (bool x)
{
this->what_specified_ = x;
}
- inline const dir_paths& depdb_dep_options::
+ inline const dir_paths& depdb_dyndep_options::
include_path () const
{
return this->include_path_;
}
- inline dir_paths& depdb_dep_options::
+ inline dir_paths& depdb_dyndep_options::
include_path ()
{
return this->include_path_;
}
- inline void depdb_dep_options::
+ inline void depdb_dyndep_options::
include_path (const dir_paths& x)
{
this->include_path_ = x;
}
- inline bool depdb_dep_options::
+ inline bool depdb_dyndep_options::
include_path_specified () const
{
return this->include_path_specified_;
}
- inline void depdb_dep_options::
+ inline void depdb_dyndep_options::
include_path_specified (bool x)
{
this->include_path_specified_ = x;
}
- inline const string& depdb_dep_options::
- default_prereq_type () const
+ inline const string& depdb_dyndep_options::
+ default_type () const
{
- return this->default_prereq_type_;
+ return this->default_type_;
}
- inline string& depdb_dep_options::
- default_prereq_type ()
+ inline string& depdb_dyndep_options::
+ default_type ()
{
- return this->default_prereq_type_;
+ return this->default_type_;
}
- inline void depdb_dep_options::
- default_prereq_type (const string& x)
+ inline void depdb_dyndep_options::
+ default_type (const string& x)
{
- this->default_prereq_type_ = x;
+ this->default_type_ = x;
}
- inline bool depdb_dep_options::
- default_prereq_type_specified () const
+ inline bool depdb_dyndep_options::
+ default_type_specified () const
{
- return this->default_prereq_type_specified_;
+ return this->default_type_specified_;
}
- inline void depdb_dep_options::
- default_prereq_type_specified (bool x)
+ inline void depdb_dyndep_options::
+ default_type_specified (bool x)
{
- this->default_prereq_type_specified_ = x;
+ this->default_type_specified_ = x;
+ }
+
+ inline const dir_path& depdb_dyndep_options::
+ cwd () const
+ {
+ return this->cwd_;
+ }
+
+ inline dir_path& depdb_dyndep_options::
+ cwd ()
+ {
+ return this->cwd_;
+ }
+
+ inline void depdb_dyndep_options::
+ cwd (const dir_path& x)
+ {
+ this->cwd_ = x;
+ }
+
+ inline bool depdb_dyndep_options::
+ cwd_specified () const
+ {
+ return this->cwd_specified_;
+ }
+
+ inline void depdb_dyndep_options::
+ cwd_specified (bool x)
+ {
+ this->cwd_specified_ = x;
}
}
}
diff --git a/libbuild2/build/script/builtin.cli b/libbuild2/build/script/builtin.cli
index 3ed3659..fafb330 100644
--- a/libbuild2/build/script/builtin.cli
+++ b/libbuild2/build/script/builtin.cli
@@ -15,17 +15,33 @@ namespace build2
{
// Pseudo-builtin options.
//
- class depdb_dep_options
+ class depdb_dyndep_options
{
// Note that --byproduct, if any, must be the first option and is
// handled ad hoc, kind of as a sub-command.
//
- path --file; // Read from file rather than stdin.
- string --format; // Dependency format: make (default).
- string --what; // Dependency kind, e.g., "header".
- dir_paths --include-path|-I; // Search paths for generated files.
- string --default-prereq-type; // Default prerequisite type to use
- // if none could be derived from ext.
+ // Note that in the future we may extend --cwd support to the non-
+ // byproduct mode where it will also have the `env --cwd` semantics
+ // (thus the matching name). Note that it will also be incompatible
+ // with support for generated files (and thus -I) at least in the make
+ // format where we use relative paths for non-existent files.
+ //
+ // Note on naming: whenever we (may) have two options, one for target
+ // and the other for prerequisite, we omit "prerequisite" as that's
+ // what we extract by default and most commonly. For example:
+ //
+ // --what --what-target
+ // --default-type --default-target-type
+ //
+ path --file; // Read from file rather than stdin.
+ string --format; // Dependency format: make (default).
+ string --what; // Dependency kind, e.g., "header".
+ dir_paths --include-path|-I; // Search paths for generated files.
+ string --default-type; // Default prerequisite type to use
+ // if none could be derived from ext.
+ dir_path --cwd; // Builtin's working directory used
+ // to complete relative paths (only
+ // in --byproduct mode).
};
}
}
diff --git a/libbuild2/build/script/parser.cxx b/libbuild2/build/script/parser.cxx
index 67dbf69..15545cf 100644
--- a/libbuild2/build/script/parser.cxx
+++ b/libbuild2/build/script/parser.cxx
@@ -135,7 +135,10 @@ namespace build2
//
s.depdb_clear = depdb_clear_.has_value ();
if (depdb_dyndep_)
+ {
s.depdb_dyndep = depdb_dyndep_->second;
+ s.depdb_dyndep_byproduct = depdb_dyndep_byproduct_;
+ }
s.depdb_preamble = move (depdb_preamble_);
return s;
@@ -548,7 +551,7 @@ namespace build2
}
else
{
- // Verify depdb-dyndep is last.
+ // Verify depdb-dyndep is last and detect the byproduct flavor.
//
if (v == "dyndep")
{
@@ -563,10 +566,8 @@ namespace build2
fail (l) << "multiple 'depdb dyndep' calls" <<
info (depdb_dyndep_->first) << "previous call is here";
-#if 0
if (peek () == type::word && peeked ().value == "--byproduct")
- ;
-#endif
+ depdb_dyndep_byproduct_ = true;
}
else
{
@@ -933,7 +934,8 @@ namespace build2
depdb& dd,
bool* update,
bool* deferred_failure,
- optional<timestamp> mt)
+ optional<timestamp> mt,
+ dyndep_byproduct* byp)
{
tracer trace ("exec_depdb_preamble");
@@ -961,8 +963,9 @@ namespace build2
bool* update;
bool* deferred_failure;
optional<timestamp> mt;
+ dyndep_byproduct* byp;
- } data {trace, a, bs, t, e, s, dd, update, deferred_failure, mt};
+ } data {trace, a, bs, t, e, s, dd, update, deferred_failure, mt, byp};
auto exec_cmd = [this, &data] (token& t,
build2::script::token_type& tt,
@@ -986,7 +989,8 @@ namespace build2
if (cmd == "dyndep")
{
- // Note: cast is safe since this is always executed in apply().
+ // Note: the cast is safe since the part where the target is
+ // modified is always executed in apply().
//
exec_depdb_dyndep (t, tt,
li, ll,
@@ -994,7 +998,8 @@ namespace build2
data.dd,
*data.update,
*data.deferred_failure,
- *data.mt);
+ *data.mt,
+ data.byp);
}
else
{
@@ -1207,7 +1212,8 @@ namespace build2
depdb& dd,
bool& update,
bool& deferred_failure,
- timestamp mt)
+ timestamp mt,
+ dyndep_byproduct* byprod_result)
{
tracer trace ("exec_depdb_dyndep");
@@ -1215,13 +1221,22 @@ namespace build2
// Similar approach to parse_env_builtin().
//
- depdb_dep_options ops;
+ depdb_dyndep_options ops;
bool prog (false);
+ bool byprod (false);
{
auto& t (lt);
auto& tt (ltt);
- next (t, tt); // Skip 'dep' command.
+ next (t, tt); // Skip the 'dyndep' command.
+
+ if (tt == type::word && t.value == "--byproduct")
+ {
+ byprod = true;
+ next (t, tt);
+ }
+
+ assert (byprod == (byprod_result != nullptr));
// Note that an option name and value can belong to different name
// chunks. That's why we parse the arguments in the chunking mode
@@ -1273,6 +1288,10 @@ namespace build2
if (prog)
{
+ if (byprod)
+ fail (t) << "depdb dyndep: --byproduct cannot be used with "
+ << "program";
+
next (t, tt); // Skip '--'.
if (tt == type::newline || tt == type::eos)
@@ -1311,12 +1330,10 @@ namespace build2
continue;
}
-#if 0
// Handle --byproduct in the wrong place.
//
if (strcmp (a, "--byproduct") == 0)
fail (ll) << "depdb dyndep: --byproduct must be first option";
-#endif
// Handle unknown option.
//
@@ -1334,6 +1351,64 @@ namespace build2
}
}
+ // --what
+ //
+ const char* what (ops.what_specified ()
+ ? ops.what ().c_str ()
+ : "file");
+
+ // --format
+ //
+ dyndep_format format (dyndep_format::make);
+
+ if (ops.format_specified ())
+ {
+ const string& f (ops.format ());
+
+ if (f != "make")
+ fail (ll) << "depdb dyndep: invalid --format option value '"
+ << f << "'";
+ }
+
+ // --cwd
+ //
+ optional<dir_path> cwd;
+
+ if (ops.cwd_specified ())
+ {
+ if (!byprod)
+ fail (ll) << "depdb dyndep: --cwd only valid in --byproduct mode";
+
+ cwd = move (ops.cwd ());
+
+ if (cwd->relative ())
+ fail (ll) << "depdb dyndep: relative path specified with --cwd";
+ }
+
+ // --file
+ //
+ // Note that if --file is specified without a program, then we assume
+ // it is one of the static prerequisites.
+ //
+ optional<path> file;
+
+ if (ops.file_specified ())
+ {
+ file = move (ops.file ());
+
+ if (file->relative ())
+ {
+ if (!cwd)
+ fail (ll) << "depdb dyndep: relative path specified with --file";
+
+ *file = *cwd / *file;
+ }
+ }
+ else if (!prog)
+ fail (ll) << "depdb dyndep: program or --file expected";
+
+ // --default-type
+ //
// Get the default prerequisite type falling back to file{} if not
// specified.
//
@@ -1344,17 +1419,34 @@ namespace build2
// system headers to h{} targets analogous to the c module's rule.
//
const target_type* def_pt;
- if (ops.default_prereq_type_specified ())
+ if (ops.default_type_specified ())
{
- const string& t (ops.default_prereq_type ());
+ const string& t (ops.default_type ());
def_pt = bs.find_target_type (t);
if (def_pt == nullptr)
- fail (ll) << "unknown target type '" << t << "'";
+ fail (ll) << "unknown target type '" << t << "' specific with "
+ << "--default-type";
}
else
def_pt = &file::static_type;
+ if (byprod)
+ {
+ if (!ops.include_path ().empty ())
+ fail (ll) << "depdb dyndep: -I specified with --byproduct";
+
+ *byprod_result = dyndep_byproduct {
+ ll,
+ format,
+ move (cwd),
+ move (*file),
+ ops.what_specified () ? move (ops.what ()) : string (what),
+ def_pt};
+
+ return;
+ }
+
// This code is based on the prior work in the cc module (specifically
// extract_headers()) where you can often find more detailed rationale
// for some of the steps performed.
@@ -1369,6 +1461,8 @@ namespace build2
function<dyndep::map_extension_func> map_ext (
[] (const scope& bs, const string& n, const string& e)
{
+ // NOTE: another version in adhoc_buildscript_rule::apply().
+
// @@ TODO: allow specifying base target types.
//
// Feels like the only reason one would want to specify base types
@@ -1403,7 +1497,7 @@ namespace build2
{
tracer& trace;
const location& ll;
- const depdb_dep_options& ops;
+ const depdb_dyndep_options& ops;
optional<prefix_map> map;
} pfx_data {trace, ll, ops, nullopt};
@@ -1440,11 +1534,6 @@ namespace build2
};
}
- optional<path> file;
- enum class format {make} fmt (format::make);
- command_expr cmd;
- srcout_map so_map;
-
// Parse the remainder of the command line as a program (which can be
// a pipe). If file is absent, then we save the command's stdout to a
// pipe. Otherwise, assume the command writes to file and add it to
@@ -1454,31 +1543,13 @@ namespace build2
// could do other broken tools). However, the user can always merge
// stderr to stdout (2>&1).
//
+ command_expr cmd;
+ srcout_map so_map;
+
auto init_run = [this, &ctx,
&lt, &ltt, &ll,
- &ops, prog, &file, &cmd, &so_map] ()
+ prog, &file, &ops, &cmd, &so_map] ()
{
- // --format
- //
- if (ops.format_specified ())
- {
- const string& f (ops.format ());
-
- if (f != "make")
- fail (ll) << "depdb dyndep: invalid --format option value '"
- << f << "'";
- }
-
- // --file
- //
- if (ops.file_specified ())
- {
- file = move (ops.file ());
-
- if (file->relative ())
- fail (ll) << "depdb dyndep: relative path specified with --file";
- }
-
// Populate the srcout map with the -I$out_base -I$src_base pairs.
//
{
@@ -1515,25 +1586,20 @@ namespace build2
{build2::script::cleanup_type::always, *file},
true /* implicit */);
}
- else
- {
- // Assume file is one of the prerequisites.
- //
- if (!file)
- fail (ll) << "depdb dyndep: program or --file expected";
- }
};
// Enter as a target, update, and add to the list of prerequisite
// targets a file.
//
- const char* what (ops.what_specified ()
- ? ops.what ().c_str ()
- : "file");
-
+ // Note that these targets don't end up in $< (which is the right
+ // thing) because that variable has already been initialized (in the
+ // environment ctor).
+ //
size_t skip_count (0);
+ auto& pts (t.prerequisite_targets[a]);
+
auto add = [this, &trace, what,
- a, &bs, &t,
+ a, &bs, &t, &pts, pts_n = pts.size (),
&map_ext, def_pt, &pfx_map, &so_map,
&dd, &skip_count] (path fp,
bool cache,
@@ -1567,16 +1633,38 @@ namespace build2
if (const build2::file* ft = dyndep::enter_file (
trace, what,
a, bs, t,
- move (fp), cache, false /* normalize */,
+ fp, cache, cache /* normalized */,
map_ext, *def_pt, pfx_map, so_map).first)
{
+ // Skip if this is one of the static prerequisites.
+ //
+ for (size_t i (0); i != pts_n; ++i)
+ {
+ const prerequisite_target& p (pts[i]);
+
+ if (const target* pt =
+ (p.target != nullptr ? p.target :
+ p.data != 0 ? reinterpret_cast<target*> (p.data) :
+ nullptr))
+ {
+ if (pt == ft)
+ {
+ // Note that we have to increment the skip count since we
+ // skip before performing this test.
+ //
+ skip_count++;
+ return false;
+ }
+ }
+ }
+
if (optional<bool> u = dyndep::inject_file (
trace, what,
a, t,
*ft, mt, false /* fail */))
{
if (!cache)
- dd.expect (ft->path ());
+ dd.expect (ft->path ()); // @@ Use fp (or verify match)?
skip_count++;
return *u;
@@ -1721,14 +1809,16 @@ namespace build2
: path_name ("<stdin>"));
location il (in, 1);
+ size_t skip (skip_count);
// The way we parse things is format-specific.
//
- size_t skip (skip_count);
-
- switch (fmt)
+ // Note: similar code in
+ // adhoc_buildscript_rule::perform_update_file_dyndep_byproduct().
+ //
+ switch (format)
{
- case format::make:
+ case dyndep_format::make:
{
using make_state = make_parser;
using make_type = make_parser::type;
diff --git a/libbuild2/build/script/parser.hxx b/libbuild2/build/script/parser.hxx
index da15509..bbdb052 100644
--- a/libbuild2/build/script/parser.hxx
+++ b/libbuild2/build/script/parser.hxx
@@ -127,6 +127,46 @@ namespace build2
dd, &update, &deferred_failure, mt);
}
+ // This version doesn't actually execute the depdb-dyndep builtin (but
+ // may execute some variable assignments) instead returning all the
+ // information (extracted from options) necessary to implement the
+ // depdb-dyndep --byproduct logic (which fits better into the rule
+ // implementation).
+ //
+ enum class dyndep_format {make};
+
+ struct dyndep_byproduct
+ {
+ location_value location;
+ dyndep_format format;
+ optional<dir_path> cwd;
+ path file;
+ string what;
+ const target_type* default_type;
+ };
+
+ dyndep_byproduct
+ execute_depdb_preamble_dyndep_byproduct (
+ action a, const scope& base, const file& t,
+ environment& e, const script& s, runner& r,
+ depdb& dd)
+ {
+ // This is getting really ugly (we also don't really need to pass
+ // depdb here). One day we will find a better way...
+ //
+ bool update, deferred_failure; // Dymmy.
+ timestamp mt; // Dummy.
+
+ dyndep_byproduct v;
+ exec_depdb_preamble (
+ a, base, t,
+ e, s, r,
+ s.depdb_preamble.begin () + *s.depdb_dyndep,
+ s.depdb_preamble.end (),
+ dd, &update, &deferred_failure, mt, &v);
+ return v;
+ }
+
// Parse a special builtin line into names, performing the variable
// and pattern expansions. If omit_builtin is true, then omit the
// builtin name from the result.
@@ -166,7 +206,8 @@ namespace build2
depdb&,
bool* update = nullptr,
bool* deferred_failure = nullptr,
- optional<timestamp> mt = nullopt);
+ optional<timestamp> mt = nullopt,
+ dyndep_byproduct* = nullptr);
void
exec_depdb_dyndep (token&, build2::script::token_type&,
@@ -175,7 +216,8 @@ namespace build2
depdb&,
bool& update,
bool& deferred_failure,
- timestamp);
+ timestamp,
+ dyndep_byproduct*);
// Helpers.
//
@@ -274,13 +316,21 @@ namespace build2
// depdb env <var-names> - Track the environment variables change as a
// hash.
//
- // depdb dyndep ... - Extract dynamic dependency information.
- // Can only be the last depdb builtin call
- // in the preamble.
+ // depdb dyndep ... - Extract dynamic dependency information. Can
+ // only be the last depdb builtin call in the
+ // preamble. Note that such dependencies don't
+ // end up in $<. We also don't cause clean of
+ // such dependencies (since there may be no .d
+ // file) -- they should also be listed as
+ // static prerequisites of some other target
+ // (e.g., lib{} for headers) or a custom clean
+ // recipe should be provided.
+ //
//
optional<location> depdb_clear_; // depdb-clear location.
optional<pair<location, size_t>>
depdb_dyndep_; // depdb-dyndep location/position.
+ bool depdb_dyndep_byproduct_ = false; // --byproduct
lines depdb_preamble_; // Note: excluding depdb-clear.
// If present, the first impure function called in the body of the
diff --git a/libbuild2/build/script/script.hxx b/libbuild2/build/script/script.hxx
index 9d7567c..4e88785 100644
--- a/libbuild2/build/script/script.hxx
+++ b/libbuild2/build/script/script.hxx
@@ -75,7 +75,8 @@ namespace build2
// script parser for details).
//
bool depdb_clear;
- optional<size_t> depdb_dyndep; // Position of first depdb-dyndep.
+ optional<size_t> depdb_dyndep; // Pos of first dyndep.
+ bool depdb_dyndep_byproduct = false; // dyndep --byproduct
lines_type depdb_preamble;
bool depdb_preamble_temp_dir = false; // True if refs $~.