]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
valac: Add --enable-version-header option
authorJürg Billeter <j@bitron.ch>
Thu, 28 Jan 2010 00:57:41 +0000 (01:57 +0100)
committerJürg Billeter <j@bitron.ch>
Sun, 21 Mar 2010 07:53:13 +0000 (08:53 +0100)
Writes Vala version in generated files. Disabled by default for
bootstrapping reasons.

Based on patch by Marc-André Lureau, fixes bug 608371.

ccode/Makefile.am
ccode/valaccodewriter.vala
codegen/valaccodebasemodule.vala
compiler/valacompiler.vala
vala/valacodecontext.vala
vala/valacodewriter.vala

index fdc07bb2f245dfcfb915351384642daebd050f57..f3b5d2e7cfdb72d6b6a6c3282b380c326f1605d3 100644 (file)
@@ -77,7 +77,7 @@ ccodeinclude_HEADERS = \
        $(NULL)
 
 ccode.vapi ccode.vala.stamp: $(libvalaccode_la_VALASOURCES)
-       $(VALAC) $(COVERAGE_VALAFLAGS) $(VALAFLAGS) -C --vapidir $(srcdir)/../vapi --pkg gobject-2.0 --vapidir ../gee --pkg gee -H valaccode.h --library ccode $^
+       $(VALAC) $(COVERAGE_VALAFLAGS) $(VALAFLAGS) -C --vapidir $(srcdir)/../vapi --pkg gobject-2.0 --vapidir ../gee --pkg gee --pkg config -H valaccode.h --library ccode $^
        touch $@
 
 libvalaccode_la_LIBADD = \
index f2ddb7e388ea70563b22cbec5184d7680ec8fb01..ea10cbe822f3a604a65739362b52f6dc33d1b86f 100644 (file)
@@ -71,7 +71,7 @@ public class Vala.CCodeWriter {
         * @return true if the file has been opened successfully,
         *         false otherwise
         */
-       public bool open () {
+       public bool open (bool write_version) {
                file_exists = FileUtils.test (filename, FileTest.EXISTS);
                if (file_exists) {
                        temp_filename = "%s.valatmp".printf (filename);
@@ -84,7 +84,10 @@ public class Vala.CCodeWriter {
                        return false;
                }
 
-               write_string ("/* %s generated by valac, the Vala compiler".printf (Path.get_basename (filename)));
+               var opening = write_version ?
+                       "/* %s generated by valac %s, the Vala compiler".printf (Path.get_basename (filename), Config.BUILD_VERSION) :
+                       "/* %s generated by valac, the Vala compiler".printf (Path.get_basename (filename));
+               write_string (opening);
 
                // Write the file name if known
                if (source_filename != null) {
index f134d79976e869dda4e9286bd592e09f1baa61cd..dd2a158beadcefdda316a80d9296830722392c07 100644 (file)
@@ -390,7 +390,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
                // generate C header file for public API
                if (context.header_filename != null) {
                        var writer = new CCodeWriter (context.header_filename);
-                       if (!writer.open ()) {
+                       if (!writer.open (context.version_header)) {
                                Report.error (null, "unable to open `%s' for writing".printf (writer.filename));
                                return;
                        }
@@ -429,7 +429,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
                // generate C header file for internal API
                if (context.internal_header_filename != null) {
                        var writer = new CCodeWriter (context.internal_header_filename);
-                       if (!writer.open ()) {
+                       if (!writer.open (context.version_header)) {
                                Report.error (null, "unable to open `%s' for writing".printf (writer.filename));
                                return;
                        }
@@ -677,7 +677,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
                }
                
                var writer = new CCodeWriter (source_file.get_csource_filename (), source_file.filename);
-               if (!writer.open ()) {
+               if (!writer.open (context.version_header)) {
                        Report.error (null, "unable to open `%s' for writing".printf (writer.filename));
                        return;
                }
index 628c6cde78733144bd6fa5329a90cc2e0a0f9f36..b6360372f80fee18fe02de965fdfba4cc3c34b7b 100644 (file)
@@ -70,6 +70,8 @@ class Vala.Compiler {
        static bool verbose_mode;
        static string profile;
        static bool nostdpkg;
+       static bool enable_version_header;
+       static bool disable_version_header;
 
        static string entry_point;
 
@@ -115,6 +117,8 @@ class Vala.Compiler {
                { "quiet", 'q', 0, OptionArg.NONE, ref quiet_mode, "Do not print messages to the console", null },
                { "verbose", 'v', 0, OptionArg.NONE, ref verbose_mode, "Print additional messages to the console", null },
                { "target-glib", 0, 0, OptionArg.STRING, ref target_glib, "Target version of glib for code generation", "MAJOR.MINOR" },
+               { "enable-version-header", 0, 0, OptionArg.NONE, ref enable_version_header, "Write vala build version in generated files", null },
+               { "disable-version-header", 0, 0, OptionArg.NONE, ref disable_version_header, "Do not write vala build version in generated files", null },
                { "", 0, 0, OptionArg.FILENAME_ARRAY, ref sources, null, "FILE..." },
                { null }
        };
@@ -209,6 +213,7 @@ class Vala.Compiler {
                context.report.enable_warnings = !disable_warnings;
                context.report.set_verbose_errors (!quiet_mode);
                context.verbose_mode = verbose_mode;
+               context.version_header = enable_version_header;
 
                context.ccode_only = ccode_only;
                context.compile_only = compile_only;
@@ -407,7 +412,7 @@ class Vala.Compiler {
                }
 
                context.codegen.emit (context);
-               
+
                if (context.report.get_errors () > 0) {
                        return quit ();
                }
index 9b24fcb07bfbc7a7b162f752ce7180b8c44436fc..41571ad99391e913b8cc1db2556e59c5692d08ea 100644 (file)
@@ -147,6 +147,8 @@ public class Vala.CodeContext {
 
        public bool verbose_mode { get; set; }
 
+       public bool version_header { get; set; }
+
        /**
         * Returns true if the target version of glib is greater than or 
         * equal to the specified version.
index 0a10126373db2046f3523665f0838c843ee968d3..a41b388e5be88fbf6893b5058ab3190e8e6fdd2d 100644 (file)
@@ -75,7 +75,10 @@ public class Vala.CodeWriter : CodeVisitor {
                        return;
                }
 
-               write_string ("/* %s generated by %s, do not modify. */".printf (Path.get_basename (filename), Environment.get_prgname ()));
+               var header = context.version_header ?
+                       "/* %s generated by %s %s, do not modify. */".printf (Path.get_basename (filename), Environment.get_prgname (), Config.BUILD_VERSION) :
+                       "/* %s generated by %s, do not modify. */".printf (Path.get_basename (filename), Environment.get_prgname ());
+               write_string (header);
                write_newline ();
                write_newline ();