From nobody Fri May 3 21:51:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+56888+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+56888+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1585814919; cv=none; d=zohomail.com; s=zohoarc; b=De/mbL5Fx7ofeszJiPNNLglYDn211IAf/oa70bs0ApChdUUTvHGL8SIOGwu2uY5OoVbMwULo2GGQtkzanQaEC9a8elhfcd7prRD6peHnYjVTRMCnazgXTvmTnN87iyWwkJO7ClZxAwkSPVLYD2MepV80fYHTZwdHarLG0TaYkpg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585814919; h=Content-Transfer-Encoding:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=U8OSARGGz95r0Bcv5XHDYsRbNtJNMFADs5o3zfvhQig=; b=kqABtQxXwwFL1womYVrRM+Vjr9VS7jlvtahbmbLrPNH9WAfDZt/DgctkTIfBzEnLDPIWk3CBzCs5rKugr/AsJzhj/wjclqX4R2+kIj6q2Jt6dyOIiIXpQ8IR8FWkzxH53lzErTvJWVETKUGbysyVJRHA5HmRDZcXO3vYo8ruwNw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+56888+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1585814919155697.0530207378233; Thu, 2 Apr 2020 01:08:39 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id E1IOYY1788612xKTUwEvi4KS; Thu, 02 Apr 2020 01:08:38 -0700 X-Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mx.groups.io with SMTP id smtpd.web11.1908.1585814918054305239 for ; Thu, 02 Apr 2020 01:08:38 -0700 IronPort-SDR: 2pN60x7SO5Hmi0VAKfoq28Lhi0Ut5hjPWWG6isIBGBDKdmutaO8ms0g4TeXCoWWddnfemjUFq5 cjJEjvOB6VYw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2020 01:08:37 -0700 IronPort-SDR: oWP++9kC3cTyMZUCsp/EhtLD9/UV8O3AMoq5TM4LtLdy/Qbx0EcMFyhX7TiYEM9p/8Jxn+ASjY AU7CzVOWcgkQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,335,1580803200"; d="scan'208";a="396278655" X-Received: from hengluo-dev.ccr.corp.intel.com ([10.239.153.154]) by orsmga004.jf.intel.com with ESMTP; 02 Apr 2020 01:08:34 -0700 From: "Heng Luo" To: devel@edk2.groups.io Cc: Ray Ni , Eric Dong , Liming Gao , Bob Feng , Amy Chan Subject: [edk2-devel] [PATCH] BaseTools/Scripts: Add scripts to set PACKAGES_PATH environment Date: Thu, 2 Apr 2020 16:08:09 +0800 Message-Id: <20200402080809.2147-1-heng.luo@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,heng.luo@intel.com X-Gm-Message-State: JgGHiAUSZqfcAAYWbqvWsbO1x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1585814918; bh=tbiK/I8kvvml/riPm+4z9m6yRSt+FChFAAg4dMGQwYY=; h=Cc:Date:From:Reply-To:Subject:To; b=h69CpzdqfX7BqyDwA9trrYC8R2528ywMK5WiAEMyx1YiKx0PfGFo/g8j2aOGvDeWzdf 9op8C9YSSE5VhVbtB4bQCRyhsfSHArxLRFImn8l9bACLhG1zRZV6C5suuNYDZ0loMIqyL RZUSpK2qEIa6P/GMZ5CpBZ2DUOiOXz4jcGM= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2656 1. Add GetPackagesPath.py, it will be used to get package pathes from special directories. A sub directory is a qualified package path when an EDKII Package can be found under it. 2. Add SetPackagesPath.bat and SetPackagesPath.sh, these scripts call GetPackagesPath.py to collect all package paths under specified directories and append them to PACKAGES_PATH environment variable. Cc: Ray Ni Cc: Eric Dong Cc: Liming Gao Cc: Bob Feng Cc: Amy Chan Signed-off-by: Heng Luo --- BaseTools/Scripts/GetPackagesPath.py | 94 +++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ BaseTools/Scripts/SetPackagesPath.bat | 33 +++++++++++++++++++++++++++++++= ++ BaseTools/Scripts/SetPackagesPath.sh | 40 +++++++++++++++++++++++++++++++= +++++++++ 3 files changed, 167 insertions(+) diff --git a/BaseTools/Scripts/GetPackagesPath.py b/BaseTools/Scripts/GetPa= ckagesPath.py new file mode 100644 index 0000000000..82d66a6106 --- /dev/null +++ b/BaseTools/Scripts/GetPackagesPath.py @@ -0,0 +1,94 @@ +## @file +# Get all recursive package paths from special directories. +# +# Copyright (c) 2020, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +import os +import glob +import argparse + +# +# Globals for help information +# +__prog__ =3D 'GetPackagesPath.py' +__copyright__ =3D 'Copyright (c) 2020, Intel Corporation. All rights reser= ved.' +__description__ =3D 'Gets all recursive package paths in specified directo= ry.\n' + +def list_packages_path(root): + """ Gets all recursive package paths in specified directory. + A directory is a package path if it satisfies conditions below: + 1. it is a directory + 2. it is not an EDK II Package. An EDK II Package (directory) is + a directory that contains an EDK II package declaration (DEC) f= ile. + 3. it contains at least one first level EDK II Package. + Note: A directory is not package path but its subdirectory could b= e. + Example: edk2-platforms/Features is not package path + but edk2-platforms/Features/Intel is. + + :param root: The specified directory to find package paths in it + :type root: String + :returns: Return all recursive package paths + :rtype: String list + """ + + if (not os.path.exists(root)) or (not os.path.isdir(root)): + return [] + + if glob.glob(os.path.join(root, '*.dec')): + # it is an EDK II Package + return [] + + paths =3D [] + contain_package =3D False + for filename in os.listdir(root): + filepath =3D os.path.join(root, filename) + if os.path.isdir(filepath): + if glob.glob(os.path.join(filepath, '*.dec')): + # it is an EDK II Package + contain_package =3D True + else: + # gets package paths for subdirectory if it is not package + paths =3D paths + list_packages_path(filepath) + + if contain_package: + # root is a package path because it contains EDK II Package + # in first level folder, inset it to head of list + paths.insert(0, root) + + # return package paths + return paths + +def get_packages_path(directories): + """ For each direcory in directories, gets all recursive package paths + in this directory and joins them into one string. + + :param directories: the list of directory + :type directories: String list + :returns: Return string of package paths + :rtype: String + """ + + packages_path =3D '' + for directory in directories: + directory =3D os.path.abspath(directory) + paths =3D list_packages_path(directory) + for path in paths: + if packages_path =3D=3D '': + packages_path =3D path + else: + packages_path +=3D os.pathsep + path + return packages_path + +if __name__ =3D=3D '__main__': + # Create command line argument parser object + parser =3D argparse.ArgumentParser( + prog=3D__prog__, + description=3D__description__ + __copyright__, + conflict_handler=3D'resolve' + ) + parser.add_argument('directory', nargs=3D'+', + help=3D'Specified directory where package packages are got fro= m') + args =3D parser.parse_args() + print(get_packages_path(args.directory)) diff --git a/BaseTools/Scripts/SetPackagesPath.bat b/BaseTools/Scripts/SetP= ackagesPath.bat new file mode 100644 index 0000000000..a8c45612c9 --- /dev/null +++ b/BaseTools/Scripts/SetPackagesPath.bat @@ -0,0 +1,33 @@ +@REM @file +@REM Windows batch file to set PACKAGES_PATH environment +@REM +@REM Copyright (c) 2020, Intel Corporation. All rights reserved.
+@REM SPDX-License-Identifier: BSD-2-Clause-Patent +@REM +@REM This script calls GetPackagesPath.py to collect all package paths und= er +@REM specified directories and append them to PACKAGES_PATH environment +@REM variable. A sub directory is a qualified package path when an EDKII +@REM Package can be found under it. + +@echo off +@if /I "%1"=3D=3D"" @goto Usage +@if /I "%1"=3D=3D"-h" @goto Usage +@if /I "%1"=3D=3D"--help" @goto Usage +@if /I "%1"=3D=3D"/?" @goto Usage + +for /f %%i in ('python %EDK_TOOLS_PATH%\Scripts\GetPackagesPath.py %*') do= ( + if defined PACKAGES_PATH ( + set "PACKAGES_PATH=3D%PACKAGES_PATH%;%%i" + ) else ( + set "PACKAGES_PATH=3D%%i" + ) +) +@goto End + +:Usage +@echo Usage: SetPackagesPath.bat directory [directory ...] +@echo Copyright(c) 2020, Intel Corporation. All rights reserved. +@echo Options: +@echo --help, -h Print this help screen and exit + +:End diff --git a/BaseTools/Scripts/SetPackagesPath.sh b/BaseTools/Scripts/SetPa= ckagesPath.sh new file mode 100644 index 0000000000..e3e337254e --- /dev/null +++ b/BaseTools/Scripts/SetPackagesPath.sh @@ -0,0 +1,40 @@ + +# +# Copyright (c) 2020, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# This script calls GetPackagesPath.py to collect all package paths under +# specified directories and append them to PACKAGES_PATH environment +# variable. A sub directory is a qualified package path when an EDKII +# Package can be found under it. +# +# Note: This script must be \'sourced\' so the environment can be changed: +# source SetPackagesPath.sh +# . SetPackagesPath.sh + +function Usage() +{ + echo "Usage: source SetPackagesPath.sh directory [directory ...]" + echo "Copyright(c) 2020, Intel Corporation. All rights reserved." + echo "Options:" + echo " --help, -h Print this help screen and exit" + echo "Please note: This script must be \'sourced\' so the environment = can be changed." + echo ". SetPackagesPath.sh" + echo "source SetPackagesPath.sh" +} + +function SetEnv() +{ + local paths=3D$(python $EDK_TOOLS_PATH/Scripts/GetPackagesPath.py $@) + if [ "$PACKAGES_PATH" ]; then + PACKAGES_PATH=3D$PACKAGES_PATH:$paths + else + PACKAGES_PATH=3D$paths + fi +} + +if [ $# -eq 0 -o "$1" =3D=3D "-h" -o "$1" =3D=3D "--help" -o "$1" =3D=3D "= /?" ]; then + Usage +else + SetEnv $@ +fi --=20 2.24.0.windows.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#56888): https://edk2.groups.io/g/devel/message/56888 Mute This Topic: https://groups.io/mt/72720370/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-