From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web12.1127.1586480822216380701 for ; Thu, 09 Apr 2020 18:07:02 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.20, mailfrom: heng.luo@intel.com) IronPort-SDR: 2gtDACOJO3oejekzcdYbgU48KGssle4jtEOmbvcG6EO++9LnchyJ697ZxslMp69CDh04oH1fr4 n4qLaMgmJFsw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Apr 2020 18:07:01 -0700 IronPort-SDR: GiSinK+uctrA4SUa5kceLMEQMfnNniRYr1h9mWGxvweCCYzCRcIObMGsGrTxEZqne6vJC4acAY 0thH5pLtWg7g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,364,1580803200"; d="scan'208";a="398777541" Received: from unknown (HELO hengluo-dev.ccr.corp.intel.com) ([10.239.153.154]) by orsmga004.jf.intel.com with ESMTP; 09 Apr 2020 18:06:59 -0700 From: "Heng Luo" To: devel@edk2.groups.io Cc: Ray Ni , Eric Dong , Liming Gao , Bob Feng , Amy Chan Subject: [PATCH] Platform/Intel/Tools: Add scripts to set PACKAGES_PATH environment Date: Fri, 10 Apr 2020 09:05:49 +0800 Message-Id: <20200410010549.866-1-heng.luo@intel.com> X-Mailer: git-send-email 2.24.0.windows.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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 AppendPackagesPath.bat and AppendPackagesPath.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 --- Platform/Intel/Tools/AppendPackagesPath/AppendPackagesPath.bat | 33 ++++++= +++++++++++++++++++++++++++ Platform/Intel/Tools/AppendPackagesPath/AppendPackagesPath.sh | 42 ++++++= ++++++++++++++++++++++++++++++++++++ Platform/Intel/Tools/AppendPackagesPath/GetPackagesPath.py | 98 ++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++ Platform/Intel/Tools/AppendPackagesPath/Readme.md | 28 ++++++= ++++++++++++++++++++++ 4 files changed, 201 insertions(+) diff --git a/Platform/Intel/Tools/AppendPackagesPath/AppendPackagesPath.bat= b/Platform/Intel/Tools/AppendPackagesPath/AppendPackagesPath.bat new file mode 100644 index 0000000000..da15d9c451 --- /dev/null +++ b/Platform/Intel/Tools/AppendPackagesPath/AppendPackagesPath.bat @@ -0,0 +1,33 @@ +@REM @file=0D +@REM Windows batch file to set PACKAGES_PATH environment=0D +@REM=0D +@REM Copyright (c) 2020, Intel Corporation. All rights reserved.
=0D +@REM SPDX-License-Identifier: BSD-2-Clause-Patent=0D +@REM=0D +@REM This script calls GetPackagesPath.py to collect all package paths und= er=0D +@REM specified directories and appends them to PACKAGES_PATH environment=0D +@REM variable. A sub directory is a qualified package path when an EDKII=0D +@REM Package can be found under it.=0D +=0D +@echo off=0D +@if /I "%1"=3D=3D"" @goto Usage=0D +@if /I "%1"=3D=3D"-h" @goto Usage=0D +@if /I "%1"=3D=3D"--help" @goto Usage=0D +@if /I "%1"=3D=3D"/?" @goto Usage=0D +=0D +for /f %%i in ('python %~dp0\GetPackagesPath.py %*') do (=0D + if defined PACKAGES_PATH (=0D + set "PACKAGES_PATH=3D%PACKAGES_PATH%;%%i"=0D + ) else (=0D + set "PACKAGES_PATH=3D%%i"=0D + )=0D +)=0D +@goto End=0D +=0D +:Usage=0D +@echo Usage: AppendPackagesPath.bat directory [directory ...]=0D +@echo Copyright(c) 2020, Intel Corporation. All rights reserved.=0D +@echo Options:=0D +@echo --help, -h Print this help screen and exit=0D +=0D +:End=0D diff --git a/Platform/Intel/Tools/AppendPackagesPath/AppendPackagesPath.sh = b/Platform/Intel/Tools/AppendPackagesPath/AppendPackagesPath.sh new file mode 100644 index 0000000000..599c8d073b --- /dev/null +++ b/Platform/Intel/Tools/AppendPackagesPath/AppendPackagesPath.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# +# 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 appends 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 +# . AppendPackagesPath.sh + +function Usage() +{ + echo "Usage: source AppendPackagesPath.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 ". AppendPackagesPath.sh" + echo "source AppendPackagesPath.sh" +} + +function SetEnv() +{ + local tool_path=3D$(dirname "$BASH_SOURCE") + local paths=3D$(python $tool_path/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 diff --git a/Platform/Intel/Tools/AppendPackagesPath/GetPackagesPath.py b/P= latform/Intel/Tools/AppendPackagesPath/GetPackagesPath.py new file mode 100644 index 0000000000..31ed44cfa3 --- /dev/null +++ b/Platform/Intel/Tools/AppendPackagesPath/GetPackagesPath.py @@ -0,0 +1,98 @@ +## @file=0D +# Get all recursive package paths from special directories.=0D +#=0D +# Copyright (c) 2020, Intel Corporation. All rights reserved.
=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +=0D +import os=0D +import glob=0D +import argparse=0D +=0D +#=0D +# Globals for help information=0D +#=0D +__prog__ =3D 'GetPackagesPath.py'=0D +__copyright__ =3D 'Copyright (c) 2020, Intel Corporation. All rights reser= ved.'=0D +__description__ =3D 'Gets all recursive package paths in specified directo= ry.\n'=0D +=0D +def __get_packages_path(root):=0D + """ Gets all recursive package paths in specified directory.=0D + A directory is a package path if it satisfies conditions below:=0D + 1. it is a directory=0D + 2. it is not an EDK II Package. An EDK II Package (directory) is=0D + a directory that contains an EDK II package declaration (DEC) f= ile.=0D + 3. it contains at least one first level EDK II Package.=0D + Note: A directory is not package path but its subdirectory could b= e.=0D + Example: edk2-platforms/Features is not package path=0D + but edk2-platforms/Features/Intel is.=0D +=0D + :param root: The specified directory to find package paths in it,= =0D + the caller should ensure it is an valid directory=0D + :type root: String=0D + :returns: Return all recursive package paths=0D + :rtype: String list=0D + """=0D +=0D + paths =3D []=0D + contain_package =3D False=0D + for filename in os.listdir(root):=0D + # skip files whose name starts with ".", such as ".git"=0D + if filename.startswith('.'):=0D + continue=0D + filepath =3D os.path.join(root, filename)=0D + if os.path.isdir(filepath):=0D + if glob.glob(os.path.join(filepath, '*.dec')):=0D + # it is an EDK II Package=0D + contain_package =3D True=0D + else:=0D + # get package paths for subdirectory if it is not package= =0D + paths =3D paths + __get_packages_path(filepath)=0D +=0D + if contain_package:=0D + # root is a package path because it contains EDK II Package=0D + # in first level folder, inset it to head of list=0D + paths.insert(0, root)=0D +=0D + # return package paths=0D + return paths=0D +=0D +def get_packages_path(directories):=0D + """ For each direcory in directories, gets all recursive package paths= =0D + in this directory and joins them into one string.=0D +=0D + :param directories: the list of directory=0D + :type directories: String list=0D + :returns: Return string of package paths=0D + :rtype: String=0D + """=0D +=0D + packages_path =3D ''=0D + for directory in directories:=0D + directory =3D os.path.abspath(directory)=0D + if (not os.path.exists(directory)) or (not os.path.isdir(directory= )):=0D + continue=0D +=0D + if glob.glob(os.path.join(directory, '*.dec')):=0D + # it is an EDK II Package=0D + continue=0D +=0D + paths =3D __get_packages_path(directory)=0D + for path in paths:=0D + if packages_path =3D=3D '':=0D + packages_path =3D path=0D + else:=0D + packages_path +=3D os.pathsep + path=0D + return packages_path=0D +=0D +if __name__ =3D=3D '__main__':=0D + # Create command line argument parser object=0D + parser =3D argparse.ArgumentParser(=0D + prog=3D__prog__,=0D + description=3D__description__ + __copyright__,=0D + conflict_handler=3D'resolve'=0D + )=0D + parser.add_argument('directory', nargs=3D'+',=0D + help=3D'Specified directory where package packages are got fro= m')=0D + args =3D parser.parse_args()=0D + print(get_packages_path(args.directory))=0D diff --git a/Platform/Intel/Tools/AppendPackagesPath/Readme.md b/Platform/I= ntel/Tools/AppendPackagesPath/Readme.md new file mode 100644 index 0000000000..66aebee7cf --- /dev/null +++ b/Platform/Intel/Tools/AppendPackagesPath/Readme.md @@ -0,0 +1,28 @@ +=0D +# How to use AppendPackagesPath=0D +=0D +## Overview=0D +=0D +This script calls GetPackagesPath.py to collect all package paths under sp= ecified directories and appends them to PACKAGES_PATH environment variable.= A sub directory is a qualified package path when an EDKII Package can be f= ound under it.=0D +=0D +**Notice**:=0D +The old PACKAGES_PATH will be replaced by new one.s=0D +=0D +## The usage of the tool=0D +=0D +### Windows=0D +=0D +Usage: AppendPackagesPath.bat directory [directory ...]=0D +Copyright(c) 2020, Intel Corporation. All rights reserved.=0D +Options:=0D + --help, -h Print this help screen and exit=0D +=0D +### Ubuntu=0D +=0D +Usage: source AppendPackagesPath.sh directory [directory ...]=0D +Copyright(c) 2020, Intel Corporation. All rights reserved.=0D +Options:=0D + --help, -h Print this help screen and exit=0D +Please note: This script must be \'sourced\' so the environment can be cha= nged.=0D +. AppendPackagesPath.sh=0D +source AppendPackagesPath.sh=0D --=20 2.24.0.windows.2