public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
To: Nicolas Morey-Chaisemartin
	<NMoreyChaisemartin-l3A5Bk7waGM@public.gmane.org>
Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH rdma-core 3/3] cbuild: use rpmspec for macro replacement
Date: Tue, 8 Aug 2017 17:04:59 -0600	[thread overview]
Message-ID: <20170808230459.GF29372@obsidianresearch.com> (raw)
In-Reply-To: <8ad0438f-b4a5-aec9-1e44-a9c9dc1ca17b-l3A5Bk7waGM@public.gmane.org>

On Fri, Aug 04, 2017 at 06:59:10PM +0200, Nicolas Morey-Chaisemartin wrote:
> Generate a temporary file with the spec file parsed and all its macro replaced.
> Avoid manually replacing Version and handle extra macros
> 
> Signed-off-by: Nicolas Morey-Chaisemartin <NMoreyChaisemartin-IBi9RG/b67k@public.gmane.org>
>  .gitignore      | 3 +++
>  buildlib/cbuild | 8 ++++++--
>  2 files changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/.gitignore b/.gitignore
> index f31a0617..52c7af2f 100644
> +++ b/.gitignore
> @@ -69,3 +69,6 @@ tramp
>  Session.vim
>  .netrwhist
>  *~
> +
> +# rpm
> +*/*.spec.processed
> \ No newline at end of file
> diff --git a/buildlib/cbuild b/buildlib/cbuild
> index 5228ec1b..cf7828eb 100755
> +++ b/buildlib/cbuild
> @@ -404,7 +404,12 @@ def get_image_id(args,image_name):
>  
>  def run_rpm_build(args,spec_file,env):
>      version = get_version();
> -    with open(spec_file,"r") as F:
> +
> +    # Pre-process file with rpm spec to avoid manually replacing macros
> +    f = open(spec_file + ".processed", "w");
> +    subprocess.check_call(["rpmspec", "-P", spec_file], stdout=f);

This isn't going to work on any host system that does not have
rpmspec, including my Debian systems..

How about something like this instead for the two patches?

>From 13e239b5fc39fff9e56760969b99eab462db3d89 Mon Sep 17 00:00:00 2001
From: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
Date: Tue, 8 Aug 2017 17:04:06 -0600
Subject: [PATCH] cbuild: Be more robust when computing path names

Always use the same format for the git archvie prefix, this matches
the format that github-release uses, and is what a .spec file must work
with.

Use rpmspec -P to determine what the expected tar file name is instead of
trying to do substitution internally.

Signed-off-by: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
---
 buildlib/cbuild | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/buildlib/cbuild b/buildlib/cbuild
index 9b49fa5343c8b4..a3cf26e85bc722 100755
--- a/buildlib/cbuild
+++ b/buildlib/cbuild
@@ -409,16 +409,10 @@ def get_image_id(args,image_name):
 # -------------------------------------------------------------------------
 
 def run_rpm_build(args,spec_file,env):
-    version = get_version();
     with open(spec_file,"r") as F:
         for ln in F:
-            if ln.startswith("Version:"):
-                ver = ln.strip().partition(' ')[2];
-                assert(ver == get_version());
-
             if ln.startswith("Source:"):
                 tarfn = ln.strip().partition(' ')[2];
-    tarfn = tarfn.replace("%{version}",version);
 
     image_id = get_image_id(args,env.image_name());
     with private_tmp(args) as tmpdir:
@@ -426,7 +420,8 @@ def run_rpm_build(args,spec_file,env):
         os.mkdir(os.path.join(tmpdir,"tmp"));
 
         subprocess.check_call(["git","archive",
-                               "--prefix","%s/"%(os.path.splitext(tarfn)[0]),
+                               # This must match the prefix generated buildlib/github-release
+                               "--prefix","%s-%s/"%(project,get_version()),
                                "--output",os.path.join(tmpdir,"SOURCES",tarfn),
                                "HEAD"]);
 
@@ -453,17 +448,25 @@ def run_rpm_build(args,spec_file,env):
         # for the user we are going to use to do the build.
         with open(os.path.join(tmpdir,"go.py"),"w") as F:
             print >> F,"""
-import os;
+import os,subprocess;
 with open("/etc/passwd","a") as F:
    print >> F, {passwd!r};
 with open("/etc/group","a") as F:
    print >> F, {group!r};
 os.setgid({gid:d});
 os.setuid({uid:d});
+
+# Get RPM to tell us the expected tar filename.
+for ln in subprocess.check_output(["rpmspec","-P",{tspec_file!r}]).splitlines():
+   if ln.startswith("Source:"):
+      tarfn = ln.strip().partition(' ')[2];
+os.symlink({tarfn!r},os.path.join("SOURCES",tarfn));
 """.format(passwd=":".join(str(I) for I in pwd.getpwuid(os.getuid())),
            group=":".join(str(I) for I in grp.getgrgid(os.getgid())),
            uid=os.getuid(),
-           gid=os.getgid());
+           gid=os.getgid(),
+           tarfn=tarfn,
+           tspec_file=tspec_file);
 
             bopts = ["-bb",tspec_file];
 
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2017-08-08 23:04 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-04 16:57 [PATCH rdma-core 0/3] cbuild tweaks Nicolas Morey-Chaisemartin
     [not found] ` <27366048-d80f-3711-c6cd-93c87809650e-l3A5Bk7waGM@public.gmane.org>
2017-08-04 16:58   ` [PATCH rdma-core 1/3] cbuild: allow indentation in RPM version Nicolas Morey-Chaisemartin
2017-08-04 16:59   ` [PATCH rdma-core 2/3] cbuild: support .tar.(gz|bz|>...) extensions Nicolas Morey-Chaisemartin
2017-08-04 16:59   ` [PATCH rdma-core 3/3] cbuild: use rpmspec for macro replacement Nicolas Morey-Chaisemartin
     [not found]     ` <8ad0438f-b4a5-aec9-1e44-a9c9dc1ca17b-l3A5Bk7waGM@public.gmane.org>
2017-08-08 23:04       ` Jason Gunthorpe [this message]
     [not found]         ` <20170808230459.GF29372-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-08-09  9:56           ` Nicolas Morey-Chaisemartin
     [not found]             ` <b3993b0c-0b9d-a917-cbf8-22f68c1d2a97-l3A5Bk7waGM@public.gmane.org>
2017-08-09 15:55               ` Jason Gunthorpe
     [not found]                 ` <20170809155532.GC15586-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-08-09 16:39                   ` Nicolas Morey-Chaisemartin
     [not found]                     ` <f42a6eaa-79f9-1063-b58a-08da363d09e7-l3A5Bk7waGM@public.gmane.org>
2017-08-09 20:19                       ` Jason Gunthorpe
     [not found]                         ` <20170809201932.GA7363-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-08-09 21:08                           ` Nicolas Morey-Chaisemartin
     [not found]                             ` <5c4de783-ce62-2b8d-78aa-ee2f181fe719-l3A5Bk7waGM@public.gmane.org>
2017-08-09 21:15                               ` Jason Gunthorpe
     [not found]                                 ` <20170809211536.GA10191-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-08-13  6:37                                   ` Leon Romanovsky
     [not found]                                     ` <20170813063706.GQ24282-U/DQcQFIOTAAJjI8aNfphQ@public.gmane.org>
2017-08-21  7:52                                       ` Nicolas Morey-Chaisemartin
     [not found]                                         ` <a17d1a6e-653a-0c8e-4b1b-d5ef2bf6d9b2-l3A5Bk7waGM@public.gmane.org>
2017-08-21 15:42                                           ` Jason Gunthorpe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170808230459.GF29372@obsidianresearch.com \
    --to=jgunthorpe-epgobjl8dl3ta4ec/59zmfatqe2ktcn/@public.gmane.org \
    --cc=NMoreyChaisemartin-l3A5Bk7waGM@public.gmane.org \
    --cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox