From a7e13e1f540019170de0f4fb0e008b703226df77 Mon Sep 17 00:00:00 2001
From: Joshua Harlow <harlowja@yahoo-inc.com>
Date: Mon, 9 Jul 2012 15:49:06 -0400
Subject: include ~bzr in make-tarball output tarball and top level dir

output of 'make-tarball' now is tarball with name formatted as:
    cloud-init-$VERSION~bzr$REVNO.tar.gz
Instead of
    cloud-init-$VERSION-$REVNO.tar.gz

The former is desireable for apt at least as the '~' is understood
to mean less than.

This merges revno 569 and 570 from lp:~harlowja/cloud-init/rework
---
 packages/brpm                   | 17 ++++++++++++-----
 packages/redhat/cloud-init.spec |  2 +-
 tools/make-tarball              |  4 ++--
 3 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/packages/brpm b/packages/brpm
index 99288ce9..4a9cdcf3 100755
--- a/packages/brpm
+++ b/packages/brpm
@@ -43,6 +43,8 @@ PKG_MP = {
     'argparse': 'python-argparse'
 }
 
+RPM_BUILD_SUBDIRS = ['BUILD', 'RPMS', 'SOURCES', 'SPECS', 'SRPMS']
+
 
 def get_log_header(version):
     # Try to find the version in the tags output
@@ -88,7 +90,7 @@ def format_change_line(ds, who, comment=None):
     return "* %s" % (d)
 
 
-def generate_spec_contents(args, tmpl_fn):
+def generate_spec_contents(args, tmpl_fn, arc_fn):
 
     # Figure out the version and revno
     cmd = [util.abs_join(find_root(), 'tools', 'read-version')]
@@ -103,8 +105,8 @@ def generate_spec_contents(args, tmpl_fn):
     subs = {}
     subs['version'] = version
     subs['revno'] = revno
-    subs['release'] = revno
-    subs['archive_name'] = '%{name}-%{version}-' + revno + '.tar.gz'
+    subs['release'] = "bzr%s" % (revno)
+    subs['archive_name'] = arc_fn
     subs['bd_requires'] = ['python-devel', 'python-setuptools']
 
     cmd = [util.abs_join(find_root(), 'tools', 'read-dependencies')]
@@ -177,8 +179,13 @@ def main():
     root_dir = os.path.expanduser("~/rpmbuild")
     if os.path.isdir(root_dir):
         shutil.rmtree(root_dir)
+
     arc_dir = util.abs_join(root_dir, 'SOURCES')
-    util.ensure_dirs([root_dir, arc_dir])
+    build_dirs = [root_dir, arc_dir]
+    for dname in RPM_BUILD_SUBDIRS:
+        build_dirs.append(util.abs_join(root_dir, dname))
+    build_dirs.sort()
+    util.ensure_dirs(build_dirs)
 
     # Archive the code
     cmd = [util.abs_join(find_root(), 'tools', 'make-tarball')]
@@ -189,7 +196,7 @@ def main():
 
     # Form the spec file to be used
     tmpl_fn = util.abs_join(find_root(), 'packages', 'redhat', 'cloud-init.spec')
-    contents = generate_spec_contents(args, tmpl_fn)
+    contents = generate_spec_contents(args, tmpl_fn, os.path.basename(archive_fn))
     spec_fn = util.abs_join(root_dir, 'cloud-init.spec')
     util.write_file(spec_fn, contents)
 
diff --git a/packages/redhat/cloud-init.spec b/packages/redhat/cloud-init.spec
index a9da7c5e..5dfb6b0d 100644
--- a/packages/redhat/cloud-init.spec
+++ b/packages/redhat/cloud-init.spec
@@ -54,7 +54,7 @@ need special scripts to run during initialization to retrieve and install
 ssh keys and to let the user run various scripts.
 
 %prep
-%setup -q -n %{name}-%{version}-{{revno}}
+%setup -q -n %{name}-%{version}~{{release}}
 
 %build
 %{__python} setup.py build
diff --git a/tools/make-tarball b/tools/make-tarball
index 09742dc7..47979f5b 100755
--- a/tools/make-tarball
+++ b/tools/make-tarball
@@ -23,13 +23,13 @@ if [ ! -z "$1" ]; then
 else
     REVNO=$(bzr revno $ROOT_DIR)
     VERSION=$($ROOT_DIR/tools/read-version)
-    ARCHIVE_FN="$PWD/cloud-init-$VERSION-$REVNO.tar.gz"
+    ARCHIVE_FN="$PWD/cloud-init-$VERSION~bzr$REVNO.tar.gz"
 fi
 
 FILES=$(cd $ROOT_DIR && bzr ls --versioned --recursive)
 echo "$FILES" | tar czf $ARCHIVE_FN \
                 -C "$ROOT_DIR" \
-                --transform "s,^,cloud-init-$VERSION-$REVNO/," \
+                --transform "s,^,cloud-init-$VERSION~bzr$REVNO/," \
                 --no-recursion --files-from -
 
 echo "$ARCHIVE_FN"
-- 
cgit v1.2.3