Merge ~raharper/curtin:fix-tools-build-package into curtin:master

Proposed by Ryan Harper
Status: Merged
Merged at revision: c5cb03e197f0a5066188530f50b2c6c1f15a904a
Proposed branch: ~raharper/curtin:fix-tools-build-package
Merge into: curtin:master
Diff against target: 366 lines (+199/-91)
6 files modified
.gitignore (+12/-0)
debian/changelog.trunk (+1/-1)
dev/null (+0/-61)
tools/build-deb (+14/-29)
tools/make-tarball (+63/-0)
tools/read-version (+109/-0)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Needs Fixing
curtin developers Pending
Review via email: mp+335427@code.launchpad.net

Description of the change

Fix tools/build-deb

- Import some tools from cloud-init
  - tools/read-version
    - Updated to mention curtin instead
    - Added --shell which emits key=value pairs
    - Added --long which emits just the version_long value
  - tools/make-tarball
    - Updated to mention/use curtin instead
- Removed tools/export-tarball
- debian/changelog.trunk
  - Modified for easier replacement for the version string
- Removed all of the bzr command and revision parsing logic
  and now use read-version to extract the long and short
  version values and feed them to make-tarball

This now works and writes out debs like:
     curtin_17.1-2-g757848bf-1~bddeb_all.deb
     curtin-common_17.1-2-g757848bf-1~bddeb_all.deb
     python3-curtin_17.1-2-g757848bf-1~bddeb_all.deb
     python-curtin_17.1-2-g757848bf-1~bddeb_all.deb

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Scott Moser (smoser) wrote :

talked with ryan, the mp that i had up did the same basic thing as this.
took some input on it and merged in 8108efbd9377 and c5cb03e197f0

