]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
valac: Output make-style dependency file
authorRyan Lortie <desrt@desrt.ca>
Wed, 25 Aug 2010 14:10:30 +0000 (16:10 +0200)
committerJürg Billeter <j@bitron.ch>
Fri, 17 Sep 2010 23:00:14 +0000 (01:00 +0200)
Add a --deps= option to the compiler to write out a make-style
dependency file.  The name of the target used is the name of the
dependency file itself.

This lets the dependency file serve as a stamp for the C file (which may
or may not be touched depending if it was changed).  The dependency
output is always touched.

compiler/valacompiler.vala
vala/valacodecontext.vala
vala/valasourcefile.vala
vala/valasymbol.vala
vala/valasymbolresolver.vala

index bedfb86fe8e1f211fff1aa9c87bea05ae8096057..39a71bfbdfed08a5b44e1d2ca683ccef5a988a01 100644 (file)
@@ -76,6 +76,7 @@ class Vala.Compiler {
        static bool enable_version_header;
        static bool disable_version_header;
        static bool fatal_warnings;
+       static string dependencies;
 
        static string entry_point;
 
@@ -101,6 +102,7 @@ class Vala.Compiler {
                { "internal-vapi", 0, 0, OptionArg.FILENAME, ref internal_vapi_filename, "Output vapi with internal api", "FILE" },
                { "fast-vapi", 0, 0, OptionArg.STRING, ref fast_vapi_filename, "Output vapi without performing symbol resolution", null },
                { "use-fast-vapi", 0, 0, OptionArg.STRING_ARRAY, ref fast_vapis, "Use --fast-vapi output during this compile", null },
+               { "deps", 0, 0, OptionArg.STRING, ref dependencies, "Write make-style dependency information to this file", 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 },
                { "output", 'o', 0, OptionArg.FILENAME, ref output, "Place output in file FILE", "FILE" },
@@ -545,6 +547,10 @@ class Vala.Compiler {
                        internal_vapi_filename = null;
                }
 
+               if (dependencies != null) {
+                       context.write_dependencies (dependencies);
+               }
+
                if (!ccode_only) {
                        var ccompiler = new CCodeCompiler ();
                        if (cc_command == null && Environment.get_variable ("CC") != null) {
index 476142c178f692c14ba5dd76917299c7aadeec2a..38e01e32df3089bf6893d98ace87dfb87c15cade 100644 (file)
@@ -362,4 +362,21 @@ public class Vala.CodeContext {
 
                return null;
        }
+
+       public void write_dependencies (string filename) {
+               var stream = FileStream.open (filename, "w");
+
+               if (stream == null) {
+                       Report.error (null, "unable to open `%s' for writing".printf (filename));
+                       return;
+               }
+
+               stream.printf ("%s:", filename);
+               foreach (var src in source_files) {
+                       if (src.file_type == SourceFileType.FAST && src.used) {
+                               stream.printf (" %s", src.filename);
+                       }
+               }
+               stream.printf ("\n\n");
+       }
 }
index 15c3a6b9c487a3a7a6dd43e812d3c0a79b62dcdc..28397cf4b8bee123c713b00503a79906167fcd2a 100644 (file)
@@ -67,6 +67,12 @@ public class Vala.SourceFile {
                }
        }
 
+       /**
+        * If the file has been used (ie: if anything in the file has
+        * been found by symbol resolution).
+        */
+       public bool used { get; set; }
+
        private ArrayList<Comment> comments = new ArrayList<Comment> ();
 
        public List<UsingDirective> current_using_directives { get; set; default = new ArrayList<UsingDirective> (); }
index b63662456fb3f368aa9408d6375153cec2698ee0..9caaa2789257e721687e4d8331b75045d1f22b1a 100644 (file)
@@ -97,7 +97,16 @@ public abstract class Vala.Symbol : CodeNode {
        /**
         * Specifies whether this symbol has been accessed.
         */
-       public bool used { get; set; }
+       public bool used {
+               get { return _used; }
+               set {
+                       _used = value;
+                       if (_used && source_reference != null) {
+                               source_reference.file.used = true;
+                        }
+               }
+       }
+       bool _used;
 
        /**
         * Specifies the accessibility of this symbol. Public accessibility
index 026d6ea265f2d60a38e0935195651fcc4bde1a59..ef61c36aa2e2f0a6aec0e177dd35921f5d42a919 100644 (file)
@@ -271,6 +271,7 @@ public class Vala.SymbolResolver : CodeVisitor {
                                Report.error (unresolved_symbol.inner.source_reference, "The symbol `%s' could not be found".printf (unresolved_symbol.inner.name));
                                return null;
                        }
+                       parent_symbol.used = true;
 
                        return parent_symbol.scope.lookup (unresolved_symbol.name);
                }
@@ -354,6 +355,7 @@ public class Vala.SymbolResolver : CodeVisitor {
 
                type.source_reference = unresolved_type.source_reference;
                type.value_owned = unresolved_type.value_owned;
+               sym.used = true;
 
                if (type is GenericType) {
                        // type parameters are always considered nullable