~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/scripts/setlocalversion

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /scripts/setlocalversion (Version linux-6.12-rc7) and /scripts/setlocalversion (Version linux-6.2.16)


  1 #!/bin/sh                                           1 #!/bin/sh
  2 # SPDX-License-Identifier: GPL-2.0                  2 # SPDX-License-Identifier: GPL-2.0
  3 #                                                   3 #
  4 # This scripts adds local version information       4 # This scripts adds local version information from the version
  5 # control system git.                          !!   5 # control systems git, mercurial (hg) and subversion (svn).
  6 #                                                   6 #
  7 # If something goes wrong, send a mail the ker      7 # If something goes wrong, send a mail the kernel build mailinglist
  8 # (see MAINTAINERS) and CC Nico Schottelius         8 # (see MAINTAINERS) and CC Nico Schottelius
  9 # <nico-linuxsetlocalversion -at- schottelius.      9 # <nico-linuxsetlocalversion -at- schottelius.org>.
 10 #                                                  10 #
 11 #                                                  11 #
 12                                                    12 
 13 usage() {                                          13 usage() {
 14         echo "Usage: $0 [--no-local] [srctree] !!  14         echo "Usage: $0 [--save-scmversion] [srctree]" >&2
 15         exit 1                                     15         exit 1
 16 }                                                  16 }
 17                                                    17 
 18 no_local=false                                 !!  18 scm_only=false
 19 if test "$1" = "--no-local"; then              !!  19 srctree=.
 20         no_local=true                          !!  20 if test "$1" = "--save-scmversion"; then
                                                   >>  21         scm_only=true
 21         shift                                      22         shift
 22 fi                                                 23 fi
 23                                                << 
 24 srctree=.                                      << 
 25 if test $# -gt 0; then                             24 if test $# -gt 0; then
 26         srctree=$1                                 25         srctree=$1
 27         shift                                      26         shift
 28 fi                                                 27 fi
 29 if test $# -gt 0 -o ! -d "$srctree"; then          28 if test $# -gt 0 -o ! -d "$srctree"; then
 30         usage                                      29         usage
 31 fi                                                 30 fi
 32                                                    31 
 33 scm_version()                                      32 scm_version()
 34 {                                                  33 {
 35         local short=false                      !!  34         local short
 36         local no_dirty=false                   !!  35         short=false
 37         local tag                              << 
 38                                                << 
 39         while [ $# -gt 0 ];                    << 
 40         do                                     << 
 41                 case "$1" in                   << 
 42                 --short)                       << 
 43                         short=true;;           << 
 44                 --no-dirty)                    << 
 45                         no_dirty=true;;        << 
 46                 esac                           << 
 47                 shift                          << 
 48         done                                   << 
 49                                                    36 
 50         cd "$srctree"                              37         cd "$srctree"
 51                                                !!  38         if test -e .scmversion; then
 52         if test -n "$(git rev-parse --show-cdu !!  39                 cat .scmversion
 53                 return                         << 
 54         fi                                     << 
 55                                                << 
 56         if ! head=$(git rev-parse --verify HEA << 
 57                 return                             40                 return
 58         fi                                         41         fi
 59                                                !!  42         if test "$1" = "--short"; then
 60         # mainline kernel:  6.2.0-rc5  ->  v6. !!  43                 short=true
 61         # stable kernel:    6.1.7      ->  v6. << 
 62         version_tag=v$(echo "${KERNELVERSION}" << 
 63                                                << 
 64         # If a localversion* file exists, and  << 
 65         # annotated tag exists and is an ances << 
 66         # it. This is the case in linux-next.  << 
 67         tag=${file_localversion#-}             << 
 68         desc=                                  << 
 69         if [ -n "${tag}" ]; then               << 
 70                 desc=$(git describe --match=$t << 
 71         fi                                     << 
 72                                                << 
 73         # Otherwise, if a localversion* file e << 
 74         # obtained by appending it to the tag  << 
 75         # KERNELVERSION exists and is an ances << 
 76         # it. This is e.g. the case in linux-r << 
 77         if [ -z "${desc}" ] && [ -n "${file_lo << 
 78                 tag="${version_tag}${file_loca << 
 79                 desc=$(git describe --match=$t << 
 80         fi                                         44         fi
 81                                                    45 
 82         # Otherwise, default to the annotated  !!  46         # Check for git and a git repo.
 83         if [ -z "${desc}" ]; then              !!  47         if test -z "$(git rev-parse --show-cdup 2>/dev/null)" &&
 84                 tag="${version_tag}"           !!  48            head=$(git rev-parse --verify HEAD 2>/dev/null); then
 85                 desc=$(git describe --match=$t !!  49 
 86         fi                                     !!  50                 # If we are at a tagged commit (like "v2.6.30-rc6"), we ignore
                                                   >>  51                 # it, because this version is defined in the top level Makefile.
                                                   >>  52                 if [ -z "$(git describe --exact-match 2>/dev/null)" ]; then
                                                   >>  53 
                                                   >>  54                         # If only the short version is requested, don't bother
                                                   >>  55                         # running further git commands
                                                   >>  56                         if $short; then
                                                   >>  57                                 echo "+"
                                                   >>  58                                 return
                                                   >>  59                         fi
                                                   >>  60                         # If we are past a tagged commit (like
                                                   >>  61                         # "v2.6.30-rc5-302-g72357d5"), we pretty print it.
                                                   >>  62                         if atag="$(git describe 2>/dev/null)"; then
                                                   >>  63                                 echo "$atag" | awk -F- '{printf("-%05d", $(NF-1))}'
                                                   >>  64                         fi
 87                                                    65 
 88         # If we are at the tagged commit, we i !!  66                         # Add -g and exactly 12 hex chars.
 89         # well-defined.                        !!  67                         printf '%s%s' -g "$(echo $head | cut -c1-12)"
 90         if [ "${tag}" != "${desc}" ]; then     << 
 91                                                << 
 92                 # If only the short version is << 
 93                 # running further git commands << 
 94                 if $short; then                << 
 95                         echo "+"               << 
 96                         return                 << 
 97                 fi                             << 
 98                 # If we are past the tagged co << 
 99                 # (like 6.1.0-14595-g292a089d7 << 
100                 if [ -n "${desc}" ]; then      << 
101                         echo "${desc}" | awk - << 
102                 fi                                 68                 fi
103                                                    69 
104                 # Add -g and exactly 12 hex ch !!  70                 # Check for uncommitted changes.
105                 printf '%s%s' -g "$(echo $head !!  71                 # This script must avoid any write attempt to the source tree,
106         fi                                     !!  72                 # which might be read-only.
107                                                !!  73                 # You cannot use 'git describe --dirty' because it tries to
108         if ${no_dirty}; then                   !!  74                 # create .git/index.lock .
109                 return                         !!  75                 # First, with git-status, but --no-optional-locks is only
110         fi                                     !!  76                 # supported in git >= 2.14, so fall back to git-diff-index if
111                                                !!  77                 # it fails. Note that git-diff-index does not refresh the
112         # Check for uncommitted changes.       !!  78                 # index, so it may give misleading results. See
113         # This script must avoid any write att !!  79                 # git-update-index(1), git-diff-index(1), and git-status(1).
114         # might be read-only.                  !!  80                 if {
115         # You cannot use 'git describe --dirty !!  81                         git --no-optional-locks status -uno --porcelain 2>/dev/null ||
116         # .git/index.lock .                    !!  82                         git diff-index --name-only HEAD
117         # First, with git-status, but --no-opt !!  83                 } | read dummy; then
118         # git >= 2.14, so fall back to git-dif !!  84                         printf '%s' -dirty
119         # git-diff-index does not refresh the  !!  85                 fi
120         # results.                             << 
121         # See git-update-index(1), git-diff-in << 
122         if {                                   << 
123                 git --no-optional-locks status << 
124                 git diff-index --name-only HEA << 
125         } | read dummy; then                   << 
126                 printf '%s' -dirty             << 
127         fi                                         86         fi
128 }                                                  87 }
129                                                    88 
130 collect_files()                                    89 collect_files()
131 {                                                  90 {
132         local file res=                            91         local file res=
133                                                    92 
134         for file; do                               93         for file; do
135                 case "$file" in                    94                 case "$file" in
136                 *\~*)                              95                 *\~*)
137                         continue                   96                         continue
138                         ;;                         97                         ;;
139                 esac                               98                 esac
140                 if test -e "$file"; then           99                 if test -e "$file"; then
141                         res="$res$(cat "$file"    100                         res="$res$(cat "$file")"
142                 fi                                101                 fi
143         done                                      102         done
144         echo "$res"                               103         echo "$res"
145 }                                                 104 }
146                                                   105 
147 if [ -z "${KERNELVERSION}" ]; then             !! 106 if $scm_only; then
148         echo "KERNELVERSION is not set" >&2    !! 107         if test ! -e .scmversion; then
149         exit 1                                 !! 108                 res=$(scm_version)
150 fi                                             !! 109                 echo "$res" >.scmversion
151                                                !! 110         fi
152 # localversion* files in the build and source  !! 111         exit
153 file_localversion="$(collect_files localversio << 
154 if test ! "$srctree" -ef .; then               << 
155         file_localversion="${file_localversion << 
156 fi                                             << 
157                                                << 
158 if ${no_local}; then                           << 
159         echo "${KERNELVERSION}$(scm_version -- << 
160         exit 0                                 << 
161 fi                                                112 fi
162                                                   113 
163 if ! test -e include/config/auto.conf; then       114 if ! test -e include/config/auto.conf; then
164         echo "Error: kernelrelease not valid -    115         echo "Error: kernelrelease not valid - run 'make prepare' to update it" >&2
165         exit 1                                    116         exit 1
166 fi                                                117 fi
167                                                   118 
168 # version string from CONFIG_LOCALVERSION      !! 119 # localversion* files in the build and source directory
                                                   >> 120 res="$(collect_files localversion*)"
                                                   >> 121 if test ! "$srctree" -ef .; then
                                                   >> 122         res="$res$(collect_files "$srctree"/localversion*)"
                                                   >> 123 fi
                                                   >> 124 
                                                   >> 125 # CONFIG_LOCALVERSION and LOCALVERSION (if set)
169 config_localversion=$(sed -n 's/^CONFIG_LOCALV    126 config_localversion=$(sed -n 's/^CONFIG_LOCALVERSION=\(.*\)$/\1/p' include/config/auto.conf)
                                                   >> 127 res="${res}${config_localversion}${LOCALVERSION}"
170                                                   128 
171 # scm version string if not at the kernel vers !! 129 # scm version string if not at a tagged commit
172 if grep -q "^CONFIG_LOCALVERSION_AUTO=y$" incl    130 if grep -q "^CONFIG_LOCALVERSION_AUTO=y$" include/config/auto.conf; then
173         # full scm version string                 131         # full scm version string
174         scm_version="$(scm_version)"           !! 132         res="$res$(scm_version)"
175 elif [ "${LOCALVERSION+set}" != "set" ]; then     133 elif [ "${LOCALVERSION+set}" != "set" ]; then
176         # If the variable LOCALVERSION is not     134         # If the variable LOCALVERSION is not set, append a plus
177         # sign if the repository is not in a c    135         # sign if the repository is not in a clean annotated or
178         # signed tagged state (as git describe    136         # signed tagged state (as git describe only looks at signed
179         # or annotated tags - git tag -a/-s).     137         # or annotated tags - git tag -a/-s).
180         #                                         138         #
181         # If the variable LOCALVERSION is set     139         # If the variable LOCALVERSION is set (including being set
182         # to an empty string), we don't want t    140         # to an empty string), we don't want to append a plus sign.
183         scm_version="$(scm_version --short)"   !! 141         scm=$(scm_version --short)
                                                   >> 142         res="$res${scm:++}"
184 fi                                                143 fi
185                                                   144 
186 echo "${KERNELVERSION}${file_localversion}${co !! 145 echo "$res"
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php