From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by sourceware.org (Postfix) with ESMTPS id B4949385E006 for ; Fri, 27 Mar 2020 11:45:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B4949385E006 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=andrew.burgess@embecosm.com Received: by mail-wm1-x341.google.com with SMTP id z18so11101005wmk.2 for ; Fri, 27 Mar 2020 04:45:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=tmedfPllcOJlXjUYo8SWpDH/z+KT64RQMHHNM6NBkUY=; b=IUVv09xjHDnQ8oy+LTRtRXSV+wJituAotZT0lVR8lejMC7qF/BHq3+dpof2vJ6wieV uOk8O9ahtGWVmEv6afv7Uk7enF0URJBDUEbSxBrrtKI08iw1jSbFPDaaM62/gh7tcJfX Fard2KDd1T0iQBhHa0auuX4tfNzHqtFDhflbuIBs2Dge2nldvsVBtdVUbmHZ2asfVoAG jZ/Nh0t0qJx7B9uNoRkmol3Ak9+xeSKS5Cgpo91MO1VnseK2VwQWfawl2nKj/T8y0JW1 ntR5Z+0F58ccGiCUAHCCcBnFKtQ4paWbC+nNyMLaOKdlGwBEfZkjujpFkIipQE2Hk451 KJMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=tmedfPllcOJlXjUYo8SWpDH/z+KT64RQMHHNM6NBkUY=; b=ZroKgTmlFJowl5SdwezhpS5OxQIx+J6ExyERy0kHMqKov7uvFHsyys5WymFPV0J3we 7A+8D5yc8pzJ8Gvpcin9Mo1lU6dSwCKpubH617C0/D/5Hbb8evKRp1mNoUoCGpmdR800 bIEy20t3URaGeoYWSHCRPb7F1Y23kpkciuYLtbUjAUQZEjNmQCyzo3YoNedrfWxGx1hT N7PF+YO3dtnrnsFPAFGTwEwHlnz3MvSIGEHmKGcX1x7k3mIXyRw8nW/6E1stMr5sngSY buKDdjCGIS5evl2hD69CTosry/RKEBuDK7BPbB8rLBqwU2iYIPRhdVVt3OXqbnfUIR3a VD/w== X-Gm-Message-State: ANhLgQ0Y+8sHN3mU3YQuR4KHM/ac5N3zFAO5ONuH/lVOBf4P3g7j0iTg WoNEyK0qKh8wbY0x7sC6ARSk66giHn0= X-Google-Smtp-Source: ADFU+vsi7+CTs3BuhNkt6TmJ3IuKIebp6ivNDFI692UP1zjZYUaDeTvcbfLC6VsC+mhJmTibyWHJBg== X-Received: by 2002:a1c:de07:: with SMTP id v7mr5192103wmg.79.1585309502578; Fri, 27 Mar 2020 04:45:02 -0700 (PDT) Received: from localhost (host86-186-80-207.range86-186.btcentralplus.com. [86.186.80.207]) by smtp.gmail.com with ESMTPSA id g7sm8083713wrq.21.2020.03.27.04.45.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 27 Mar 2020 04:45:01 -0700 (PDT) Date: Fri, 27 Mar 2020 11:45:01 +0000 From: Andrew Burgess To: Simon Marchi Cc: gdb-patches@sourceware.org, Joel Brobecker Subject: Re: [RFC] Add git sha information to the gdb version string Message-ID: <20200327114500.GA587@embecosm.com> References: <20200325114811.6234-1-andrew.burgess@embecosm.com> <47128465-bbae-6241-6b04-929163f15229@simark.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <47128465-bbae-6241-6b04-929163f15229@simark.ca> X-Operating-System: Linux/4.18.19-100.fc27.x86_64 (x86_64) X-Uptime: 11:40:15 up 41 days, 23:08, X-Fortune: Time flies like an arrow. Fruit flies like a banana. X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] User-Agent: Mutt/1.9.2 (2017-12-15) X-Spam-Status: No, score=-26.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Mar 2020 11:45:05 -0000 * Simon Marchi [2020-03-26 10:55:59 -0400]: > Hi Andrew, > > On 2020-03-25 7:48 a.m., Andrew Burgess wrote: > > I don't know if there is any interest in adding git sha information to > > the GDB version string. I seem to recall this was discussed briefly > > at 2019's GNU cauldron, but I don't recall if there was interest in > > the idea or not. > > > > Personally I think having the git information in the binary can be > > helpful, so below is an initial proposal. I'm happy to change this as > > needed if people have feedback on how to improve it. > > > > Let me know what you think, > > > > Thanks, > > Andrew > > I am in favor of this, and I have no comments on the user-visible result, I like the > way it looks. > > When we discussed this, we had the "build date" and the "git sha1" camps. I think > they both have their use, so keeping both in the version string is good. > > For the shell script, I'd suggest to first make a patch (probably obvious) to make it > shellcheck-clean [1], and then ensure that your patch keeps it clean. shellcheck finds > so many little gotchas of shell scripting. > > [1] https://github.com/koalaman/shellcheck Good idea, I'll take a look at doing this. > > > The file gdbsupport/remote-repository contains the pattern used to > > identify the remote repository, and the name of the upstream branch > > from that repository which we care about. For us this will be > > sourceware and master, but by moving these strings into a separate > > file anyone maintaining an out of tree GDB can easily update these to > > point to their repository and branch, and get project specific version > > strings. > > What is the advantage of doing this, versus just doing > > git-merge-base master HEAD > > ... which would just use the local master branch? I'd very much like to not make assumptions about what people have chosen to name branches in their local repository. > > I presume that this file will need to be updated to change the branch name > in the stable branches (CCing Joel for that). Yes, if we wanted the merge-base part to show anything better than the SHA where the release branch forked from the master branch then this file would need to be changed when the release branch was created. > > > diff --git a/gdbsupport/create-version.sh b/gdbsupport/create-version.sh > > index 81d6dbf8c1f..2f8e5a3e283 100755 > > --- a/gdbsupport/create-version.sh > > +++ b/gdbsupport/create-version.sh > > @@ -27,9 +27,54 @@ host_alias="$2" > > target_alias="$3" > > output="$4" > > > > +GIT_TAG="" > > +if $(cd $srcdir && git rev-parse --show-toplevel >/dev/null 2>/dev/null); then > > + short_head_sha=$(cd $srcdir && git rev-parse --short HEAD) > > + > > + dirty_mark="" > > + (cd $srcdir && git update-index -q --refresh) > > > > + test -z "$(cd $srcdir && git diff-index --name-only HEAD --)" || > > + dirty_mark="-dirty" > > + > > + remote_repo_pattern=`grep ^pattern: \ > > + $srcdir/../gdbsupport/remote-repository \ > > + | cut -d: -f2-` > > + remote_repo_branch=`grep ^branch: \ > > + $srcdir/../gdbsupport/remote-repository \ > > + | cut -d: -f2-` > > + branch_info="" > > + remote_name=`(cd $srcdir && git remote -v) \ > > + | grep ${remote_repo_pattern} | grep \(fetch\) \ > > + | awk -F '\t' '{print $1}'` > > + if [ -n "${remote_name}" ]; then > > + remote_branch="${remote_name}/${remote_repo_branch}" > > + # If the remote branch contains our commit, then we're good. > > + if ! $(cd $srcdir && git merge-base \ > > + --is-ancestor ${short_head_sha} \ > > + ${remote_branch}); then > > + # SHA is not on the remote tracking branch. We need to figure out > > + # the merge base, and the distance from that merge base. > > + merge_base_sha=$(cd $srcdir && git merge-base ${short_head_sha} \ > > + ${remote_branch}) > > + short_merge_base_sha=$(cd $srcdir \ > > + && git rev-parse \ > > + --short ${merge_base_sha}) > > + commit_count=$(cd $srcdir \ > > + && git rev-list --count ${merge_base_sha}..HEAD) > > + branch_info="-${short_merge_base_sha}-${commit_count}" > > + fi > > + else > > + branch_info="-unknown" > > + fi > > + GIT_TAG="${short_head_sha}${branch_info}${dirty_mark}" > > +fi > > Could you please comment the code a bit more, to say what each line does? It will > make it easier to read in the future, if we want to fix/modify it. Will do. Thanks, Andrew