diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2016-04-05 07:26:09 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2016-04-05 07:26:09 +0200 |
commit | 46a95c974de475070d0eedb07212e5c5282b66bd (patch) | |
tree | 687d232cb775f0840c50a9c64bf96d3a16e6f4f3 | |
parent | 5c369faa461ec4416d2d4b231a5b36963a7315ce (diff) |
Implement --buildfile option, overrides default buildfile, supports '-'
-rw-r--r-- | build2/b-options | 8 | ||||
-rw-r--r-- | build2/b-options.cxx | 15 | ||||
-rw-r--r-- | build2/b-options.ixx | 12 | ||||
-rw-r--r-- | build2/b.cli | 11 | ||||
-rw-r--r-- | build2/b.cxx | 5 | ||||
-rw-r--r-- | build2/context.cxx | 3 | ||||
-rw-r--r-- | build2/file | 6 | ||||
-rw-r--r-- | build2/file.cxx | 19 |
8 files changed, 70 insertions, 9 deletions
diff --git a/build2/b-options b/build2/b-options index 602ea64..b592ece 100644 --- a/build2/b-options +++ b/build2/b-options @@ -408,6 +408,12 @@ namespace build2 verbose_specified () const; const path& + buildfile () const; + + bool + buildfile_specified () const; + + const path& config_guess () const; bool @@ -460,6 +466,8 @@ namespace build2 bool q_; uint16_t verbose_; bool verbose_specified_; + path buildfile_; + bool buildfile_specified_; path config_guess_; bool config_guess_specified_; path config_sub_; diff --git a/build2/b-options.cxx b/build2/b-options.cxx index bbdbde9..cf15200 100644 --- a/build2/b-options.cxx +++ b/build2/b-options.cxx @@ -573,6 +573,8 @@ namespace build2 q_ (), verbose_ (1), verbose_specified_ (false), + buildfile_ ("buildfile"), + buildfile_specified_ (false), config_guess_ (), config_guess_specified_ (false), config_sub_ (), @@ -677,6 +679,16 @@ namespace build2 << " 6. Even more detailed information, including state dumps." << ::std::endl; os << std::endl + << "\033[1m--buildfile\033[0m \033[4mpath\033[0m The alternative file to read build information from. The" << ::std::endl + << " default is \033[1mbuildfile\033[0m. If \033[4mpath\033[0m is '\033[1m-\033[0m', then read from" << ::std::endl + << " \033[1mSTDIN\033[0m. Note that this option only affects the files read" << ::std::endl + << " as part of the buildspec processing. Specifically, it has" << ::std::endl + << " no effect on the \033[1msource\033[0m and \033[1minclude\033[0m directives. As a" << ::std::endl + << " result, this option is primarily intended for testing" << ::std::endl + << " rather than changing the build file names in real" << ::std::endl + << " projects." << ::std::endl; + + os << std::endl << "\033[1m--config-guess\033[0m \033[4mpath\033[0m The path to the \033[1mconfig.guess(1)\033[0m script that should be used" << ::std::endl << " to guess the host machine triplet. If this option is not" << ::std::endl << " specified, then \033[1mb\033[0m will fall back on to using the target it" << ::std::endl @@ -732,6 +744,9 @@ namespace build2 _cli_options_map_["--verbose"] = &::build2::cl::thunk< options, uint16_t, &options::verbose_, &options::verbose_specified_ >; + _cli_options_map_["--buildfile"] = + &::build2::cl::thunk< options, path, &options::buildfile_, + &options::buildfile_specified_ >; _cli_options_map_["--config-guess"] = &::build2::cl::thunk< options, path, &options::config_guess_, &options::config_guess_specified_ >; diff --git a/build2/b-options.ixx b/build2/b-options.ixx index ed538c9..15329dc 100644 --- a/build2/b-options.ixx +++ b/build2/b-options.ixx @@ -241,6 +241,18 @@ namespace build2 } inline const path& options:: + buildfile () const + { + return this->buildfile_; + } + + inline bool options:: + buildfile_specified () const + { + return this->buildfile_specified_; + } + + inline const path& options:: config_guess () const { return this->config_guess_; diff --git a/build2/b.cli b/build2/b.cli index 9144acf..013a756 100644 --- a/build2/b.cli +++ b/build2/b.cli @@ -220,6 +220,17 @@ namespace build2 \li|Even more detailed information, including state dumps.||" } + path --buildfile = "buildfile" + { + "<path>", + "The alternative file to read build information from. The default is + \cb{buildfile}. If <path> is '\cb{-}', then read from \cb{STDIN}. Note + that this option only affects the files read as part of the buildspec + processing. Specifically, it has no effect on the \cb{source} and + \cb{include} directives. As a result, this option is primarily intended + for testing rather than changing the build file names in real projects." + } + path --config-guess { "<path>", diff --git a/build2/b.cxx b/build2/b.cxx index f9c3683..313fe95 100644 --- a/build2/b.cxx +++ b/build2/b.cxx @@ -786,12 +786,13 @@ main (int argc, char* argv[]) trace << " src_root: " << src_root; } - path bf (src_base / path ("buildfile")); + const path& bfn (ops.buildfile ()); + path bf (bfn.string () != "-" ? src_base / bfn : bfn); // If we were guessing src_base, check that the buildfile // exists and if not, issue more detailed diagnostics. // - if (guessing && !file_exists (bf)) + if (guessing && bf.string () != "-" && !file_exists (bf)) fail << bf << " does not exist" << info << "consider explicitly specifying src_base " << "for " << tn; diff --git a/build2/context.cxx b/build2/context.cxx index 941f98a..6317476 100644 --- a/build2/context.cxx +++ b/build2/context.cxx @@ -406,6 +406,9 @@ namespace build2 string diag_relative (const path& p) { + if (p.string () == "-") + return "<stdin>"; + const path& b (*relative_base); if (p.absolute ()) diff --git a/build2/file b/build2/file index b198557..00ece85 100644 --- a/build2/file +++ b/build2/file @@ -49,11 +49,13 @@ namespace build2 dir_path find_out_root (const dir_path&, bool* src = nullptr); + // If buildfile is '-', then read from STDIN. + // void source (const path& buildfile, scope& root, scope& base); - // As above but first check if this buildfile has already been - // sourced for the base scope. + // As above but first check if this buildfile has already been sourced for + // the base scope. // void source_once (const path& buildfile, scope& root, scope& base); diff --git a/build2/file.cxx b/build2/file.cxx index 10461c4..b735cab 100644 --- a/build2/file.cxx +++ b/build2/file.cxx @@ -5,6 +5,7 @@ #include <build2/file> #include <fstream> +#include <iostream> // cin #include <butl/filesystem> @@ -80,16 +81,24 @@ namespace build2 try { - ifstream ifs (bf.string ()); - if (!ifs.is_open ()) - fail << "unable to open " << bf; + bool sin (bf.string () == "-"); - ifs.exceptions (ifstream::failbit | ifstream::badbit); + ifstream ifs; + if (!sin) + { + ifs.open (bf.string ()); + + if (!ifs.is_open ()) + fail << "unable to open " << bf; + } + + istream& is (sin ? std::cin : ifs); + is.exceptions (ifstream::failbit | ifstream::badbit); l5 ([&]{trace << "sourcing " << bf;}); parser p (boot); - p.parse_buildfile (ifs, bf, root, base); + p.parse_buildfile (is, bf, root, base); } catch (const ifstream::failure&) { |