]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
compiler: Add "--depfile" option writing package dependencies to given file 4e78d7713e80ce0b3044979e848b78229a1b6061
authorRico Tzschichholz <ricotz@ubuntu.com>
Mon, 2 Dec 2019 16:04:06 +0000 (17:04 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 21 Dec 2019 20:23:28 +0000 (21:23 +0100)
This is meant to be used by build systems before invoking rebuilds

compiler/valacompiler.vala
doc/valac.1
vala/valacodecontext.vala

index 54c3535a5bd707107a2ebcde1c660fb305694fa4..174baded7086afe45d57d91b3f19ebc8c1d21f21 100644 (file)
@@ -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 ();
                }
index 4f9d1c5dd0da0560540d48f364eafc0d8c0ca1f0..7f46b178e10ddc6d27710242ab94129b22ccdc5d 100644 (file)
@@ -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
index 47c1cede4592b872e796a75bf8b74e1828327b12..9bce9f19d50745a2a41ba29d5b7e78400d132245 100644 (file)
@@ -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));
        }