From patchwork Fri Aug 4 16:59:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Morey-Chaisemartin X-Patchwork-Id: 9881727 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B0540603FB for ; Fri, 4 Aug 2017 16:59:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9DE462890C for ; Fri, 4 Aug 2017 16:59:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 92DE1289EF; Fri, 4 Aug 2017 16:59:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 400102890C for ; Fri, 4 Aug 2017 16:59:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752984AbdHDQ7M (ORCPT ); Fri, 4 Aug 2017 12:59:12 -0400 Received: from mx2.suse.de ([195.135.220.15]:35684 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752966AbdHDQ7M (ORCPT ); Fri, 4 Aug 2017 12:59:12 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id DE6B3ADE6 for ; Fri, 4 Aug 2017 16:59:10 +0000 (UTC) From: Nicolas Morey-Chaisemartin Subject: [PATCH rdma-core 3/3] cbuild: use rpmspec for macro replacement To: linux-rdma@vger.kernel.org References: <27366048-d80f-3711-c6cd-93c87809650e@suse.de> Message-ID: <8ad0438f-b4a5-aec9-1e44-a9c9dc1ca17b@suse.de> Date: Fri, 4 Aug 2017 18:59:10 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:55.0) Gecko/20100101 Thunderbird/55.0 MIME-Version: 1.0 In-Reply-To: <27366048-d80f-3711-c6cd-93c87809650e@suse.de> Content-Language: fr-xx-classique+reforme1990 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- .gitignore | 3 +++ buildlib/cbuild | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index f31a0617..52c7af2f 100644 --- a/.gitignore +++ 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 --- a/buildlib/cbuild +++ 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); + + with open(spec_file + ".processed" ,"r") as F: for ln in F: if ln.startswith("Version:"): ver = ln.strip().partition(' ')[2].strip(); @@ -412,7 +417,6 @@ def run_rpm_build(args,spec_file,env): if ln.startswith("Source:"): tarfn = ln.strip().partition(' ')[2].strip(); - tarfn = tarfn.replace("%{version}",version); image_id = get_image_id(args,env.image_name()); with private_tmp(args) as tmpdir: