Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH 1/2] support/scripts/setlocalversion: fix detection of hg revision when _not_ on branch 'default'
@ 2019-01-30 20:15 Thomas De Schampheleire
  2019-01-30 20:15 ` [Buildroot] [PATCH 2/2] support/scripts/setlocalversion: ignore user settings for Mercurial Thomas De Schampheleire
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Thomas De Schampheleire @ 2019-01-30 20:15 UTC (permalink / raw)
  To: buildroot

From: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>

When Buildroot is stored in a Mercurial repository on a branch other than
'default' ('master' in git terms), setlocalversion (used to populate
/etc/os-release) will incorrectly think that this is a tagged version and
will NOT print out the revision hash.

This is due to the fact that the output of 'hg id' is assumed to be
    "<revision> <tags-if-any>"
but when on a branch it actually is:
    "<revision> (<branch>) <tags-if-any>"

To let setlocalversion receive the output it expects, explicitly ask 'hg id'
to retrieve only the revision hash and any tags, ommitting any branch
information.

Signed-off-by: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
---
 support/scripts/setlocalversion | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/support/scripts/setlocalversion b/support/scripts/setlocalversion
index 33cd605bf3..45f4283bb1 100755
--- a/support/scripts/setlocalversion
+++ b/support/scripts/setlocalversion
@@ -53,7 +53,7 @@ if head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
 fi
 
 # Check for mercurial and a mercurial repo.
-if hgid=`hg id 2>/dev/null`; then
+if hgid=`hg id --id --tags 2>/dev/null`; then
 	tag=`printf '%s' "$hgid" | cut -d' ' -f2 --only-delimited`
 
 	# Do we have an untagged version?
-- 
2.19.2

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Buildroot] [PATCH 2/2] support/scripts/setlocalversion: ignore user settings for Mercurial
  2019-01-30 20:15 [Buildroot] [PATCH 1/2] support/scripts/setlocalversion: fix detection of hg revision when _not_ on branch 'default' Thomas De Schampheleire
@ 2019-01-30 20:15 ` Thomas De Schampheleire
  2019-02-18 16:13   ` Peter Korsgaard
  2019-02-04 20:24 ` [Buildroot] [PATCH 1/2] support/scripts/setlocalversion: fix detection of hg revision when _not_ on branch 'default' Thomas Petazzoni
  2019-02-18 16:13 ` Peter Korsgaard
  2 siblings, 1 reply; 5+ messages in thread
From: Thomas De Schampheleire @ 2019-01-30 20:15 UTC (permalink / raw)
  To: buildroot

From: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>

setlocalversion will use 'hg id' to determine whether or not the current
revision is tagged. If there is no tag, the Mercurial revision is printed,
otherwise nothing is printed.

The problem is that the user may have custom configuration settings (in
their ~/.hgrc file or similar) that changes the output of 'hg id' in a way
that the script does not expect. In such cases, the Mercurial revision may
not be printed or printed incorrectly.

It is good practice to ignore the user environment when calling Mercurial
commands from a well-defined script, by setting the environment variable
HGRCPATH to the empty string. See also 'hg help environment'.

In the particular case of Nokia, a custom extension adds dynamic tags in the
repository, i.e. tags that are stored in a file external to the repository
and only visible when the extension is active. These tags should not
influence the behavior of setlocalversion as they are not official Buildroot
tags, i.e. even if a revision is tagged, the Mercurial revision should still
be printed.

Note that this still does not solve the problem where an organization adds
_real_ tags in their Buildroot repository. For example, there might be a
moving tag 'last-validated' or tags indicating in which product release that
Buildroot revision was used. In these cases, setlocalversion will still not
behave as expected, i.e. show the Mercurial revision.

Signed-off-by: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
---
 support/scripts/setlocalversion | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/support/scripts/setlocalversion b/support/scripts/setlocalversion
index 45f4283bb1..b39b751f03 100755
--- a/support/scripts/setlocalversion
+++ b/support/scripts/setlocalversion
@@ -53,7 +53,7 @@ if head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
 fi
 
 # Check for mercurial and a mercurial repo.
-if hgid=`hg id --id --tags 2>/dev/null`; then
+if hgid=`HGRCPATH= hg id --id --tags 2>/dev/null`; then
 	tag=`printf '%s' "$hgid" | cut -d' ' -f2 --only-delimited`
 
 	# Do we have an untagged version?
-- 
2.19.2

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Buildroot] [PATCH 1/2] support/scripts/setlocalversion: fix detection of hg revision when _not_ on branch 'default'
  2019-01-30 20:15 [Buildroot] [PATCH 1/2] support/scripts/setlocalversion: fix detection of hg revision when _not_ on branch 'default' Thomas De Schampheleire
  2019-01-30 20:15 ` [Buildroot] [PATCH 2/2] support/scripts/setlocalversion: ignore user settings for Mercurial Thomas De Schampheleire
@ 2019-02-04 20:24 ` Thomas Petazzoni
  2019-02-18 16:13 ` Peter Korsgaard
  2 siblings, 0 replies; 5+ messages in thread
From: Thomas Petazzoni @ 2019-02-04 20:24 UTC (permalink / raw)
  To: buildroot