calling this MP 'merged'.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/.gitignore b/.gitignore
2new file mode 100644
3index 0000000..7f909cf
4--- /dev/null
5+++ b/.gitignore
6@@ -0,0 +1,12 @@
7+build
8+curtin.egg-info
9+dist
10+*.pyc
11+__pycache__
12+.tox
13+.coverage
14+doc/rtd_html
15+parts
16+prime
17+stage
18+*.snap
19diff --git a/debian/changelog.trunk b/debian/changelog.trunk
20index ec1e294..c8c6e08 100644
21--- a/debian/changelog.trunk
22+++ b/debian/changelog.trunk
23@@ -1,4 +1,4 @@
24-curtin (17.1~bzrREVNO-0ubuntu1) UNRELEASED; urgency=low
25+curtin (VERSION_LONG-1~bddeb) UNRELEASED; urgency=low
26
27 * Initial release
28
29diff --git a/tools/build-deb b/tools/build-deb
30index 685473b..68d77c8 100755
31--- a/tools/build-deb
32+++ b/tools/build-deb
33@@ -38,46 +38,31 @@ top_d=$(cd "$(dirname "${0}")"/.. && pwd)
34 # resulting in something like: 0.1.0~bzrREVNO-1~trunk1
35 clogver_o=$(sed -n '1s,.*(\([^)]*\)).*,\1,p' debian/changelog.trunk)
36
37-revno=$(bzr revno) || fail "failed to get revno"
38-clogver_upstream=${clogver_o%%-*}
39-clogver_debian=${clogver_o#*-}
40-
41-# uver_bzr gets 17.1~bzr<revno>
42-uver_bzr=$(echo "${clogver_upstream}" | sed "s,REVNO,$revno,")
43-# uver_rel gets '17.1'
44-uver_rel=$(echo "${clogver_upstream}" | sed 's,~bzrREVNO,,')
45-
46-tag_revno=$(bzr tags | awk '$1 == v { print $2 }' v="${uver_rel}")
47-if [ "${tag_revno}" = "$revno" ]; then
48- # if this is a tag, then drop ~bzrXXX from the changelog version.
49- echo "Building a tag of upstream version ($uver_rel -> $revno)" 1>&2
50- clogver_new="${uver}-${clogver_debian}"
51- uver="${uver_rel}"
52- export_string="tag:${uver_rel}"
53-else
54- uver="${uver_bzr}"
55- export_string="$revno"
56-fi
57-clogver_new="${uver}-${clogver_debian}"
58+
59+revno=$(git describe --abbrev=8 --match=[0-9]*) || fail "failed to get revno"
60+version_long=$(./tools/read-version --long)
61+version_short=$(./tools/read-version)
62+
63+
64
65 TEMP_D=$(mktemp -d "${TMPDIR:-/tmp}/${bname}.XXXXXX")
66
67 trap cleanup EXIT
68
69-echo "building upstream version $uver, debian ver=${clogver_debian}"
70+echo "building upstream version $version_long, debian ver=${version_short}"
71
72-dir="${sourcename}-$uver"
73-tarball="${sourcename}_$uver.orig.tar.gz"
74+dir="${sourcename}-$version_long"
75+tarball="${sourcename}_$version_long.orig.tar.gz"
76
77 myd=$(dirname "$0")
78-"$myd/export-tarball" "${export_string}" "${TEMP_D}/$tarball"
79+"$myd/make-tarball" --long "${version_long}" --output="${TEMP_D}/$tarball"
80 echo "created ${tarball}"
81
82 cd "${TEMP_D}"
83 tar xzf "$tarball" || fail "failed extract tarball"
84
85 if [ ! -d "$dir" ]; then
86- # export-tarball will create the directory name based on the
87+ # make-tarball will create the directory name based on the
88 # contents of debian/changelog.trunk in the version provided.
89 # if that differs from what is here, then user has changes.
90 for d in ${sourcename}*; do
91@@ -85,13 +70,13 @@ if [ ! -d "$dir" ]; then
92 done
93 if [ -d "$d" ]; then
94 {
95- echo "WARNING: bzr at '${export_string}' had different version"
96+ echo "WARNING: git at '${export_string}' had different version"
97 echo " in debian/changelog.trunk than your tree. version there"
98 echo " is '$d' working directory had $uver"
99 } 1>&2
100 dir=$d
101 else
102- echo "did not find a directory created by export-tarball. sorry." 1>&2
103+ echo "did not find a directory created by make-tarball. sorry." 1>&2
104 exit
105 fi
106 fi
107@@ -106,7 +91,7 @@ done
108 # first line of debian/changelog looks like
109 # curtin (<version>) UNRELEASED; urgency=low
110 # fix the version and UNRELEASED
111-sed -i -e "1s,([^)]*),(${clogver_new})," \
112+sed -i -e "1s,VERSION_LONG,${version_long}," \
113 -e "1s,UNRELEASED,${RELEASE}," debian/changelog ||
114 fail "failed to write debian/changelog"
115 debuild "$@" || fail "debuild failed"
116diff --git a/tools/export-tarball b/tools/export-tarball
117deleted file mode 100755
118index 1b9c17d..0000000
119--- a/tools/export-tarball
120+++ /dev/null
121@@ -1,61 +0,0 @@
122-#!/bin/sh
123-
124-set -e
125-sourcename="curtin"
126-
127-Usage() {
128- cat <<EOF
129-Usage: [revno [output.tar.gz]]
130-
131- Create a tarball of revno (or tag) in output.tar.gz
132- revno defaults to \`bzr revno\`.
133- output filename defaults to:
134- curtin-X.Y~bzrREVNO.tar.gz
135- or, if a tag is given:
136- curtin-TAG.tar.gz
137-
138- if UNCOMMITTED is set to non '0' in environment
139- then uncommitted changes will be kept in the tarball.
140-EOF
141-}
142-
143-TEMP_D=""
144-fail() { echo "$@" 1>&2; exit 1; }
145-cleanup() {
146- [ -z "$TEMP_D" ] || rm -Rf "$TEMP_D"
147-}
148-
149-export_uncommitted=""
150-if [ "${UNCOMMITTED:-0}" != "0" ]; then
151- export_uncommitted="--uncommitted"
152-fi
153-
154-[ "$1" = "-h" -o "$1" = "--help" ] && { Usage; exit 0; }
155-
156-TEMP_D=$(mktemp -d)
157-trap cleanup EXIT
158-
159-case "${1:-HEAD}" in
160- tag:*) version="${1#tag:}";;
161- HEAD) revno="$(bzr revno)"; revargs="-r $revno";;
162- [0-9]*) revno="$1" ; revargs="-r $1";;
163-esac
164-output="$2"
165-
166-if [ -z "$version" ]; then
167- bzr cat $revargs debian/changelog.trunk > "$TEMP_D/clog" ||
168- fail "failed to extract debian/change.log.trunk at $revargs"
169-
170- clogver_o=$(sed -n '1s,.*(\([^)]*\)).*,\1,p' $TEMP_D/clog)
171- clogver_upstream=${clogver_o%%-*}
172- mmm=${clogver_o%%~*}
173- version="$mmm~bzr$revno"
174-fi
175-
176-if [ -z "$output" ]; then
177- output="$sourcename-$version.tar.gz"
178-fi
179-
180-bzr export ${export_uncommitted} \
181- --format=tgz --root="$sourcename-${version}" $revargs $output
182-echo "wrote $output"
183diff --git a/tools/make-tarball b/tools/make-tarball
184new file mode 100755
185index 0000000..60ede68
186--- /dev/null
187+++ b/tools/make-tarball
188@@ -0,0 +1,63 @@
189+#!/bin/sh
190+set -e
191+
192+TEMP_D=""
193+cleanup() {
194+ [ -z "$TEMP_D" ] || rm -Rf "${TEMP_D}"
195+}
196+trap cleanup EXIT
197+
198+Usage() {
199+ cat <<EOF
200+Usage: ${0##*/} [revision]
201+ create a tarball of revision (default HEAD)
202+
203+ options:
204+ -o | --output FILE write to file
205+EOF
206+}
207+
208+short_opts="ho:v"
209+long_opts="help,output:,long,verbose"
210+getopt_out=$(getopt --name "${0##*/}" \
211+ --options "${short_opts}" --long "${long_opts}" -- "$@") &&
212+ eval set -- "${getopt_out}" || { Usage 1>&2; exit 1; }
213+
214+long_opt=""
215+while [ $# -ne 0 ]; do
216+ cur=$1; next=$2
217+ case "$cur" in
218+ -o|--output) output=$next; shift;;
219+ --long) long_opt="--long";;
220+ --) shift; break;;
221+ esac
222+ shift;
223+done
224+
225+rev=${1:-HEAD}
226+version=$(git describe --abbrev=8 "--match=[0-9]*" ${long_opt} $rev)
227+
228+archive_base="curtin-$version"
229+if [ -z "$output" ]; then
230+ output="$archive_base.tar.gz"
231+fi
232+
233+# when building an archiving from HEAD, ensure that there aren't any
234+# uncomitted changes in the working directory (because these would not
235+# end up in the archive).
236+if [ "$rev" = HEAD ] && ! git diff-index --quiet HEAD --; then
237+ if [ -z "$SKIP_UNCOMITTED_CHANGES_CHECK" ]; then
238+ echo "ERROR: There are uncommitted changes in your working directory." >&2
239+ exit 1
240+ else
241+ echo "WARNING: There are uncommitted changes in your working directory." >&2
242+ echo " This changes will not be included in the archive." >&2
243+ fi
244+fi
245+
246+TEMP_D=$(mktemp -d)
247+tar=${output##*/}
248+tar="$TEMP_D/${tar%.gz}"
249+git archive --format=tar --prefix="$archive_base/" "$rev" > "$tar"
250+gzip -9 -c "$tar" > "$output"
251+echo "$output"
252diff --git a/tools/read-version b/tools/read-version
253new file mode 100755
254index 0000000..8ad89d2
255--- /dev/null
256+++ b/tools/read-version
257@@ -0,0 +1,109 @@
258+#!/usr/bin/env python
259+
260+import os
261+import json
262+import subprocess
263+import sys
264+
265+if "avoid-pep8-E402-import-not-top-of-file":
266+ _tdir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
267+ sys.path.insert(0, _tdir)
268+ from curtin import version as ci_version
269+
270+
271+def tiny_p(cmd, capture=True):
272+ # python 2.6 doesn't have check_output
273+ stdout = subprocess.PIPE
274+ stderr = subprocess.PIPE
275+ sp = subprocess.Popen(cmd, stdout=stdout,
276+ stderr=stderr, stdin=None,
277+ universal_newlines=True)
278+ (out, err) = sp.communicate()
279+ ret = sp.returncode
280+ if ret not in [0]:
281+ raise RuntimeError("Failed running %s [rc=%s] (%s, %s)" %
282+ (cmd, ret, out, err))
283+ return out
284+
285+
286+def which(program):
287+ # Return path of program for execution if found in path
288+ def is_exe(fpath):
289+ return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
290+
291+ _fpath, _ = os.path.split(program)
292+ if _fpath:
293+ if is_exe(program):
294+ return program
295+ else:
296+ for path in os.environ.get("PATH", "").split(os.pathsep):
297+ path = path.strip('"')
298+ exe_file = os.path.join(path, program)
299+ if is_exe(exe_file):
300+ return exe_file
301+
302+ return None
303+
304+
305+use_long = '--long' in sys.argv or os.environ.get('CI_RV_LONG')
306+use_tags = '--tags' in sys.argv or os.environ.get('CI_RV_TAGS')
307+output_json = '--json' in sys.argv
308+output_shell = '--shell' in sys.argv
309+
310+src_version = ci_version.version_string()
311+version_long = None
312+
313+if os.path.isdir(os.path.join(_tdir, ".git")) and which("git"):
314+ flags = []
315+ if use_tags:
316+ flags = ['--tags']
317+ cmd = ['git', 'describe', '--abbrev=8', '--match=[0-9]*'] + flags
318+
319+ version = tiny_p(cmd).strip()
320+
321+ if not version.startswith(src_version):
322+ sys.stderr.write("git describe version (%s) differs from "
323+ "curtin.version (%s)\n" % (version, src_version))
324+ sys.exit(1)
325+
326+ version_long = tiny_p(cmd + ["--long"]).strip()
327+else:
328+ version = src_version
329+ version_long = None
330+
331+# version is X.Y.Z[+xxx.gHASH]
332+# version_long is None or X.Y.Z-xxx-gHASH
333+release = version.partition("-")[0]
334+extra = None
335+commit = None
336+distance = None
337+
338+if version_long:
339+ info = version_long.partition("-")[2]
340+ extra = "-" + info
341+ distance, commit = info.split("-")
342+ # remove the 'g' from gHASH
343+ commit = commit[1:]
344+
345+data = {
346+ 'release': release,
347+ 'version': version,
348+ 'version_long': version_long,
349+ 'extra': extra,
350+ 'commit': commit,
351+ 'distance': distance,
352+}
353+
354+if output_json:
355+ sys.stdout.write(json.dumps(data, indent=1) + "\n")
356+elif output_shell:
357+ for (k, v) in data.items():
358+ sys.stdout.write('%s="%s"\n' % (k, v))
359+elif use_long:
360+ sys.stdout.write(data['version_long'] + "\n")
361+else:
362+ sys.stdout.write(release + "\n")
363+
364+sys.exit(0)
365+
366+# vi: ts=4 expandtab

Subscribers

People subscribed via source and target branches