diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2019-12-02 17:04:06 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2019-12-21 21:23:28 +0100 |
commit | 4e78d7713e80ce0b3044979e848b78229a1b6061 (patch) | |
tree | 4007f5cbb7f38eb99b61982a90381bbbdb217ec8 | |
parent | b977da4f72503c9688725a492515c8443b2d83ae (diff) | |
download | vala-4e78d7713e80ce0b3044979e848b78229a1b6061.tar.gz |
compiler: Add "--depfile" option writing package dependencies to given file
This is meant to be used by build systems before invoking rebuilds
-rw-r--r-- | compiler/valacompiler.vala | 6 | ||||
-rw-r--r-- | doc/valac.1 | 3 | ||||
-rw-r--r-- | vala/valacodecontext.vala | 23 |
3 files changed, 32 insertions, 0 deletions
diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala index 54c3535a5..174baded7 100644 --- a/compiler/valacompiler.vala +++ b/compiler/valacompiler.vala @@ -95,6 +95,7 @@ class Vala.Compiler { static bool disable_colored_output; static Report.Colored colored_output = Report.Colored.AUTO; static string dependencies; + static string depfile; static string entry_point; @@ -126,6 +127,7 @@ class Vala.Compiler { { "use-fast-vapi", 0, 0, OptionArg.STRING_ARRAY, ref fast_vapis, "Use --fast-vapi output during this compile", null }, { "vapi-comments", 0, 0, OptionArg.NONE, ref vapi_comments, "Include comments in generated vapi", null }, { "deps", 0, 0, OptionArg.STRING, ref dependencies, "Write make-style dependency information to this file", null }, + { "depfile", 0, 0, OptionArg.STRING, ref depfile, "Write make-style external dependency information for build systems to this file", null }, { "list-sources", 0, 0, OptionArg.NONE, ref list_sources, "Output a list of all source and binding files which are used", null }, { "symbols", 0, 0, OptionArg.FILENAME, ref symbols_filename, "Output symbols file", "FILE" }, { "compile", 'c', 0, OptionArg.NONE, ref compile_only, "Compile but do not link", null }, @@ -525,6 +527,10 @@ class Vala.Compiler { context.write_dependencies (dependencies); } + if (depfile != null) { + context.write_external_dependencies (depfile); + } + if (context.report.get_errors () > 0 || (fatal_warnings && context.report.get_warnings () > 0)) { return quit (); } diff --git a/doc/valac.1 b/doc/valac.1 index 4f9d1c5dd..7f46b178e 100644 --- a/doc/valac.1 +++ b/doc/valac.1 @@ -90,6 +90,9 @@ Include comments in generated vapi \fB\-\-deps\fR Write make\-style dependency information to this file .TP +\fB\-\-depfile\fR +Write make\-style external dependency information for build systems to this file +.TP \fB\-\-list\-sources\fR Output a list of all source and binding files which are used .TP diff --git a/vala/valacodecontext.vala b/vala/valacodecontext.vala index 47c1cede4..9bce9f19d 100644 --- a/vala/valacodecontext.vala +++ b/vala/valacodecontext.vala @@ -715,6 +715,29 @@ public class Vala.CodeContext { stream.printf ("\n\n"); } + public void write_external_dependencies (string filename) { + var stream = FileStream.open (filename, "w"); + + if (stream == null) { + Report.error (null, "unable to open `%s' for writing".printf (filename)); + return; + } + + bool first = true; + foreach (var src in source_files) { + if (src.file_type != SourceFileType.SOURCE && src.used) { + if (first) { + first = false; + stream.printf ("%s: ", filename); + } else { + stream.puts (" \\\n\t"); + } + stream.printf ("%s", src.filename); + } + } + stream.puts ("\n\n"); + } + private static bool ends_with_dir_separator (string s) { return Path.is_dir_separator (s.get_char (s.length - 1)); } |