summaryrefslogtreecommitdiff
path: root/xsd
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2023-09-11 11:59:27 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2023-09-11 11:59:27 +0200
commit9c7aaf839025e58b25d1bb37afb2c11d36985dcb (patch)
tree5555e9829b492f747a95cabd25a9bd71c7eef2af /xsd
parent7d26ea59564e573b9f8a1f025f7fd5df24ee2e80 (diff)
Add --dep-file option
In particular, this now allows writing the dependency information to stdout by specifying `-` as this option's value.
Diffstat (limited to 'xsd')
-rw-r--r--xsd/doc/pregenerated/xsd.111
-rw-r--r--xsd/doc/pregenerated/xsd.xhtml14
-rw-r--r--xsd/xsd/cxx/options.cli14
-rw-r--r--xsd/xsd/cxx/tree/generator.cxx47
-rw-r--r--xsd/xsd/pregenerated/xsd/cxx/options.cxx12
-rw-r--r--xsd/xsd/pregenerated/xsd/cxx/options.hxx8
-rw-r--r--xsd/xsd/pregenerated/xsd/cxx/options.ixx12
7 files changed, 91 insertions, 27 deletions
diff --git a/xsd/doc/pregenerated/xsd.1 b/xsd/doc/pregenerated/xsd.1
index 52820fb..b75232f 100644
--- a/xsd/doc/pregenerated/xsd.1
+++ b/xsd/doc/pregenerated/xsd.1
@@ -384,7 +384,8 @@ Generate \fBmake\fR dependency information\. This option triggers the creation
of the \fB\.d\fR file containing the dependencies of the generated files on
the main schema file as well as all the schema files that it includes/imports,
transitively\. This dependency file is then normally included into the main
-\fBmakefile\fR to implement automatic dependency tracking\.
+\fBmakefile\fR to implement automatic dependency tracking\. See also the
+\fB--dep-*\fR options\.
Note also that automatic dependency generation is not supported in the
file-per-type mode (\fB--file-per-type\fR)\. In this case, all the generated
@@ -405,8 +406,12 @@ directory prefixes\. If you require multiple targets, then you can specify
them as a single, space-separated argument or you can repeat this option
multiple times\.
.IP "\fB--dep-suffix\fR \fIsuffix\fR"
-Use the provided \fIsuffix\fR instead of the default \fB\.d\fR to construct
-the name of the dependency file\.
+Use \fIsuffix\fR instead of the default \fB\.d\fR to construct the name of the
+dependency file\. See also \fB--dep-file\fR\.
+.IP "\fB--dep-file\fR \fIpath\fR"
+Use \fIpath\fR as the generated dependency file path instead of deriving it
+from the input file name\. Write the dependency information to \fBstdout\fR if
+\fIpath\fR is \fB-\fR\. See also \fB--dep-regex\fR\.
.IP "\fB--dep-regex\fR \fIregex\fR"
Use the provided expression to construct the name of the dependency file\.
\fIregex\fR is a Perl-like regular expression in the form
diff --git a/xsd/doc/pregenerated/xsd.xhtml b/xsd/doc/pregenerated/xsd.xhtml
index 53b905c..15d9d5f 100644
--- a/xsd/doc/pregenerated/xsd.xhtml
+++ b/xsd/doc/pregenerated/xsd.xhtml
@@ -482,7 +482,8 @@
dependencies of the generated files on the main schema file as well as all
the schema files that it includes/imports, transitively. This dependency
file is then normally included into the main <code><b>makefile</b></code>
- to implement automatic dependency tracking.
+ to implement automatic dependency tracking. See also the
+ <code><b>--dep-*</b></code> options.
<p>Note also that automatic dependency generation is not supported in the
file-per-type mode (<code><b>--file-per-type</b></code>). In this case,
@@ -508,8 +509,15 @@
multiple times.</dd>
<dt><code><b>--dep-suffix</b></code> <code><i>suffix</i></code></dt>
- <dd>Use the provided <code><i>suffix</i></code> instead of the default
- <code><b>.d</b></code> to construct the name of the dependency file.</dd>
+ <dd>Use <code><i>suffix</i></code> instead of the default
+ <code><b>.d</b></code> to construct the name of the dependency file. See
+ also <code><b>--dep-file</b></code>.</dd>
+
+ <dt><code><b>--dep-file</b></code> <code><i>path</i></code></dt>
+ <dd>Use <code><i>path</i></code> as the generated dependency file path
+ instead of deriving it from the input file name. Write the dependency
+ information to <code><b>stdout</b></code> if <code><i>path</i></code> is
+ <code><b>-</b></code>. See also <code><b>--dep-regex</b></code>.</dd>
<dt><code><b>--dep-regex</b></code> <code><i>regex</i></code></dt>
<dd>Use the provided expression to construct the name of the dependency
diff --git a/xsd/xsd/cxx/options.cli b/xsd/xsd/cxx/options.cli
index 1eb1b61..1be7607 100644
--- a/xsd/xsd/cxx/options.cli
+++ b/xsd/xsd/cxx/options.cli
@@ -500,7 +500,7 @@ namespace CXX
generated files on the main schema file as well as all the schema
files that it includes/imports, transitively. This dependency file
is then normally included into the main \cb{makefile} to implement
- automatic dependency tracking.
+ automatic dependency tracking. See also the \cb{--dep-*} options.
Note also that automatic dependency generation is not supported in
the file-per-type mode (\cb{--file-per-type}). In this case, all
@@ -536,8 +536,16 @@ namespace CXX
NarrowString --dep-suffix = ".d"
{
"<suffix>",
- "Use the provided <suffix> instead of the default \cb{.d} to
- construct the name of the dependency file."
+ "Use <suffix> instead of the default \cb{.d} to construct the name of
+ the dependency file. See also \cb{--dep-file}."
+ };
+
+ NarrowString --dep-file
+ {
+ "<path>",
+ "Use <path> as the generated dependency file path instead of deriving
+ it from the input file name. Write the dependency information to
+ \cb{stdout} if <path> is \cb{-}. See also \cb{--dep-regex}."
};
NarrowString --dep-regex
diff --git a/xsd/xsd/cxx/tree/generator.cxx b/xsd/xsd/cxx/tree/generator.cxx
index d3e4db2..9782b4d 100644
--- a/xsd/xsd/cxx/tree/generator.cxx
+++ b/xsd/xsd/cxx/tree/generator.cxx
@@ -54,6 +54,8 @@ using namespace XSDFrontend::SemanticGraph;
//
//
+typedef std::wostream WideOutputStream;
+
typedef std::wifstream WideInputFileStream;
typedef std::wofstream WideOutputFileStream;
@@ -344,9 +346,13 @@ namespace CXX
? "#^(.+?)(\\.[^./\\\\]+)?$#$1" + fwd_suffix + "#"
: ops.fwd_regex ());
- Regex dep_expr (ops.dep_regex ().empty ()
- ? "#^(.+?)(\\.[^./\\\\]+)?$#$1" + dep_suffix + "#"
- : ops.dep_regex ());
+ // @@ This will blow up if --dep-file value contains backslashes (e.g.,
+ // it's a Windows path).
+ //
+ Regex dep_expr (
+ ops.dep_regex_specified () ? ops.dep_regex () :
+ ops.dep_file_specified () ? "#.+#" + ops.dep_file () + "#" :
+ "#^(.+?)(\\.[^./\\\\]+)?$#$1" + dep_suffix + "#");
if (header && !hxx_expr.match (name))
{
@@ -396,7 +402,7 @@ namespace CXX
Path hxx_path (hxx_name);
Path ixx_path (ixx_name);
Path fwd_path (fwd_name);
- Path dep_path (dep_name);
+ Path dep_path (dep_name != "-" ? dep_name : NarrowString ());
Paths cxx_paths;
if (source)
@@ -457,10 +463,11 @@ namespace CXX
if (!out_dir.empty ())
{
- hxx_path = out_dir / hxx_path;
- ixx_path = out_dir / ixx_path;
- fwd_path = out_dir / fwd_path;
- dep_path = out_dir / dep_path;
+ if (!hxx_path.empty ()) hxx_path = out_dir / hxx_path;
+ if (!ixx_path.empty ()) ixx_path = out_dir / ixx_path;
+ if (!fwd_path.empty ()) fwd_path = out_dir / fwd_path;
+ if (!dep_path.empty () &&
+ !dep_path.absolute ()) dep_path = out_dir / dep_path;
for (Paths::iterator i (cxx_paths.begin ());
i != cxx_paths.end (); ++i)
@@ -472,25 +479,32 @@ namespace CXX
WideOutputFileStream hxx;
WideOutputFileStream ixx;
WideOutputFileStream fwd;
- WideOutputFileStream dep;
+ WideOutputFileStream depf; // See dep below.
WideOutputFileStreams cxx;
// DEP
//
if (gen_dep)
{
- dep.open (dep_path.string ().c_str (), ios_base::out);
-
- if (!dep.is_open ())
+ if (!dep_path.empty ())
{
- wcerr << dep_path << ": error: unable to open in write mode" << endl;
- throw Failed ();
+ depf.open (dep_path.string ().c_str (), ios_base::out);
+
+ if (!depf.is_open ())
+ {
+ wcerr << dep_path << ": error: unable to open in write mode"
+ << endl;
+ throw Failed ();
+ }
+
+ unlinks.add (dep_path);
}
- unlinks.add (dep_path);
// Note: not adding to file_list.
}
+ WideOutputStream& dep (gen_dep && !dep_path.empty () ? depf : wcout);
+
// FWD
//
if (forward)
@@ -683,7 +697,8 @@ namespace CXX
i != cxx_paths.end (); ++i)
target += " \\\n" + i->string ();
- target += " \\\n" + dep_path.string ();
+ if (!dep_path.empty ())
+ target += " \\\n" + dep_path.string ();
}
dep << target.c_str () << ':';
diff --git a/xsd/xsd/pregenerated/xsd/cxx/options.cxx b/xsd/xsd/pregenerated/xsd/cxx/options.cxx
index 4d4fa23..9eea3a9 100644
--- a/xsd/xsd/pregenerated/xsd/cxx/options.cxx
+++ b/xsd/xsd/pregenerated/xsd/cxx/options.cxx
@@ -361,6 +361,8 @@ namespace CXX
dep_target_specified_ (false),
dep_suffix_ (".d"),
dep_suffix_specified_ (false),
+ dep_file_ (),
+ dep_file_specified_ (false),
dep_regex_ (),
dep_regex_specified_ (false)
{
@@ -527,8 +529,11 @@ namespace CXX
os << "--dep-target <target> Change the target of the dependency rule." << ::std::endl;
- os << "--dep-suffix <suffix> Use the provided <suffix> instead of the default" << ::std::endl
- << " .d to construct the name of the dependency file." << ::std::endl;
+ os << "--dep-suffix <suffix> Use <suffix> instead of the default .d to" << ::std::endl
+ << " construct the name of the dependency file." << ::std::endl;
+
+ os << "--dep-file <path> Use <path> as the generated dependency file path" << ::std::endl
+ << " instead of deriving it from the input file name." << ::std::endl;
os << "--dep-regex <regex> Use the provided expression to construct the name" << ::std::endl
<< " of the dependency file." << ::std::endl;
@@ -696,6 +701,9 @@ namespace CXX
_cli_options_map_["--dep-suffix"] =
&::cli::thunk< options, NarrowString, &options::dep_suffix_,
&options::dep_suffix_specified_ >;
+ _cli_options_map_["--dep-file"] =
+ &::cli::thunk< options, NarrowString, &options::dep_file_,
+ &options::dep_file_specified_ >;
_cli_options_map_["--dep-regex"] =
&::cli::thunk< options, NarrowString, &options::dep_regex_,
&options::dep_regex_specified_ >;
diff --git a/xsd/xsd/pregenerated/xsd/cxx/options.hxx b/xsd/xsd/pregenerated/xsd/cxx/options.hxx
index b01027a..085aa4c 100644
--- a/xsd/xsd/pregenerated/xsd/cxx/options.hxx
+++ b/xsd/xsd/pregenerated/xsd/cxx/options.hxx
@@ -313,6 +313,12 @@ namespace CXX
dep_suffix_specified () const;
const NarrowString&
+ dep_file () const;
+
+ bool
+ dep_file_specified () const;
+
+ const NarrowString&
dep_regex () const;
bool
@@ -428,6 +434,8 @@ namespace CXX
bool dep_target_specified_;
NarrowString dep_suffix_;
bool dep_suffix_specified_;
+ NarrowString dep_file_;
+ bool dep_file_specified_;
NarrowString dep_regex_;
bool dep_regex_specified_;
};
diff --git a/xsd/xsd/pregenerated/xsd/cxx/options.ixx b/xsd/xsd/pregenerated/xsd/cxx/options.ixx
index e8ba2fb..8266e31 100644
--- a/xsd/xsd/pregenerated/xsd/cxx/options.ixx
+++ b/xsd/xsd/pregenerated/xsd/cxx/options.ixx
@@ -585,6 +585,18 @@ namespace CXX
}
inline const NarrowString& options::
+ dep_file () const
+ {
+ return this->dep_file_;
+ }
+
+ inline bool options::
+ dep_file_specified () const
+ {
+ return this->dep_file_specified_;
+ }
+
+ inline const NarrowString& options::
dep_regex () const
{
return this->dep_regex_;