From: Rico Tzschichholz Date: Mon, 2 Dec 2019 16:04:06 +0000 (+0100) Subject: compiler: Add "--depfile" option writing package dependencies to given file X-Git-Tag: 0.47.2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e78d7713e80ce0b3044979e848b78229a1b6061;p=thirdparty%2Fvala.git compiler: Add "--depfile" option writing package dependencies to given file This is meant to be used by build systems before invoking rebuilds --- 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)); }