Skip to content
Snippets Groups Projects
  1. Sep 24, 2020
    • Rasmus Villemoes's avatar
      scripts/setlocalversion: make git describe output more reliable · 548b8b51
      Rasmus Villemoes authored
      
      When building for an embedded target using Yocto, we're sometimes
      observing that the version string that gets built into vmlinux (and
      thus what uname -a reports) differs from the path under /lib/modules/
      where modules get installed in the rootfs, but only in the length of
      the -gabc123def suffix. Hence modprobe always fails.
      
      The problem is that Yocto has the concept of "sstate" (shared state),
      which allows different developers/buildbots/etc. to share build
      artifacts, based on a hash of all the metadata that went into building
      that artifact - and that metadata includes all dependencies (e.g. the
      compiler used etc.). That normally works quite well; usually a clean
      build (without using any sstate cache) done by one developer ends up
      being binary identical to a build done on another host. However, one
      thing that can cause two developers to end up with different builds
      [and thus make one's vmlinux package incompatible with the other's
      kernel-dev package], which is not captured by the metadata hashing, is
      this `git describe`: The output of that can be affected by
      
      (1) git version: before 2.11 git defaulted to a minimum of 7, since
      2.11 (git.git commit e6c587) the default is dynamic based on the
      number of objects in the repo
      (2) hence even if both run the same git version, the output can differ
      based on how many remotes are being tracked (or just lots of local
      development branches or plain old garbage)
      (3) and of course somebody could have a core.abbrev config setting in
      ~/.gitconfig
      
      So in order to avoid `uname -a` output relying on such random details
      of the build environment which are rather hard to ensure are
      consistent between developers and buildbots, make sure the abbreviated
      sha1 always consists of exactly 12 hex characters. That is consistent
      with the current rule for -stable patches, and is almost always enough
      to identify the head commit unambigously - in the few cases where it
      does not, the v5.4.3-00021- prefix would certainly nail it down.
      
      Signed-off-by: default avatarRasmus Villemoes <linux@rasmusvillemoes.dk>
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      548b8b51
  2. Nov 11, 2019
  3. Oct 15, 2019
  4. Oct 05, 2019
    • Masahiro Yamada's avatar
      scripts/setlocalversion: clear local variable to make it work for sh · 7a82e3fa
      Masahiro Yamada authored
      
      Geert Uytterhoeven reports a strange side-effect of commit 858805b3
      ("kbuild: add $(BASH) to run scripts with bash-extension"), which
      inserts the contents of a localversion file in the build directory twice.
      
      [Steps to Reproduce]
        $ echo bar > localversion
        $ mkdir build
        $ cd build/
        $ echo foo > localversion
        $ make -s -f ../Makefile defconfig include/config/kernel.release
        $ cat include/config/kernel.release
        5.4.0-rc1foofoobar
      
      This comes down to the behavior change of local variables.
      
      The 'man sh' on my Ubuntu machine, where sh is an alias to dash,
      explains as follows:
        When a variable is made local, it inherits the initial value and
        exported and readonly flags from the variable with the same name
        in the surrounding scope, if there is one. Otherwise, the variable
        is initially unset.
      
      [Test Code]
      
        foo ()
        {
                local res
                echo "res: $res"
        }
      
        res=1
        foo
      
      [Result]
      
        $ sh test.sh
        res: 1
        $ bash test.sh
        res:
      
      So, scripts/setlocalversion correctly works only for bash in spite of
      its hashbang being #!/bin/sh. Nobody had noticed it before because
      CONFIG_SHELL was previously set to bash almost all the time.
      
      Now that CONFIG_SHELL is set to sh, we must write portable and correct
      code. I gave the Fixes tag to the commit that uncovered the issue.
      
      Clear the variable 'res' in collect_files() to make it work for sh
      (and it also works on distributions where sh is an alias to bash).
      
      Fixes: 858805b3 ("kbuild: add $(BASH) to run scripts with bash-extension")
      Reported-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      Tested-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
      7a82e3fa
  5. Nov 21, 2018
    • Brian Norris's avatar
      scripts/setlocalversion: Improve -dirty check with git-status --no-optional-locks · ff64dd48
      Brian Norris authored
      
      git-diff-index does not refresh the index for you, so using it for a
      "-dirty" check can give misleading results. Commit 6147b1cf
      ("scripts/setlocalversion: git: Make -dirty check more robust") tried to
      fix this by switching to git-status, but it overlooked the fact that
      git-status also writes to the .git directory of the source tree, which
      is definitely not kosher for an out-of-tree (O=) build. That is getting
      reverted.
      
      Fortunately, git-status now supports avoiding writing to the index via
      the --no-optional-locks flag, as of git 2.14. It still calculates an
      up-to-date index, but it avoids writing it out to the .git directory.
      
      So, let's retry the solution from commit 6147b1cf using this new
      flag first, and if it fails, we assume this is an older version of git
      and just use the old git-diff-index method.
      
      It's hairy to get the 'grep -vq' (inverted matching) correct by stashing
      the output of git-status (you have to be careful about the difference
      betwen "empty stdin" and "blank line on stdin"), so just pipe the output
      directly to grep and use a regex that's good enough for both the
      git-status and git-diff-index version.
      
      Cc: Christian Kujau <lists@nerdbynature.de>
      Cc: Guenter Roeck <linux@roeck-us.net>
      Suggested-by: default avatarAlexander Kapshuk <alexander.kapshuk@gmail.com>
      Signed-off-by: default avatarBrian Norris <briannorris@chromium.org>
      Tested-by: default avatarGenki Sky <sky@genki.is>
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      ff64dd48
  6. Nov 11, 2018
    • Guenter Roeck's avatar
      Revert "scripts/setlocalversion: git: Make -dirty check more robust" · 8ef14c2c
      Guenter Roeck authored
      
      This reverts commit 6147b1cf.
      
      The reverted patch results in attempted write access to the source
      repository, even if that repository is mounted read-only.
      
      Output from "strace git status -uno --porcelain":
      
      getcwd("/tmp/linux-test", 129)          = 16
      open("/tmp/linux-test/.git/index.lock", O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC, 0666) =
      	-1 EROFS (Read-only file system)
      
      While git appears to be able to handle this situation, a monitored
      build environment (such as the one used for Chrome OS kernel builds)
      may detect it and bail out with an access violation error. On top of
      that, the attempted write access suggests that git _will_ write to the
      file even if a build output directory is specified. Users may have the
      reasonable expectation that the source repository remains untouched in
      that situation.
      
      Fixes: 6147b1cf ("scripts/setlocalversion: git: Make -dirty check more robust"
      Cc: Genki Sky <sky@genki.is>
      Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Reviewed-by: default avatarBrian Norris <briannorris@chromium.org>
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      8ef14c2c
  7. Aug 31, 2018
  8. Nov 02, 2017
    • Greg Kroah-Hartman's avatar
      License cleanup: add SPDX GPL-2.0 license identifier to files with no license · b2441318
      Greg Kroah-Hartman authored
      
      Many source files in the tree are missing licensing information, which
      makes it harder for compliance tools to determine the correct license.
      
      By default all files without license information are under the default
      license of the kernel, which is GPL version 2.
      
      Update the files which contain no license information with the 'GPL-2.0'
      SPDX license identifier.  The SPDX identifier is a legally binding
      shorthand, which can be used instead of the full boiler plate text.
      
      This patch is based on work done by Thomas Gleixner and Kate Stewart and
      Philippe Ombredanne.
      
      How this work was done:
      
      Patches were generated and checked against linux-4.14-rc6 for a subset of
      the use cases:
       - file had no licensing information it it.
       - file was a */uapi/* one with no licensing information in it,
       - file was a */uapi/* one with existing licensing information,
      
      Further patches will be generated in subsequent months to fix up cases
      where non-standard license headers were used, and references to license
      had to be inferred by heuristics based on keywords.
      
      The analysis to determine which SPDX License Identifier to be applied to
      a file was done in a spreadsheet of side by side results from of the
      output of two independent scanners (ScanCode & Windriver) producing SPDX
      tag:value files created by Philippe Ombredanne.  Philippe prepared the
      base worksheet, and did an initial spot review of a few 1000 files.
      
      The 4.13 kernel was the starting point of the analysis with 60,537 files
      assessed.  Kate Stewart did a file by file comparison of the scanner
      results in the spreadsheet to determine which SPDX license identifier(s)
      to be applied to the file. She confirmed any determination that was not
      immediately clear with lawyers working with the Linux Foundation.
      
      Criteria used to select files for SPDX license identifier tagging was:
       - Files considered eligible had to be source code files.
       - Make and config files were included as candidates if they contained >5
         lines of source
       - File already had some variant of a license header in it (even if <5
         lines).
      
      All documentation files were explicitly excluded.
      
      The following heuristics were used to determine which SPDX license
      identifiers to apply.
      
       - when both scanners couldn't find any license traces, file was
         considered to have no license information in it, and the top level
         COPYING file license applied.
      
         For non */uapi/* files that summary was:
      
         SPDX license identifier                            # files
         ---------------------------------------------------|-------
         GPL-2.0                                              11139
      
         and resulted in the first patch in this series.
      
         If that file was a */uapi/* path one, it was "GPL-2.0 WITH
         Linux-syscall-note" otherwise it was "GPL-2.0".  Results of that was:
      
         SPDX license identifier                            # files
         ---------------------------------------------------|-------
         GPL-2.0 WITH Linux-syscall-note                        930
      
         and resulted in the second patch in this series.
      
       - if a file had some form of licensing information in it, and was one
         of the */uapi/* ones, it was denoted with the Linux-syscall-note if
         any GPL family license was found in the file or had no licensing in
         it (per prior point).  Results summary:
      
         SPDX license identifier                            # files
         ---------------------------------------------------|------
         GPL-2.0 WITH Linux-syscall-note                       270
         GPL-2.0+ WITH Linux-syscall-note                      169
         ((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause)    21
         ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)    17
         LGPL-2.1+ WITH Linux-syscall-note                      15
         GPL-1.0+ WITH Linux-syscall-note                       14
         ((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause)    5
         LGPL-2.0+ WITH Linux-syscall-note                       4
         LGPL-2.1 WITH Linux-syscall-note                        3
         ((GPL-2.0 WITH Linux-syscall-note) OR MIT)              3
         ((GPL-2.0 WITH Linux-syscall-note) AND MIT)             1
      
         and that resulted in the third patch in this series.
      
       - when the two scanners agreed on the detected license(s), that became
         the concluded license(s).
      
       - when there was disagreement between the two scanners (one detected a
         license but the other didn't, or they both detected different
         licenses) a manual inspection of the file occurred.
      
       - In most cases a manual inspection of the information in the file
         resulted in a clear resolution of the license that should apply (and
         which scanner probably needed to revisit its heuristics).
      
       - When it was not immediately clear, the license identifier was
         confirmed with lawyers working with the Linux Foundation.
      
       - If there was any question as to the appropriate license identifier,
         the file was flagged for further research and to be revisited later
         in time.
      
      In total, over 70 hours of logged manual review was done on the
      spreadsheet to determine the SPDX license identifiers to apply to the
      source files by Kate, Philippe, Thomas and, in some cases, confirmation
      by lawyers working with the Linux Foundation.
      
      Kate also obtained a third independent scan of the 4.13 code base from
      FOSSology, and compared selected files where the other two scanners
      disagreed against that SPDX file, to see if there was new insights.  The
      Windriver scanner is based on an older version of FOSSology in part, so
      they are related.
      
      Thomas did random spot checks in about 500 files from the spreadsheets
      for the uapi headers and agreed with SPDX license identifier in the
      files he inspected. For the non-uapi files Thomas did random spot checks
      in about 15000 files.
      
      In initial set of patches against 4.14-rc6, 3 files were found to have
      copy/paste license identifier errors, and have been fixed to reflect the
      correct identifier.
      
      Additionally Philippe spent 10 hours this week doing a detailed manual
      inspection and review of the 12,461 patched files from the initial patch
      version early this week with:
       - a full scancode scan run, collecting the matched texts, detected
         license ids and scores
       - reviewing anything where there was a license detected (about 500+
         files) to ensure that the applied SPDX license was correct
       - reviewing anything where there was no detection but the patch license
         was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
         SPDX license was correct
      
      This produced a worksheet with 20 files needing minor correction.  This
      worksheet was then exported into 3 different .csv files for the
      different types of files to be modified.
      
      These .csv files were then reviewed by Greg.  Thomas wrote a script to
      parse the csv files and add the proper SPDX tag to the file, in the
      format that the file expected.  This script was further refined by Greg
      based on the output to detect more types of files automatically and to
      distinguish between header and source .c files (which need different
      comment types.)  Finally Greg ran the script using the .csv files to
      generate the patches.
      
      Reviewed-by: default avatarKate Stewart <kstewart@linuxfoundation.org>
      Reviewed-by: default avatarPhilippe Ombredanne <pombredanne@nexb.com>
      Reviewed-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b2441318
  9. Jun 20, 2016
    • Wolfram Sang's avatar
      kbuild: setlocalversion: print error to STDERR · 78283edf
      Wolfram Sang authored
      
      I tried to use 'make O=...' from an unclean source tree. This triggered
      the error path of setlocalversion. But by printing to STDOUT, it created
      a broken localversion which then caused another (unrelated) error:
      
      "4.7.0-rc2Error: kernelrelease not valid - run make prepare to update it" exceeds 64 characters
      
      After printing to STDERR, the true build error gets displayed later:
      
        /home/wsa/Kernel/linux is not clean, please run 'make mrproper'
        in the '/home/wsa/Kernel/linux' directory.
      
      Signed-off-by: default avatarWolfram Sang <wsa@the-dreams.de>
      Signed-off-by: default avatarMichal Marek <mmarek@suse.com>
      78283edf
  10. Jan 03, 2014
  11. Jun 24, 2013
    • Christian Kujau's avatar
      scripts/setlocalversion on write-protected source tree · cdf2bc63
      Christian Kujau authored
      I just stumbled across another[0] issue when scripts/setlocalversion
      operates on a write-protected source tree. Back then[0] the source tree
      was on an read-only NFS share, so "test -w" was introduced before "git
      update-index" was run.
      
      This time, the source tree is on read/write NFS share, but the permissions
      are world-readable and only a specific user (or root) can write.
      Thus, "test -w ." returns "0" and then runs "git update-index",
      producing the following message (on a dirty tree):
      
        fatal: Unable to create '/usr/local/src/linux-git/.git/index.lock': Permission denied
      
      While it says "fatal", compilation continues just fine.
      
      However, I don't think a kernel compilation should alter the source
      tree (or the .git directory) in any way and I don't see how removing
      "git update-index" could do any harm. The Mercurial and SVN routines in
      scripts/setlocalversion don't have any tree-modifying commands, AFAICS.
      So, maybe the patch below would be acceptable.
      
      [0] https://patchwork.kernel.org/patch/29718/
      
      
      
      Signed-off-by: default avatarChristian Kujau <lists@nerdbynature.de>
      Cc: Nico Schottelius <nico-linuxsetlocalversion@schottelius.org>
      Signed-off-by: default avatarMichal Marek <mmarek@suse.cz>
      cdf2bc63
  12. Feb 22, 2013
  13. Mar 26, 2012
  14. Jan 15, 2011
  15. Sep 06, 2010
  16. Aug 21, 2010
    • Michal Marek's avatar
      setlocalversion: Ignote SCMs above the linux source tree · 8558f59e
      Michal Marek authored
      
      Dan McGee <dpmcgee@gmail.com> writes:
      > Note that when in git, you get the appended "+" sign. If
      > LOCALVERSION_AUTO is set, you will get something like
      > "eee-gb01b08c-dirty" (whereas the copy of the tree in /tmp still
      > returns "eee"). It doesn't matter whether the working tree is dirty or
      > clean.
      >
      > Is there a way to disable this? I'm building from a clean tarball that
      > just happens to be unpacked inside a git repository. One would think
      > setting LOCALVERSION_AUTO to false would do it, but no such luck...
      
      Fix this by checking if the kernel source tree is the root of the git or
      hg repository. No fix for svn: If the kernel source is not tracked in
      the svn repository, it works as expected, otherwise determining the
      'repository root' is not really a defined task.
      
      Reported-and-tested-by: default avatarDan McGee <dpmcgee@gmail.com>
      Signed-off-by: default avatarMichal Marek <mmarek@suse.cz>
      8558f59e
  17. Aug 13, 2010
  18. Jul 21, 2010
  19. Jul 20, 2010
    • Michał Górny's avatar
      kbuild: Make the setlocalversion script POSIX-compliant · 6dc0c2f3
      Michał Górny authored
      
      The 'source' builtin is a bash alias to the '.' (dot) builtin. While the
      former is supported only by bash, the latter is specified in POSIX and
      works fine with all POSIX-compliant shells I am aware of.
      
      The '$_' special parameter is specific to bash. It is partially
      supported in dash too but it always evaluates to the current script path
      (which causes the script to enter a loop recursively re-executing
      itself). This is why I have replaced the two occurences of '$_' with the
      explicit parameter.
      
      The 'local' builtin is another example of bash-specific code. Although
      it is supported by all POSIX-compliant shells I am aware of, it is not
      part of POSIX specification and thus the code should not rely on it
      assigning a specific value to the local variable. Moreover, the 'posh'
      shell has a limited version of 'local' builtin not supporting direct
      variable assignments. Thus, I have broken one of the 'local'
      declarations down into a (non-POSIX) 'local' declaration and a plain
      (POSIX-compliant) variable assignment.
      
      Signed-off-by: default avatarMichał Górny <gentoo@mgorny.alt.pl>
      Signed-off-by: default avatarMichal Marek <mmarek@suse.cz>
      6dc0c2f3
  20. Jun 18, 2010
    • Michal Marek's avatar
      kbuild: Clean up and speed up the localversion logic · 09155120
      Michal Marek authored
      
      Now that we run scripts/setlocalversion during every build, it makes
      sense to move all the localversion logic there. This cleans up the
      toplevel Makefile and also makes sure that the script is called only
      once in 'make prepare' (previously, it would be called every time due to
      a variable expansion in an ifneq statement). No user-visible change is
      intended, unless one runs the setlocalversion script directly.
      
      Reported-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
      Cc: David Rientjes <rientjes@google.com>
      Cc: Greg Thelen <gthelen@google.com>
      Cc: Nico Schottelius <nico-linuxsetlocalversion@schottelius.org>
      Signed-off-by: default avatarMichal Marek <mmarek@suse.cz>
      09155120
  21. Jun 14, 2009
  22. May 19, 2009
  23. May 01, 2009
  24. Apr 11, 2009
  25. Feb 15, 2009
  26. Dec 03, 2008
  27. Oct 29, 2008
  28. Jul 25, 2008
  29. Feb 03, 2008
  30. Jan 28, 2008
  31. Jun 17, 2006
  32. Jan 08, 2006
  33. Jan 06, 2006
    • Rene Scharfe's avatar
      kbuild: Use git in scripts/setlocalversion · 117a93db
      Rene Scharfe authored
      
      Currently scripts/setlocalversion is a Perl script that tries to figure
      out the current git commit ID of a repo without using git.  It also
      imports Digest::MD5 without using it and generally is too big for the
      small task it does. :]  And it always reports a git ID, even when the
      HEAD is tagged -- this is a bug.
      
      This patch replaces it with a Bourne Shell script that uses git
      commands to do the same.  I can't come up with a scenario where someone
      would use a git repo and refuse to install git core at the same time,
      so I think it's reasonable to assume git is available.
      
      The new script also reports uncommitted changes by adding -git_dirty to
      the version string.  Obviously you can't see from that _what_ has been
      changed from the last commit, so it's more of a reminder that you
      forgot to commit something.
      
      The script is easily extensible: simply add a check for Mercurial (or
      whatever) below the git check.
      
      Note: the script doesn't print a newline char anymore.  That's only
      because it was easier to implement it that way, not a feature (or bug).
      'make kernelrelease' doesn't care.
      
      Signed-off-by: default avatarRene Scharfe <rene.scharfe@lsrfire.ath.cx>
      Acked-by: default avatarRyan Anderson <ryan@michonline.com>
      Signed-off-by: default avatarSam Ravnborg <sam@ravnborg.org>
      117a93db
  34. Aug 10, 2005
Loading