Commit 82eaf6f1 authored by Jürg Billeter's avatar Jürg Billeter

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.
parent 8ada9e89
......@@ -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 = \
......
......@@ -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) {
......
......@@ -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;
}
......
......@@ -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 ();
}
......
......@@ -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.
......
......@@ -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 ();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment