[vala/wip/depfile] compiler: Add "--depfile" option writing package dependencies to given file



commit 76a03d0158a4b18685f45f3bc16f0356dc554026
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Mon Dec 2 17:04:06 2019 +0100

    compiler: Add "--depfile" option writing package dependencies to given file
    
    This is meant to be used by build systems before invoking rebuilds

 compiler/valacompiler.vala |  6 ++++++
 doc/valac.1                |  3 +++
 vala/valacodecontext.vala  | 23 +++++++++++++++++++++++
 3 files changed, 32 insertions(+)
---
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));
        }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]