public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin] Cygwin: uname: generate default release string from git as well
Date: Wed,  7 Dec 2022 20:30:46 +0000 (GMT)	[thread overview]
Message-ID: <20221207203046.890AA381ECA3@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=97eb64b909bc0a47b3159ae7f7ef2060e4bb8d54

commit 97eb64b909bc0a47b3159ae7f7ef2060e4bb8d54
Author:     Corinna Vinschen <corinna@vinschen.de>
AuthorDate: Wed Dec 7 21:14:27 2022 +0100
Commit:     Corinna Vinschen <corinna@vinschen.de>
CommitDate: Wed Dec 7 21:30:23 2022 +0100

    Cygwin: uname: generate default release string from git as well
    
    When building a release with cygport, we get uname version info
    from cygport, which in turn gets version info from `git describe'.
    
    During development, the release info for local builds was not
    that helpful yet.  Fix that, by creating version info from
    `git describe' if CYGPORT_RELEASE_INFO isn't given.  Make sure to
    always force rebuild of the version info to pick up source file
    changes as well as git actions.
    
    Rearrange code slightly to generate machine info first, release info
    after that.  Use snprintf to generate release string safely.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/Makefile.am |  8 +++++++-
 winsup/cygwin/uname.cc    | 31 +++++++++++++++++--------------
 2 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/winsup/cygwin/Makefile.am b/winsup/cygwin/Makefile.am
index 8ba5ae2717b0..b1849d5a6737 100644
--- a/winsup/cygwin/Makefile.am
+++ b/winsup/cygwin/Makefile.am
@@ -365,7 +365,8 @@ GMON_FILES= \
 	profil.c
 
 GENERATED_FILES= \
-	sigfe.s
+	sigfe.s \
+	uname_version.c
 
 liblib_a_SOURCES= \
 	$(LIB_FILES)
@@ -418,6 +419,11 @@ dirs = $(srcdir) $(srcdir)/fhandler $(srcdir)/lib $(srcdir)/libc $(srcdir)/math
 find_src_files = $(wildcard $(dir)/*.[chS]) $(wildcard $(dir)/*.cc)
 src_files := $(foreach dir,$(dirs),$(find_src_files))
 
+uname_version.c: .FORCE
+	$(AM_V_GEN)cd $(srcdir) && \
+	echo "const char *uname_dev_version = \"$$(git describe --dirty | sed -e 's/cygwin-//')\";" > $(abs_builddir)/uname_version.c
+.FORCE:
+
 # mkvers.sh creates version.cc in the first place, winver.o always
 # second, so version.cc is always older than winver.o
 version.cc: scripts/mkvers.sh include/cygwin/version.h winver.rc $(src_files)
diff --git a/winsup/cygwin/uname.cc b/winsup/cygwin/uname.cc
index e893660c6a1d..d2f93304e494 100644
--- a/winsup/cygwin/uname.cc
+++ b/winsup/cygwin/uname.cc
@@ -9,6 +9,7 @@ Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
 details. */
 
 #include "winsup.h"
+#include <stdio.h>
 #include <sys/utsname.h>
 #include <netdb.h>
 #include "cygwin_version.h"
@@ -41,29 +42,31 @@ uname_x (struct utsname *name)
       memset (buf, 0, sizeof buf);
       cygwin_gethostname (buf, sizeof buf - 1);
       strncat (name->nodename, buf, sizeof (name->nodename) - 1);
-      /* release */
-#ifdef CYGPORT_RELEASE_INFO
-      stpcpy (name->release, __XSTRING (CYGPORT_RELEASE_INFO));
-#else
-      __small_sprintf (name->release, "%d.%d.%d-0.%d.local.",
-		       cygwin_version.dll_major / 1000,
-		       cygwin_version.dll_major % 1000,
-		       cygwin_version.dll_minor,
-		       cygwin_version.api_minor);
-#endif
-      /* version */
-      stpcpy (name->version, cygwin_version.dll_build_date);
-      strcat (name->version, " UTC");
       /* machine */
       switch (wincap.cpu_arch ())
 	{
 	  case PROCESSOR_ARCHITECTURE_AMD64:
-	    strcat (name->release, strcpy (name->machine, "x86_64"));
+	    strcpy (name->machine, "x86_64");
 	    break;
 	  default:
 	    strcpy (name->machine, "unknown");
 	    break;
 	}
+      /* release */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-truncation="
+#ifdef CYGPORT_RELEASE_INFO
+      snprintf (name->release, _UTSNAME_LENGTH, "%s.%s",
+		__XSTRING (CYGPORT_RELEASE_INFO), name->machine);
+#else
+      extern const char *uname_dev_version;
+      snprintf (name->release, _UTSNAME_LENGTH, "%s.%s",
+		uname_dev_version, name->machine);
+#endif
+#pragma GCC diagnostic pop
+      /* version */
+      stpcpy (name->version, cygwin_version.dll_build_date);
+      strcat (name->version, " UTC");
       /* domainame */
       memset (buf, 0, sizeof buf);
       getdomainname (buf, sizeof buf - 1);

                 reply	other threads:[~2022-12-07 20:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221207203046.890AA381ECA3@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).