From nobody Fri Dec 27 17:58:44 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1501781444298224.71541073552794; Thu, 3 Aug 2017 10:30:44 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id D0A4F21CE7490; Thu, 3 Aug 2017 10:28:30 -0700 (PDT) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 103DC21C9126D for ; Thu, 3 Aug 2017 10:28:29 -0700 (PDT) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP; 03 Aug 2017 10:30:40 -0700 Received: from mdkinney-mobl1.amr.corp.intel.com ([10.254.75.199]) by fmsmga006.fm.intel.com with ESMTP; 03 Aug 2017 10:30:30 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,317,1498546800"; d="scan'208";a="135756576" From: Michael D Kinney To: edk2-devel@lists.01.org Date: Thu, 3 Aug 2017 10:30:22 -0700 Message-Id: <20170803173023.2452-3-michael.d.kinney@intel.com> X-Mailer: git-send-email 2.13.1.windows.2 In-Reply-To: <20170803173023.2452-1-michael.d.kinney@intel.com> References: <20170803173023.2452-1-michael.d.kinney@intel.com> Subject: [edk2] [RFC Patch 2/3] BaseTools/Scripts: Add python script to run a makefile X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Kinney , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add the python script RunMakefile.py that can be used in a PREBUILD/POSTBUIILD action to invoke a makefile passing in context as makefile defines. The command line arguments passed into RunMakefile.py are converted to the following set of defines. * ACTIVE_PLATFORM * TARGET_ARCH * TOOL_CHAIN_TAG * CONF_DIRECTORY * TARGET * EXTRA_FLAGS In addition, a makefile can access the system environment variables including WORKSPACE and PACKAGES_PATH. The makefile target from the following set is also passed into the makefile. If no target is passed into build, then the 'all' target is used. [all|fds|genc|genmake|clean|cleanall|cleanlib|modules|libraries|run] A platform DSC file can use a statements in the [Defines] section of the following form to use this script. MAKEFILE is a WORKSPACE or PACKAGES_PATH relative path to the makefile to run. [Defines] PREBUILD =3D python BaseTools/Script/RunMakefile.py --makefile MAKEFILE POSTBUILD =3D python BaseTools/Script/RunMakefile.py --makefile MAKEFILE Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Michael Kinney --- BaseTools/Scripts/RunMakefile.py | 178 +++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 178 insertions(+) create mode 100644 BaseTools/Scripts/RunMakefile.py diff --git a/BaseTools/Scripts/RunMakefile.py b/BaseTools/Scripts/RunMakefi= le.py new file mode 100644 index 0000000000..48bc198c76 --- /dev/null +++ b/BaseTools/Scripts/RunMakefile.py @@ -0,0 +1,178 @@ +## @file +# Run a makefile as part of a PREBUILD or POSTBUILD action. +# +# Copyright (c) 2017, Intel Corporation. All rights reserved.
+# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BS= D License +# which accompanies this distribution. The full text of the license may b= e found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. +# + +''' +RunMakefile.py +''' + +import os +import sys +import argparse +import subprocess + +# +# Globals for help information +# +__prog__ =3D 'RunMakefile' +__version__ =3D '%s Version %s' % (__prog__, '1.0') +__copyright__ =3D 'Copyright (c) 2017, Intel Corporation. All rights res= erved.' +__description__ =3D 'Run a makefile as part of a PREBUILD or POSTBUILD act= ion.\n' + +# +# Globals +# +gArgs =3D None + +def Log(Message): + if not gArgs.Verbose: + return + sys.stdout.write (__prog__ + ': ' + Message + '\n') + +def Error(Message, ExitValue=3D1): + sys.stderr.write (__prog__ + ': ERROR: ' + Message + '\n') + sys.exit (ExitValue) + +def RelativePath(target): + return os.path.relpath (target, gWorkspace) + +def NormalizePath(target): + if isinstance(target, tuple): + return os.path.normpath (os.path.join (*target)) + else: + return os.path.normpath (target) + +if __name__ =3D=3D '__main__': + # + # Create command line argument parser object + # + parser =3D argparse.ArgumentParser ( + prog =3D __prog__, + version =3D __version__, + description =3D __description__ + __copyright__, + conflict_handler =3D 'resolve' + ) + parser.add_argument ( + '-a', '--arch', dest =3D 'Arch', nargs =3D '+', action =3D 'app= end', + required =3D True, + help =3D '''ARCHS is one of list: IA32, X64, IPF, ARM, AARCH64 = or EBC, + which overrides target.txt's TARGET_ARCH definition. = To + specify more archs, please repeat this option.''' + ) + parser.add_argument ( + '-t', '--tagname', dest =3D 'ToolChain', required =3D True, + help =3D '''Using the Tool Chain Tagname to build the platform, + overriding target.txt's TOOL_CHAIN_TAG definition.''' + ) + parser.add_argument ( + '-p', '--platform', dest =3D 'PlatformFile', required =3D True, + help =3D '''Build the platform specified by the DSC file name a= rgument, + overriding target.txt's ACTIVE_PLATFORM definition.''' + ) + parser.add_argument ( + '-b', '--buildtarget', dest =3D 'BuildTarget', required =3D Tru= e, + help =3D '''Using the TARGET to build the platform, overriding + target.txt's TARGET definition.''' + ) + parser.add_argument ( + '--conf=3D', dest =3D 'ConfDirectory', required =3D True, + help =3D '''Specify the customized Conf directory.''' + ) + parser.add_argument ( + '-D', '--define', dest =3D 'Define', nargs=3D'*', action =3D 'a= ppend', + help =3D '''Macro: "Name [=3D Value]".''' + ) + parser.add_argument ( + '--makefile', dest =3D 'Makefile', required =3D True, + help =3D '''Makefile to run passing in arguments as makefile de= fines.''' + ) + parser.add_argument ( + '-v', '--verbose', dest =3D 'Verbose', action =3D 'store_true', + help =3D '''Turn on verbose output with informational messages = printed''' + ) + + # + # Parse command line arguments + # + gArgs, remaining =3D parser.parse_known_args() + gArgs.BuildType =3D 'all' + for BuildType in ['all', 'fds', 'genc', 'genmake', 'clean', 'cleanall', = 'modules', 'libraries', 'run']: + if BuildType in remaining: + gArgs.BuildType =3D BuildType + remaining.remove(BuildType) + break + gArgs.Remaining =3D ' '.join(remaining) + + # + # Start + # + Log ('Start') + + # + # Find makefile in WORKSPACE or PACKAGES_PATH + # + PathList =3D [''] + try: + PathList.append(os.environ['WORKSPACE']) + except: + Error ('WORKSPACE environment variable not set') + try: + PathList +=3D os.environ['PACKAGES_PATH'].split(os.pathsep) + except: + pass + for Path in PathList: + Makefile =3D NormalizePath((Path, gArgs.Makefile)) + if os.path.exists (Makefile): + break + if not os.path.exists(Makefile): + Error ('makefile %s not found' % (gArgs.Makefile)) + + # + # Build command line arguments converting build arguments to makefile de= fines + # + CommandLine =3D [Makefile] + CommandLine.append('TARGET_ARCH=3D"%s"' % (' '.join([Item[0] for Item in= gArgs.Arch]))) + CommandLine.append('TOOL_CHAIN_TAG=3D"%s"' % (gArgs.ToolChain)) + CommandLine.append('TARGET=3D"%s"' % (gArgs.BuildTarget)) + CommandLine.append('ACTIVE_PLATFORM=3D"%s"' % (gArgs.PlatformFile)) + CommandLine.append('CONF_DIRECTORY=3D"%s"' % (gArgs.ConfDirectory)) + if gArgs.Define: + for Item in gArgs.Define: + if '=3D' not in Item[0]: + continue + Item =3D Item[0].split('=3D',1) + CommandLine.append('%s=3D"%s"' % (Item[0], Item[1])) + CommandLine.append('EXTRA_FLAGS=3D"%s"' % (gArgs.Remaining)) + CommandLine.append(gArgs.BuildType) + if sys.platform =3D=3D "win32": + CommandLine =3D 'nmake /f %s' % (' '.join(CommandLine)) + else: + CommandLine =3D 'make -f %s' % (' '.join(CommandLine)) + + # + # Run the makefile + # + try: + Process =3D subprocess.Popen(CommandLine, shell=3DTrue) + except: + Error ('make command not available. Please verify PATH') + Process.communicate() + + # + # Done + # + Log ('Done') + + # + # Return status from running the makefile + # + sys.exit(Process.returncode) --=20 2.13.1.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel