From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mx.groups.io with SMTP id smtpd.web12.6452.1586914296818407266 for ; Tue, 14 Apr 2020 18:31:37 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.43, mailfrom: ray.ni@intel.com) IronPort-SDR: vLofmTW1N0xKpaPOVq3EDyTjpquCXp5Lq8PFjzD5T6GwQA3Fsl5K2DugsE6+426DO8Sl5H2I/w 6utUmdRstFXg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Apr 2020 18:31:35 -0700 IronPort-SDR: eQ92fMwbeJCqxMbUuIsmEIwNNLU3jWUeAbFbQJbJ3Hp3PMS4/hucKBDNYwS1pjLUgzf7V0Auha pukgZ/xzJqGQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,385,1580803200"; d="scan'208";a="271585393" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga002.jf.intel.com with ESMTP; 14 Apr 2020 18:31:35 -0700 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 14 Apr 2020 18:31:35 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.225]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.22]) with mapi id 14.03.0439.000; Wed, 15 Apr 2020 09:31:30 +0800 From: "Ni, Ray" To: "Luo, Heng" , "devel@edk2.groups.io" CC: "Dong, Eric" , "Gao, Liming" , "Feng, Bob C" , "Chan, Amy" Subject: Re: [PATCH] Platform/Intel/Tools: Add scripts to set PACKAGES_PATH environment Thread-Topic: [PATCH] Platform/Intel/Tools: Add scripts to set PACKAGES_PATH environment Thread-Index: AQHWDtRazO1M6U6Bm0CSN5cL8Fxz4Kh5bT7A Date: Wed, 15 Apr 2020 01:31:29 +0000 Deferred-Delivery: Wed, 15 Apr 2020 01:31:00 +0000 Message-ID: <734D49CCEBEEF84792F5B80ED585239D5C4FEB7B@SHSMSX104.ccr.corp.intel.com> References: <20200410010549.866-1-heng.luo@intel.com> In-Reply-To: <20200410010549.866-1-heng.luo@intel.com> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.2.0.6 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Return-Path: ray.ni@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Ray Ni > -----Original Message----- > From: Luo, Heng > Sent: Friday, April 10, 2020 9:06 AM > To: devel@edk2.groups.io > Cc: Ni, Ray ; Dong, Eric ; Gao, Li= ming ; Feng, Bob C > ; Chan, Amy > Subject: [PATCH] Platform/Intel/Tools: Add scripts to set PACKAGES_PATH e= nvironment >=20 > Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2656 >=20 > 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. >=20 > 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(+) >=20 > diff --git a/Platform/Intel/Tools/AppendPackagesPath/AppendPackagesPath.b= at > 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 >=20 > +@REM Windows batch file to set PACKAGES_PATH environment >=20 > +@REM >=20 > +@REM Copyright (c) 2020, Intel Corporation. All rights reserved.
>=20 > +@REM SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > +@REM >=20 > +@REM This script calls GetPackagesPath.py to collect all package paths u= nder >=20 > +@REM specified directories and appends them to PACKAGES_PATH environment >=20 > +@REM variable. A sub directory is a qualified package path when an EDKII >=20 > +@REM Package can be found under it. >=20 > + >=20 > +@echo off >=20 > +@if /I "%1"=3D=3D"" @goto Usage >=20 > +@if /I "%1"=3D=3D"-h" @goto Usage >=20 > +@if /I "%1"=3D=3D"--help" @goto Usage >=20 > +@if /I "%1"=3D=3D"/?" @goto Usage >=20 > + >=20 > +for /f %%i in ('python %~dp0\GetPackagesPath.py %*') do ( >=20 > + if defined PACKAGES_PATH ( >=20 > + set "PACKAGES_PATH=3D%PACKAGES_PATH%;%%i" >=20 > + ) else ( >=20 > + set "PACKAGES_PATH=3D%%i" >=20 > + ) >=20 > +) >=20 > +@goto End >=20 > + >=20 > +:Usage >=20 > +@echo Usage: AppendPackagesPath.bat directory [directory ...] >=20 > +@echo Copyright(c) 2020, Intel Corporation. All rights reserved. >=20 > +@echo Options: >=20 > +@echo --help, -h Print this help screen and exit >=20 > + >=20 > +:End >=20 > diff --git a/Platform/Intel/Tools/AppendPackagesPath/AppendPackagesPath.s= h > 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 unde= r > +# 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 change= d: > +# 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 environmen= t 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/Platform/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 >=20 > +# Get all recursive package paths from special directories. >=20 > +# >=20 > +# Copyright (c) 2020, Intel Corporation. All rights reserved.
>=20 > +# SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > +# >=20 > + >=20 > +import os >=20 > +import glob >=20 > +import argparse >=20 > + >=20 > +# >=20 > +# Globals for help information >=20 > +# >=20 > +__prog__ =3D 'GetPackagesPath.py' >=20 > +__copyright__ =3D 'Copyright (c) 2020, Intel Corporation. All rights res= erved.' >=20 > +__description__ =3D 'Gets all recursive package paths in specified direc= tory.\n' >=20 > + >=20 > +def __get_packages_path(root): >=20 > + """ Gets all recursive package paths in specified directory. >=20 > + A directory is a package path if it satisfies conditions below: >=20 > + 1. it is a directory >=20 > + 2. it is not an EDK II Package. An EDK II Package (directory) is >=20 > + a directory that contains an EDK II package declaration (DEC)= file. >=20 > + 3. it contains at least one first level EDK II Package. >=20 > + Note: A directory is not package path but its subdirectory could= be. >=20 > + Example: edk2-platforms/Features is not package path >=20 > + but edk2-platforms/Features/Intel is. >=20 > + >=20 > + :param root: The specified directory to find package paths in it= , >=20 > + the caller should ensure it is an valid directory >=20 > + :type root: String >=20 > + :returns: Return all recursive package paths >=20 > + :rtype: String list >=20 > + """ >=20 > + >=20 > + paths =3D [] >=20 > + contain_package =3D False >=20 > + for filename in os.listdir(root): >=20 > + # skip files whose name starts with ".", such as ".git" >=20 > + if filename.startswith('.'): >=20 > + continue >=20 > + filepath =3D os.path.join(root, filename) >=20 > + if os.path.isdir(filepath): >=20 > + if glob.glob(os.path.join(filepath, '*.dec')): >=20 > + # it is an EDK II Package >=20 > + contain_package =3D True >=20 > + else: >=20 > + # get package paths for subdirectory if it is not packag= e >=20 > + paths =3D paths + __get_packages_path(filepath) >=20 > + >=20 > + if contain_package: >=20 > + # root is a package path because it contains EDK II Package >=20 > + # in first level folder, inset it to head of list >=20 > + paths.insert(0, root) >=20 > + >=20 > + # return package paths >=20 > + return paths >=20 > + >=20 > +def get_packages_path(directories): >=20 > + """ For each direcory in directories, gets all recursive package pat= hs >=20 > + in this directory and joins them into one string. >=20 > + >=20 > + :param directories: the list of directory >=20 > + :type directories: String list >=20 > + :returns: Return string of package paths >=20 > + :rtype: String >=20 > + """ >=20 > + >=20 > + packages_path =3D '' >=20 > + for directory in directories: >=20 > + directory =3D os.path.abspath(directory) >=20 > + if (not os.path.exists(directory)) or (not os.path.isdir(directo= ry)): >=20 > + continue >=20 > + >=20 > + if glob.glob(os.path.join(directory, '*.dec')): >=20 > + # it is an EDK II Package >=20 > + continue >=20 > + >=20 > + paths =3D __get_packages_path(directory) >=20 > + for path in paths: >=20 > + if packages_path =3D=3D '': >=20 > + packages_path =3D path >=20 > + else: >=20 > + packages_path +=3D os.pathsep + path >=20 > + return packages_path >=20 > + >=20 > +if __name__ =3D=3D '__main__': >=20 > + # Create command line argument parser object >=20 > + parser =3D argparse.ArgumentParser( >=20 > + prog=3D__prog__, >=20 > + description=3D__description__ + __copyright__, >=20 > + conflict_handler=3D'resolve' >=20 > + ) >=20 > + parser.add_argument('directory', nargs=3D'+', >=20 > + help=3D'Specified directory where package packages are got f= rom') >=20 > + args =3D parser.parse_args() >=20 > + print(get_packages_path(args.directory)) >=20 > diff --git a/Platform/Intel/Tools/AppendPackagesPath/Readme.md > b/Platform/Intel/Tools/AppendPackagesPath/Readme.md > new file mode 100644 > index 0000000000..66aebee7cf > --- /dev/null > +++ b/Platform/Intel/Tools/AppendPackagesPath/Readme.md > @@ -0,0 +1,28 @@ > + >=20 > +# How to use AppendPackagesPath >=20 > + >=20 > +## Overview >=20 > + >=20 > +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 packag= e path when an EDKII Package can be found > under it. >=20 > + >=20 > +**Notice**: >=20 > +The old PACKAGES_PATH will be replaced by new one.s >=20 > + >=20 > +## The usage of the tool >=20 > + >=20 > +### Windows >=20 > + >=20 > +Usage: AppendPackagesPath.bat directory [directory ...] >=20 > +Copyright(c) 2020, Intel Corporation. All rights reserved. >=20 > +Options: >=20 > + --help, -h Print this help screen and exit >=20 > + >=20 > +### Ubuntu >=20 > + >=20 > +Usage: source AppendPackagesPath.sh directory [directory ...] >=20 > +Copyright(c) 2020, Intel Corporation. All rights reserved. >=20 > +Options: >=20 > + --help, -h Print this help screen and exit >=20 > +Please note: This script must be \'sourced\' so the environment can be c= hanged. >=20 > +. AppendPackagesPath.sh >=20 > +source AppendPackagesPath.sh >=20 > -- > 2.24.0.windows.2