From: Jürg Billeter Date: Thu, 28 Jan 2010 00:57:41 +0000 (+0100) Subject: valac: Add --enable-version-header option X-Git-Tag: 0.8.0~124 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=82eaf6f167ba40e05dfd96448b575ffe3282f362;p=thirdparty%2Fvala.git valac: Add --enable-version-header option Writes Vala version in generated files. Disabled by default for bootstrapping reasons. Based on patch by Marc-André Lureau, fixes bug 608371. --- diff --git a/ccode/Makefile.am b/ccode/Makefile.am index fdc07bb2f..f3b5d2e7c 100644 --- a/ccode/Makefile.am +++ b/ccode/Makefile.am @@ -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 = \ diff --git a/ccode/valaccodewriter.vala b/ccode/valaccodewriter.vala index f2ddb7e38..ea10cbe82 100644 --- a/ccode/valaccodewriter.vala +++ b/ccode/valaccodewriter.vala @@ -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) { diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index f134d7997..dd2a158be 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -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; } diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala index 628c6cde7..b6360372f 100644 --- a/compiler/valacompiler.vala +++ b/compiler/valacompiler.vala @@ -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 (); } diff --git a/vala/valacodecontext.vala b/vala/valacodecontext.vala index 9b24fcb07..41571ad99 100644 --- a/vala/valacodecontext.vala +++ b/vala/valacodecontext.vala @@ -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. diff --git a/vala/valacodewriter.vala b/vala/valacodewriter.vala index 0a1012637..a41b388e5 100644 --- a/vala/valacodewriter.vala +++ b/vala/valacodewriter.vala @@ -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 ();