[m-rev.] for review: support optional package version information
Julien Fischer
jfischer at opturion.com
Sat Sep 9 00:43:17 AEST 2023
For review by anyone.
Support optional package version information.
Add a new configure option, ---with-pkgversion, that allows those packaging
Mercury to include additional version information specific to their package in
the output of mmc --version etc.
Omit version and copyright information from the short usage messages for mmc, mprof
and mcov. The result is less cluttered and more direct.
Omit version information from the long usage (i.e. --help) message for the
above programs. This is to save space on the first line of the output and also
brings the man pages for mmc, mprof and mcov into line with the other man
pages, which do *not* have version information in their NAME section.
configure.ac:
Add the new --with-pkgversion option.
runtime/mercury_conf.h.in:
runtime/mercury_dotnet.cs.in:
java/runtime/Constants.java.in:
Define a constant for the package version.
library/library.m:
Add version/3, which returns the package version string in addition
to the version and fullarch strings.
compiler/handle_options.m:
profiler/mercury_profile.m:
slice/mcov.m:
Include a non-empty package version in the output of --version.
Make the above changes to the short and long usage messages.
Add an XXX about mprof's short usage message.
Julien.
diff --git a/compiler/handle_options.m b/compiler/handle_options.m
index c9217b6..413adab 100644
--- a/compiler/handle_options.m
+++ b/compiler/handle_options.m
@@ -3116,9 +3116,14 @@ disable_smart_recompilation(ProgressStream, OptionDescr, !Globals, !IO) :-
%---------------------------------------------------------------------------%
display_compiler_version(ProgressStream, !IO) :-
- library.version(Version, _FullArch),
- io.format(ProgressStream, "Mercury Compiler, version %s\n",
- [s(Version)], !IO),
+ library.version(Version, Package, _FullArch),
+ io.format(ProgressStream, "Mercury Compiler, version %s", [s(Version)],
+ !IO),
+ ( if Package = "" then
+ io.nl(ProgressStream, !IO)
+ else
+ io.format(ProgressStream, " (%s)\n", [s(Package)], !IO)
+ ),
write_copyright_notice(ProgressStream, !IO).
usage_errors(ErrorStream, Globals, Specs, !IO) :-
@@ -3136,7 +3141,6 @@ short_usage(ProgressStream, !IO) :-
get_already_printed_usage(AlreadyPrinted, !IO),
(
AlreadyPrinted = no,
- display_compiler_version(ProgressStream, !IO),
io.write_strings(ProgressStream, [
"Usage: mmc [<options>] <arguments>\n",
"Use `mmc --help' for more information.\n"
@@ -3150,10 +3154,8 @@ long_usage(ProgressStream, !IO) :-
% long_usage is called from only one place, so can't print duplicate
% copies of the long usage message. We can print both a short and along
% usage message, but there is no simple way to avoid that.
- library.version(Version, _Fullarch),
- io.format(ProgressStream,
- "Name: mmc - Melbourne Mercury Compiler, version %s\n",
- [s(Version)], !IO),
+ io.write_string(ProgressStream,
+ "Name: mmc - Melbourne Mercury Compiler\n", !IO),
write_copyright_notice(ProgressStream, !IO),
io.write_strings(ProgressStream, [
"Usage: mmc [<options>] <arguments>\n",
diff --git a/configure.ac b/configure.ac
index 400f896..60d4103 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@
# vim: ts=4 sw=4 expandtab
#-----------------------------------------------------------------------------#
# Copyright (C) 1995-2012 The University of Melbourne.
-# Copyright (C) 2013-2022 The Mercury team.
+# Copyright (C) 2013-2023 The Mercury team.
# This file may only be copied under the terms of the GNU General
# Public Licence - see the file COPYING in the Mercury distribution.
#-----------------------------------------------------------------------------#
@@ -105,6 +105,25 @@ AC_PREFIX_DEFAULT(/usr/local/mercury-`. ./VERSION; echo $VERSION`)
#-----------------------------------------------------------------------------#
#
+# Let the user specify an optional package version.
+#
+
+AC_ARG_WITH(pkgversion,
+ AS_HELP_STRING([--with-pkgversion],
+ [Specify the package version for version and usage messages.]),
+ [PACKAGE="$withval"], [PACKAGE=])
+
+case "$PACKAGE" in
+ yes)
+ AC_MSG_ERROR(missing argument to --with-pkgversion=... option)
+ exit 1
+ ;;
+esac
+AC_DEFINE_UNQUOTED(MR_PKGVERSION, "$PACKAGE")
+AC_SUBST(PACKAGE)
+
+#-----------------------------------------------------------------------------#
+#
# Let the user specify which C compiler to use.
#
diff --git a/java/runtime/Constants.java.in b/java/runtime/Constants.java.in
index 3cbab90..95a92e0 100644
--- a/java/runtime/Constants.java.in
+++ b/java/runtime/Constants.java.in
@@ -3,7 +3,7 @@
// @configure_input@
//
// Copyright (C) 2001-2004 The University of Melbourne.
-// Copyright (C) 2018 The Mercury team.
+// Copyright (C) 2018, 2023 The Mercury team.
// This file is distributed under the terms specified in COPYING.LIB.
//
// This class is used to store miscellaneous Mercury-related constants.
@@ -15,4 +15,5 @@ package jmercury.runtime;
public class Constants {
public static final java.lang.String MR_VERSION = "@VERSION@";
public static final java.lang.String MR_FULLARCH = "@FULLARCH@";
+ public static final java.lang.String MR_PKGVERSION = "@PACKAGE@";
}
diff --git a/library/library.m b/library/library.m
index cdcf9ab..d2957b5 100644
--- a/library/library.m
+++ b/library/library.m
@@ -2,7 +2,7 @@
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
% Copyright (C) 1993-2007, 2009-2014 The University of Melbourne.
-% Copyright (C) 2013-2022 The Mercury team.
+% Copyright (C) 2013-2023 The Mercury team.
% This file is distributed under the terms specified in COPYING.LIB.
%---------------------------------------------------------------------------%
%
@@ -21,6 +21,10 @@
%
:- pred version(string::out, string::out) is det.
+ % version(VersionString, PackageVersionString, FullarchString)
+ %
+:- pred version(string::out, string::out, string::out) is det.
+
:- implementation.
% Everything below here is not intended to be part of the public interface,
@@ -228,34 +232,41 @@
% because that would cause bootstrapping problems: we might not have
% a working Mercury compiler to compile library.m with.
-:- pragma no_inline(pred(library.version/2)).
+version(Version, Fullarch) :-
+ version(Version, _Package, Fullarch).
+
+:- pragma no_inline(pred(library.version/3)).
:- pragma foreign_proc("C",
- version(Version::out, Fullarch::out),
+ version(Version::out, Package::out, Fullarch::out),
[will_not_call_mercury, promise_pure, thread_safe, will_not_modify_trail],
"
MR_ConstString version_string = MR_VERSION;
MR_ConstString fullarch_string = MR_FULLARCH;
+ MR_ConstString package_string = MR_PKGVERSION;
// We need to cast away const here, because Mercury declares Version
// and Fullarch to have type MR_String, not MR_ConstString.
Version = (MR_String) (MR_Word) version_string;
+ Package = (MR_String) (MR_Word) package_string;
Fullarch = (MR_String) (MR_Word) fullarch_string;
").
:- pragma foreign_proc("C#",
- version(Version::out, Fullarch::out),
+ version(Version::out, Package::out, Fullarch::out),
[will_not_call_mercury, promise_pure, thread_safe],
"
Version = runtime.Constants.MR_VERSION;
+ Package = runtime.Constants.MR_PKGVERSION;
Fullarch = runtime.Constants.MR_FULLARCH;
").
:- pragma foreign_proc("Java",
- version(Version::out, Fullarch::out),
+ version(Version::out, Package::out, Fullarch::out),
[will_not_call_mercury, promise_pure, thread_safe],
"
Version = jmercury.runtime.Constants.MR_VERSION;
+ Package = jmercury.runtime.Constants.MR_PKGVERSION;
Fullarch = jmercury.runtime.Constants.MR_FULLARCH;
").
diff --git a/profiler/mercury_profile.m b/profiler/mercury_profile.m
index 428acca..76cebec 100644
--- a/profiler/mercury_profile.m
+++ b/profiler/mercury_profile.m
@@ -92,9 +92,14 @@ postprocess_options(Args, !IO) :-
:- pred display_version(io.text_output_stream::in, io::di, io::uo) is det.
display_version(OutputStream, !IO) :-
- library.version(Version, _FullArch),
- io.format(OutputStream, "Mercury profiler, version %s\n",
- [s(Version)], !IO),
+ library.version(Version, Package, _FullArch),
+ io.format(OutputStream, "Mercury profiler, version %s", [s(Version)],
+ !IO),
+ ( if Package = "" then
+ io.nl(OutputStream, !IO)
+ else
+ io.format(OutputStream, " (%s)\n", [s(Package)], !IO)
+ ),
write_copyright_notice(OutputStream, !IO).
% Display error message and then short usage message.
@@ -109,12 +114,13 @@ usage_error(ErrorMessage, !IO) :-
short_usage(StdErr, !IO).
% Display short_usage message.
- %
+ % XXX the only place we call short_usage is in usage_error above.
+ % Also: why does the default name of the executable differ betweeen
+ % the two?
:- pred short_usage(io.text_output_stream::in, io::di, io::uo) is det.
short_usage(OutputStream, !IO) :-
io.progname_base("mprof", ProgName, !IO),
- display_version(OutputStream, !IO),
io.format(OutputStream, "Usage: %s[<options>] [<files>]\n",
[s(ProgName)], !IO),
io.format(OutputStream, "Use `%s --help' for more information.\n",
@@ -124,10 +130,7 @@ short_usage(OutputStream, !IO) :-
long_usage(OutputStream, !IO) :-
io.progname_base("mprof", ProgName, !IO),
- library.version(Version, _FullArch),
- io.format(OutputStream,
- "Name: mprof - Mercury profiler, version %s\n",
- [s(Version)], !IO),
+ io.write_string(OutputStream, "Name: mprof - Mercury profiler\n", !IO),
write_copyright_notice(OutputStream, !IO),
io.write_strings(OutputStream, [
"Usage: ", ProgName, " [<options>] [<files>]\n",
diff --git a/runtime/mercury_conf.h.in b/runtime/mercury_conf.h.in
index 780999f..63e43cb 100644
--- a/runtime/mercury_conf.h.in
+++ b/runtime/mercury_conf.h.in
@@ -479,6 +479,10 @@
#define MR_FULLARCH "unknown"
+// What package version is this? (Taken from configure --with-pkgversion.)
+
+#define MR_PKGVERSION ""
+
// Should we build the Mercury libraries as Windows DLLs?
#undef MR_USE_DLLS
diff --git a/runtime/mercury_dotnet.cs.in b/runtime/mercury_dotnet.cs.in
index 10406c0..cf32078 100644
--- a/runtime/mercury_dotnet.cs.in
+++ b/runtime/mercury_dotnet.cs.in
@@ -1,7 +1,7 @@
// vim: ts=4 sw=4 expandtab ft=cs
//
// Copyright (C) 2003-2004, 2010-2011 The University of Melbourne.
-// Copyright (C) 2014-2018, 2021 The Mercury team.
+// Copyright (C) 2014-2018, 2021, 2023 The Mercury team.
// This file is distributed under the terms specified in COPYING.LIB.
//
@@ -1122,6 +1122,7 @@ public class Constants
public static readonly string MR_VERSION = "@VERSION@";
public static readonly string MR_FULLARCH = "@FULLARCH@";
+ public static readonly string MR_PKGVERSION = "@PACKAGE@";
}
/*---------------------------------------------------------------------------*/
diff --git a/slice/mcov.m b/slice/mcov.m
index 97d18de..c82e9a7 100644
--- a/slice/mcov.m
+++ b/slice/mcov.m
@@ -437,17 +437,21 @@ write_path_port_for_user(OutStream, port_and_path(Port, Path), !IO) :-
:- pred display_version(io.text_output_stream::in, io::di, io::uo) is det.
display_version(OutStream, !IO) :-
- library.version(Version, _FullArch),
+ library.version(Version, Package, _FullArch),
io.format(OutStream,
- "Mercury Coverage Testing Tool, version %s\n",
+ "Mercury Coverage Testing Tool, version %s",
[s(Version)], !IO),
+ ( if Package = "" then
+ io.nl(OutStream, !IO)
+ else
+ io.format(OutStream, " (%s)\n", [s(Package)], !IO)
+ ),
write_copyright_notice(OutStream, !IO).
:- pred short_usage(io.text_output_stream::in, io::di, io::uo) is det.
short_usage(OutStream, !IO) :-
io.progname_base("mcov", ProgName, !IO),
- display_version(OutStream, !IO),
io.format(OutStream, "Usage: %s [<options>] [<files>]\n",
[s(ProgName)], !IO),
io.format(OutStream, "Use `%s --help' for more information.\n",
@@ -456,10 +460,8 @@ short_usage(OutStream, !IO) :-
:- pred long_usage(io.text_output_stream::in, io::di, io::uo) is det.
long_usage(OutStream, !IO) :-
- library.version(Version, _FullArch),
- io.format(OutStream,
- "Name: mcov - Mercury Coverage Testing Tool, version %s\n",
- [s(Version)], !IO),
+ io.write_string(OutStream,
+ "Name: mcov - Mercury Coverage Testing Tool\n", !IO),
write_copyright_notice(OutStream, !IO),
io.write_string(OutStream, "Usage: mcov [<options>] <arguments>\n", !IO),
io.write_string(OutStream, "Arguments:\n", !IO),
More information about the reviews
mailing list