On Wed, 30 Jan 2019 21:15:07 +0100
Thomas De Schampheleire <patrickdepinguin@gmail.com> wrote:

> From: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
> 
> When Buildroot is stored in a Mercurial repository on a branch other than
> 'default' ('master' in git terms), setlocalversion (used to populate
> /etc/os-release) will incorrectly think that this is a tagged version and
> will NOT print out the revision hash.
> 
> This is due to the fact that the output of 'hg id' is assumed to be
>     "<revision> <tags-if-any>"
> but when on a branch it actually is:
>     "<revision> (<branch>) <tags-if-any>"
> 
> To let setlocalversion receive the output it expects, explicitly ask 'hg id'
> to retrieve only the revision hash and any tags, ommitting any branch
> information.
> 
> Signed-off-by: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
> ---
>  support/scripts/setlocalversion | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Both applied to master. Thanks!

Thomas
-- 
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Buildroot] [PATCH 1/2] support/scripts/setlocalversion: fix detection of hg revision when _not_ on branch 'default'
  2019-01-30 20:15 [Buildroot] [PATCH 1/2] support/scripts/setlocalversion: fix detection of hg revision when _not_ on branch 'default' Thomas De Schampheleire
  2019-01-30 20:15 ` [Buildroot] [PATCH 2/2] support/scripts/setlocalversion: ignore user settings for Mercurial Thomas De Schampheleire
  2019-02-04 20:24 ` [Buildroot] [PATCH 1/2] support/scripts/setlocalversion: fix detection of hg revision when _not_ on branch 'default' Thomas Petazzoni
@ 2019-02-18 16:13 ` Peter Korsgaard
  2 siblings, 0 replies; 5+ messages in thread
From: Peter Korsgaard @ 2019-02-18 16:13 UTC (permalink / raw)
  To: buildroot

>>>>> "Thomas" == Thomas De Schampheleire <patrickdepinguin@gmail.com> writes:

 > From: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
 > When Buildroot is stored in a Mercurial repository on a branch other than
 > 'default' ('master' in git terms), setlocalversion (used to populate
 > /etc/os-release) will incorrectly think that this is a tagged version and
 > will NOT print out the revision hash.

 > This is due to the fact that the output of 'hg id' is assumed to be
 >     "<revision> <tags-if-any>"
 > but when on a branch it actually is:
 >     "<revision> (<branch>) <tags-if-any>"

 > To let setlocalversion receive the output it expects, explicitly ask 'hg id'
 > to retrieve only the revision hash and any tags, ommitting any branch
 > information.

 > Signed-off-by: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>

Committed to 2018.02.x and 2018.11.x, thanks.

-- 
Bye, Peter Korsgaard

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Buildroot] [PATCH 2/2] support/scripts/setlocalversion: ignore user settings for Mercurial
  2019-01-30 20:15 ` [Buildroot] [PATCH 2/2] support/scripts/setlocalversion: ignore user settings for Mercurial Thomas De Schampheleire
@ 2019-02-18 16:13   ` Peter Korsgaard
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Korsgaard @ 2019-02-18 16:13 UTC (permalink / raw)
  To: buildroot

>>>>> "Thomas" == Thomas De Schampheleire <patrickdepinguin@gmail.com> writes:

 > From: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
 > setlocalversion will use 'hg id' to determine whether or not the current
 > revision is tagged. If there is no tag, the Mercurial revision is printed,
 > otherwise nothing is printed.

 > The problem is that the user may have custom configuration settings (in
 > their ~/.hgrc file or similar) that changes the output of 'hg id' in a way
 > that the script does not expect. In such cases, the Mercurial revision may
 > not be printed or printed incorrectly.

 > It is good practice to ignore the user environment when calling Mercurial
 > commands from a well-defined script, by setting the environment variable
 > HGRCPATH to the empty string. See also 'hg help environment'.

 > In the particular case of Nokia, a custom extension adds dynamic tags in the
 > repository, i.e. tags that are stored in a file external to the repository
 > and only visible when the extension is active. These tags should not
 > influence the behavior of setlocalversion as they are not official Buildroot
 > tags, i.e. even if a revision is tagged, the Mercurial revision should still
 > be printed.

 > Note that this still does not solve the problem where an organization adds
 > _real_ tags in their Buildroot repository. For example, there might be a
 > moving tag 'last-validated' or tags indicating in which product release that
 > Buildroot revision was used. In these cases, setlocalversion will still not
 > behave as expected, i.e. show the Mercurial revision.

 > Signed-off-by: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>

Committed to 2018.02.x and 2018.11.x, thanks.

-- 
Bye, Peter Korsgaard

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-02-18 16:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-30 20:15 [Buildroot] [PATCH 1/2] support/scripts/setlocalversion: fix detection of hg revision when _not_ on branch 'default' Thomas De Schampheleire
2019-01-30 20:15 ` [Buildroot] [PATCH 2/2] support/scripts/setlocalversion: ignore user settings for Mercurial Thomas De Schampheleire
2019-02-18 16:13   ` Peter Korsgaard
2019-02-04 20:24 ` [Buildroot] [PATCH 1/2] support/scripts/setlocalversion: fix detection of hg revision when _not_ on branch 'default' Thomas Petazzoni
2019-02-18 16:13 ` Peter Korsgaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox