From patchwork Thu Jun 1 10:12:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent McIntyre X-Patchwork-Id: 9759143 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 043D160375 for ; Thu, 1 Jun 2017 10:12:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D2879283BA for ; Thu, 1 Jun 2017 10:12:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C7491284DC; Thu, 1 Jun 2017 10:12:23 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 04D25283BA for ; Thu, 1 Jun 2017 10:12:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751455AbdFAKMW (ORCPT ); Thu, 1 Jun 2017 06:12:22 -0400 Received: from mail-it0-f68.google.com ([209.85.214.68]:36811 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751283AbdFAKMV (ORCPT ); Thu, 1 Jun 2017 06:12:21 -0400 Received: by mail-it0-f68.google.com with SMTP id i206so5081938ita.3 for ; Thu, 01 Jun 2017 03:12:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mime-version:content-disposition :user-agent; bh=ZLEf0sINY2qlsYFozICi7IGnizeiMDHi1Z/zB0B6AVA=; b=WXMVvkGSdO1r6dkX19J0cbLQ+E4+qCRIy+bN+f+CByHbSecf29zwICmAUOFeLh4p5Z LvHHC/cge5+0yiPEe7yr3i3htVveW97Tk1z1qflOwtfdlqtZrG8DUy+CVr8Z9d+LhnWU 8Jsyp0Khv9Gdmv7MAMGe056YX3gRZIwKx6X1csQ/aR86tf8NL6KkPfUR7w3FCZWmDLOF obhgt/SpmqOeOHTHLkU4p/ICLzPcu2quEc2ty0qA+ojsMUn/qc1GfiXdw7g7fcbVyTLq rVvHXiUSUqD4OBySiPgy2sC4ox6+EhQy3rj7EApBbKURG3QmVNvW8ijg5DYYluqRhCGh PAyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=ZLEf0sINY2qlsYFozICi7IGnizeiMDHi1Z/zB0B6AVA=; b=hifQx5v3BSxUJQfajT0yBEqQ4Yg23kLqotMiBUTplOEmPgpy3HjRZ9nTtuprFVdJus OzrmPt3lYJni+oXnp3lOM8+7PpKOJAhQ/kAzIzQikziH6qQqwiKJn3XuAhRsrC06VKZC YxtsTNGYni4ScalgzmYWBnKAwSCrtxvc4f/0rme3wOcE93xPGTdwQGl3akGRUNdP5srg W+u5dqJQYhDpZaotFw4dEKpYy881NKm+gWVO36ACEvMkzryevm1USdKqyeHz7LIOU4eC dFD7jOcMRM7rnGAfUZxOZSID3O7q8tsoz+Sy6nC1UFSYlHuQZhnzl4NUvixzR/mXckvi BCGg== X-Gm-Message-State: AODbwcA99IMdpKgW5o49dN7MDkP77N3sFtIGIFQ5QPiHzZ9S+Xmpo0NQ 954m+PdTKWi4pUZW X-Received: by 10.99.139.194 with SMTP id j185mr377177pge.126.1496311939880; Thu, 01 Jun 2017 03:12:19 -0700 (PDT) Received: from ubuntu.windy (c122-106-153-7.carlnfd1.nsw.optusnet.com.au. [122.106.153.7]) by smtp.gmail.com with ESMTPSA id e124sm32870242pfc.64.2017.06.01.03.12.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 03:12:18 -0700 (PDT) Date: Thu, 1 Jun 2017 20:12:33 +1000 From: Vincent McIntyre To: linux-media@vger.kernel.org Subject: [PATCH] small cleanup of build script Message-ID: <20170601101232.GB3212@ubuntu.windy> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce a function for better tracing of system() calls While debugging a recent issue I wanted more complete information about the sequencence of events in a series of system("foo") or die("BAR") calls. Adding this helper did that and cleaned things up a little. Signed-off-by: Vincent McIntyre --- build | 81 +++++++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 47 insertions(+), 34 deletions(-) diff --git a/build b/build index 4457a73..38ffd4f 100755 --- a/build +++ b/build @@ -342,6 +342,19 @@ sub which($) return undef; } +sub run($$) +{ + my $cmd = shift; + my $err = shift; + $err = '' unless defined($err); + + my ($pkg,$filename,$line) = caller; + + print "\$ $cmd\n" if ($level); + system ($cmd) == 0 + or die($err . " at $filename line $line\n"); +} + ###### # Main ###### @@ -406,11 +419,11 @@ if (@git == 2) { if (!$local) { print "Getting the latest Kernel tree. This will take some time\n"; if ($depth) { - system("git clone --origin '$rname/$git[1]' git://linuxtv.org/media_tree.git media $depth") == 0 - or die "Can't clone from the upstream tree"; + run("git clone --origin '$rname/$git[1]' git://linuxtv.org/media_tree.git media $depth", + "Can't clone from the upstream tree"); } else { - system("git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git media $depth") == 0 - or die "Can't clone from the upstream tree"; + run("git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git media $depth", + "Can't clone from the upstream tree"); } system('git --git-dir media/.git config format.cc "Linux Media Mailing List "'); system('git --git-dir media/.git config format.signoff true'); @@ -419,56 +432,54 @@ if (@git == 2) { } else { if ($workdir ne "") { print "Creating a new workdir from $git[0] at media\n"; - system("git new-workdir $git[0] media") == 0 - or die "Can't create a new workdir"; + run("git new-workdir $git[0] media", + "Can't create a new workdir"); } else { print "Creating a new clone\n"; - system("git clone -l $git[0] media $depth") == 0 - or die "Can't create a new clone"; + run("git clone -l $git[0] media $depth", + "Can't create a new clone"); } } } elsif ($workdir eq "") { if (check_git("remote", "$rname/$git[1]")) { - system("git --git-dir media/.git remote update '$rname/$git[1]'") == 0 - or die "Can't update from the upstream tree"; + run("git --git-dir media/.git remote update '$rname/$git[1]'", + "Can't update from the upstream tree"); } else { - system("git --git-dir media/.git remote update origin") == 0 - or die "Can't update from the upstream tree"; + run("git --git-dir media/.git remote update origin", + "Can't update from the upstream tree"); } } if ($workdir eq "") { if (!check_git("remote", "$name")) { print "adding remote $name to track $git[0]\n"; - printf "\$ git --git-dir media/.git remote add $name $git[0]\n" if ($level); - system ("git --git-dir media/.git remote add $name $git[0]") == 0 - or die "Can't create remote $name"; + run("git --git-dir media/.git remote add $name $git[0]", + "Can't create remote $name"); } if (!$depth) { print "updating remote $rname\n"; - system ("git --git-dir media/.git remote update $name") == 0 - or die "Can't update remote $name"; + run("git --git-dir media/.git remote update $name", + "Can't update remote $name"); print "creating a local branch $rname\n"; if (!check_git("branch", "$rname/$git[1]")) { - print "\$ (cd media; git checkout -b $rname/$git[1] remotes/$name/$git[1])\n" if ($level); - system ("(cd media; git checkout -b $rname/$git[1] remotes/$name/$git[1])") == 0 - or die "Can't create local branch $rname"; + run("(cd media; git checkout -b $rname/$git[1] remotes/$name/$git[1])", + "Can't create local branch $rname"); } else { - system ("(cd media; git checkout $rname/$git[1])") == 0 - or die "Can't checkout to branch $rname"; - system ("(cd media; git pull . remotes/$name/$git[1])") == 0 - or die "Can't update local branch $name"; + run("(cd media; git checkout $rname/$git[1])", + "Can't checkout to branch $rname"); + run("(cd media; git pull . remotes/$name/$git[1])", + "Can't update local branch $name"); } } } else { print "git checkout $git[1]\n"; - system ("(cd media; git checkout $git[1])") == 0 - or die "Can't checkout $git[1]"; + run("(cd media; git checkout $git[1])", + "Can't checkout $git[1]"); } - system ("make -C linux dir DIR=../media/") == 0 - or die "Can't link the building system to the media directory."; + run("make -C linux dir DIR=../media/", + "Can't link the building system to the media directory."); } else { print "\n"; print "************************************************************\n"; @@ -486,8 +497,8 @@ if (@git == 2) { print "****************************\n"; system("git pull git://linuxtv.org/media_build.git master"); - system ("make -C linux/ download") == 0 or die "Download failed"; - system ("make -C linux/ untar") == 0 or die "Untar failed"; + run("make -C linux/ download", "Download failed"); + run("make -C linux/ untar", "Untar failed"); } print "**********************************************************\n"; @@ -495,17 +506,19 @@ print "* Downloading firmwares from linuxtv.org. *\n"; print "**********************************************************\n"; if (!stat $firmware_tarball) { - system ("wget $firmware_url/$firmware_tarball -O $firmware_tarball") == 0 or die "Can't download $firmware_tarball"; + run("wget $firmware_url/$firmware_tarball -O $firmware_tarball", + "Can't download $firmware_tarball"); } -system ("(cd v4l/firmware/; tar xvfj ../../$firmware_tarball)") == 0 or die "Can't extract $firmware_tarball"; +run("(cd v4l/firmware/; tar xvfj ../../$firmware_tarball)", + "Can't extract $firmware_tarball"); print "******************\n"; print "* Start building *\n"; print "******************\n"; -system ("make allyesconfig") == 0 or die "can't select all drivers"; -system ("make") == 0 or die "build failed"; +run("make allyesconfig", "can't select all drivers"); +run("make", "build failed"); print "**********************************************************\n"; print "* Compilation finished. Use 'make install' to install them\n";