From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 E722621E1453D for ; Tue, 15 Aug 2017 13:55:45 -0700 (PDT) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga104.jf.intel.com with ESMTP; 15 Aug 2017 13:58:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,379,1498546800"; d="scan'208";a="137888602" Received: from mdkinney-mobl1.amr.corp.intel.com ([10.241.98.166]) by orsmga005.jf.intel.com with ESMTP; 15 Aug 2017 13:58:10 -0700 From: Michael D Kinney To: edk2-devel@lists.01.org Cc: Andrew Fish , Supreeth Venkatesh , Michael Kinney Date: Tue, 15 Aug 2017 13:58:08 -0700 Message-Id: <20170815205808.8060-1-michael.d.kinney@intel.com> X-Mailer: git-send-email 2.13.1.windows.2 Subject: [edk2-staging/edk2-test Patch V3] Test*Pkg: Replace POSTBUILD batch files with a python script 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: , X-List-Received-Date: Tue, 15 Aug 2017 20:55:46 -0000 Update the POSTBUILD step to use a python script to create and/or update the installer for the test framework and test cases. This expands the OS compatibility to include Windows, Linux, and Mac OS X. The python script TestFrameworkPkg/GenFramework.py is used by the TestFrameworkPkg to generate the installer with the test framework. This same python script is also used by packages that provide test cases (e.g. TestCasePkg) to add the test cases to the installer. The --package flag may be listed more than once for DSC files that build test cases from more than one package. The -v flag shows messages for all the directory and file operations. The usage for GenFramework.py is as follows: usage: GenFramework [-h] [--version] -a ARCH [ARCH ...] -t TOOLCHAIN -p PLATFORMFILE -b BUILDTARGET --conf= CONFDIRECTORY [-D [DEFINE [DEFINE ...]]] [-v] [--package [PACKAGE [PACKAGE ...]]] Create EDK II Test Framework installer in build output directory. Copyright (c) 2017, Intel Corporation. All rights reserved. optional arguments: -h, --help show this help message and exit --version show program's version number and exit -a ARCH [ARCH ...], --arch ARCH [ARCH ...] 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. -t TOOLCHAIN, --tagname TOOLCHAIN Using the Tool Chain Tagname to build the platform, overriding target.txt's TOOL_CHAIN_TAG definition. -p PLATFORMFILE, --platform PLATFORMFILE Build the platform specified by the DSC file name argument, overriding target.txt's ACTIVE_PLATFORM definition. -b BUILDTARGET, --buildtarget BUILDTARGET Using the TARGET to build the platform, overriding target.txt's TARGET definition. --conf= CONFDIRECTORY Specify the customized Conf directory. -D [DEFINE [DEFINE ...]], --define [DEFINE [DEFINE ...]] Macro: "Name [= Value]". -v, --verbose Turn on verbose output with informational messages printed --package [PACKAGE [PACKAGE ...]] The directory name of a package of tests to copy Cc: Andrew Fish Cc: Supreeth Venkatesh Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Michael Kinney --- TestCasePkg/GenFramework.cmd | 86 ------------ TestCasePkg/TestCasePkg.dsc | 2 +- TestFrameworkPkg/GenFramework.cmd | 111 ---------------- TestFrameworkPkg/GenFramework.py | 239 ++++++++++++++++++++++++++++++++++ TestFrameworkPkg/TestFrameworkPkg.dsc | 2 +- 5 files changed, 241 insertions(+), 199 deletions(-) delete mode 100644 TestCasePkg/GenFramework.cmd delete mode 100644 TestFrameworkPkg/GenFramework.cmd create mode 100644 TestFrameworkPkg/GenFramework.py diff --git a/TestCasePkg/GenFramework.cmd b/TestCasePkg/GenFramework.cmd deleted file mode 100644 index 280ca70aa..000000000 --- a/TestCasePkg/GenFramework.cmd +++ /dev/null @@ -1,86 +0,0 @@ -@REM @file -@REM Windows batch file used to create installer in build output directory -@REM -@REM Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
-@REM This program and the accompanying materials -@REM are licensed and made available under the terms and conditions of the BSD License -@REM which accompanies this distribution. The full text of the license may be found at -@REM http://opensource.org/licenses/bsd-license.php -@REM -@REM THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -@REM WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -@REM - -@echo off - -::********************************************************************** -:: Parse command line arguments -::********************************************************************** -set ARCHLIST= -set CLEAN="" -:ArgLoop -if /i "%~1"=="" (goto Done) -if /i "%~1"=="clean" ( - set CLEAN=%~1 - shift - goto ArgLoop -) -if /i "%~2"=="" (goto Done) -if /i "%~1"=="-a" ( - set ARCHLIST=%ARCHLIST% %~2 - shift - shift - goto ArgLoop -) -if /i "%~1"=="-b" ( - set TARGET=%~2 - shift - shift - goto ArgLoop -) -if /i "%~1"=="-t" ( - set TOOLCHAIN=%~2 - shift - shift - goto ArgLoop -) -shift -goto ArgLoop -:Done - -for %%G in (%ARCHLIST%) do ( - set ARCH=%%G - call :CopyFiles -) - -goto Finished - -:CopyFiles -set Framework=%WORKSPACE%\Build\SctPackage\%ARCH% -set BuildOutput=%WORKSPACE%\Build\TestCasePkg\%TARGET%_%TOOLCHAIN%\%ARCH% - -if not %CLEAN%=="" ( - if exist %Framework%\Test rmdir /s/q %Framework%\Test - exit /b -) - -rem ********************************************* -rem Create target directories -rem ********************************************* - -if not exist %Framework% mkdir %Framework% -for %%G in (Data, Dependency, Support, Test, Sequence, Report, Proxy) do ( - if not exist %Framework%\%%G mkdir %Framework%\%%G -) - -::***************************************************** -:: Copy all test cases -::***************************************************** - -copy %BuildOutput%\*.efi %Framework%\Test > NUL -exit /b - -:Finished - - - diff --git a/TestCasePkg/TestCasePkg.dsc b/TestCasePkg/TestCasePkg.dsc index c2f1832ae..7ef656c27 100644 --- a/TestCasePkg/TestCasePkg.dsc +++ b/TestCasePkg/TestCasePkg.dsc @@ -22,7 +22,7 @@ SUPPORTED_ARCHITECTURES = IA32|IPF|X64|EBC|ARM BUILD_TARGETS = DEBUG|RELEASE SKUID_IDENTIFIER = DEFAULT - POSTBUILD = TestCasePkg/GenFramework.cmd + POSTBUILD = python TestFrameworkPkg/GenFramework.py --package TestCasePkg [LibraryClasses] UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf diff --git a/TestFrameworkPkg/GenFramework.cmd b/TestFrameworkPkg/GenFramework.cmd deleted file mode 100644 index 256294801..000000000 --- a/TestFrameworkPkg/GenFramework.cmd +++ /dev/null @@ -1,111 +0,0 @@ -@REM @file -@REM Windows batch file used to create installer in build output directory -@REM -@REM Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
-@REM This program and the accompanying materials -@REM are licensed and made available under the terms and conditions of the BSD License -@REM which accompanies this distribution. The full text of the license may be found at -@REM http://opensource.org/licenses/bsd-license.php -@REM -@REM THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -@REM WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -@REM - -@echo off - -::********************************************************************** -:: Parse command line arguments -::********************************************************************** -set ARCHLIST= -set CLEAN="" -:ArgLoop -if /i "%~1"=="" (goto Done) -if /i "%~1"=="clean" ( - set CLEAN=%~1 - shift - goto ArgLoop -) -if /i "%~2"=="" (goto Done) -if /i "%~1"=="-a" ( - set ARCHLIST=%ARCHLIST% %~2 - shift - shift - goto ArgLoop -) -if /i "%~1"=="-b" ( - set TARGET=%~2 - shift - shift - goto ArgLoop -) -if /i "%~1"=="-t" ( - set TOOLCHAIN=%~2 - shift - shift - goto ArgLoop -) -shift -goto ArgLoop -:Done - - -@set TEST_FRAMEWORK_PKG_PATH=%WORKSPACE%\TestFrameworkPkg -@if defined PACKAGES_PATH ( - @for %%i IN (%PACKAGES_PATH%) DO ( - @if exist %%~fi\TestFrameworkPkg ( - @set TEST_FRAMEWORK_PKG_PATH=%%~fi\TestFrameworkPkg - @goto ProcessArchList - ) - ) -) - -:ProcessArchList -for %%G in (%ARCHLIST%) do ( - set ARCH=%%G - call :CopyFiles -) - -goto Finished - -:CopyFiles -set Framework=%WORKSPACE%\Build\SctPackage\%ARCH% -set BuildOutput=%WORKSPACE%\Build\TestFrameworkPkg\%TARGET%_%TOOLCHAIN%\%ARCH% -if not %CLEAN%=="" ( - if exist %Framework%\.. rmdir /s/q %Framework%\.. - exit /b -) - -rem ********************************************* -rem Create target directories -rem ********************************************* - -if not exist %Framework% mkdir %Framework% -for %%G in (Data, Dependency, Support, Test, Sequence, Report, Proxy) do ( - if not exist %Framework%\%%G mkdir %Framework%\%%G -) - -::***************************************************** -:: Copy the SCT framework and the related application -::***************************************************** - -copy %BuildOutput%\InstallSct.efi %Framework% > NUL -copy %BuildOutput%\StallForKey.efi %Framework% > NUL - -copy %BuildOutput%\SCT.efi %Framework% > NUL - -copy %BuildOutput%\StandardTest.efi %Framework%\Support > NUL -copy %BuildOutput%\TestProfile.efi %Framework%\Support > NUL -copy %BuildOutput%\TestRecovery.efi %Framework%\Support > NUL -copy %BuildOutput%\TestLogging.efi %Framework%\Support > NUL - - -::********************************************* -:: Copy the SCT configuration data -::********************************************* - -copy %TEST_FRAMEWORK_PKG_PATH%\Scripts\SctStartup.nsh %Framework%\.. -copy %TEST_FRAMEWORK_PKG_PATH%\Data\Category.ini %Framework%\Data > NUL -copy %TEST_FRAMEWORK_PKG_PATH%\Data\GuidFile.txt %Framework%\Data > NUL -exit /b - -:Finished diff --git a/TestFrameworkPkg/GenFramework.py b/TestFrameworkPkg/GenFramework.py new file mode 100644 index 000000000..8a1527883 --- /dev/null +++ b/TestFrameworkPkg/GenFramework.py @@ -0,0 +1,239 @@ +## @file +# Create EDK II Test Framework installer in build output directory +# +# 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 BSD License +# which accompanies this distribution. The full text of the license may be 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 IMPLIED. +# + +''' +GenFramework +''' + +import os +import sys +import argparse +import glob +import shutil + +# +# Globals for help information +# +__prog__ = 'GenFramework' +__version__ = '%s Version %s' % (__prog__, '1.0') +__copyright__ = 'Copyright (c) 2017, Intel Corporation. All rights reserved.' +__description__ = 'Create EDK II Test Framework installer in build output directory.\n' + +# +# Globals +# +gWorkspace = '' +gArgs = None + +def Log(Message): + if not gArgs.Verbose: + return + sys.stdout.write (__prog__ + ': ' + Message + '\n') + +def Error(Message, ExitValue=1): + 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) + +def RemoveDirectory(target): + target = NormalizePath(target) + if not target or target == os.pathsep: + Error ('RemoveDirectory() invalid target') + if os.path.exists(target): + Log ('rmdir %s' % (RelativePath (target))) + shutil.rmtree(target) + +def CreateDirectory(target): + target = NormalizePath(target) + if not os.path.exists(target): + Log ('mkdir %s' % (RelativePath (target))) + os.makedirs (target) + +def Copy(src, dst): + src = NormalizePath(src) + dst = NormalizePath(dst) + for File in glob.glob(src): + Log ('copy %s -> %s' % (RelativePath (File), RelativePath (dst))) + shutil.copy (File, dst) + +if __name__ == '__main__': + # + # Create command line argument parser object + # + parser = argparse.ArgumentParser ( + prog = __prog__, + version = __version__, + description = __description__ + __copyright__, + conflict_handler = 'resolve' + ) + parser.add_argument ( + '-a', '--arch', dest = 'Arch', nargs = '+', action = 'append', + required = True, + help = '''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 = 'ToolChain', required = True, + help = '''Using the Tool Chain Tagname to build the platform, + overriding target.txt's TOOL_CHAIN_TAG definition.''' + ) + parser.add_argument ( + '-p', '--platform', dest = 'PlatformFile', required = True, + help = '''Build the platform specified by the DSC file name argument, + overriding target.txt's ACTIVE_PLATFORM definition.''' + ) + parser.add_argument ( + '-b', '--buildtarget', dest = 'BuildTarget', required = True, + help = '''Using the TARGET to build the platform, overriding + target.txt's TARGET definition.''' + ) + parser.add_argument ( + '--conf=', dest = 'ConfDirectory', required = True, + help = '''Specify the customized Conf directory.''' + ) + parser.add_argument ( + '-D', '--define', dest = 'Define', nargs='*', action = 'append', + help = '''Macro: "Name [= Value]".''' + ) + parser.add_argument ( + '-v', '--verbose', dest = 'Verbose', action = 'store_true', + help = '''Turn on verbose output with informational messages printed''' + ) + parser.add_argument ( + '--package', dest = 'Package', nargs = '*', action = 'append', + help = '''The directory name of a package of tests to copy''' + ) + + # + # Parse command line arguments + # + gArgs, remaining = parser.parse_known_args() + gArgs.BuildType = 'all' + for BuildType in ['all', 'fds', 'genc', 'genmake', 'clean', 'cleanall', 'modules', 'libraries', 'run']: + if BuildType in remaining: + gArgs.BuildType = BuildType + remaining.remove(BuildType) + break + gArgs.Remaining = ' '.join(remaining) + + # + # Start + # + Log ('Start') + + # + # Get WORKSPACE environment variable + # + try: + gWorkspace = os.environ['WORKSPACE'] + except: + Error ('WORKSPACE environment variable not set') + + # + # Find test framework package directory in WORKSPACE or PACKAGES_PATH + # + PathList = [gWorkspace] + try: + PathList += os.environ['PACKAGES_PATH'].split(os.pathsep) + except: + pass + for Path in PathList: + TestFrameworkPkgPath = NormalizePath((Path, 'TestFrameworkPkg')) + if os.path.exists(TestFrameworkPkgPath): + break + if not os.path.exists(TestFrameworkPkgPath): + Error ('TestFrameworkPkg directory not found in WORKSPACE or PACKAGES_PATH') + + # + # Process build target + # + InstallerPath = NormalizePath((gWorkspace, 'Build', 'SctPackage')) + if gArgs.BuildType == 'clean': + if gArgs.Package: + # + # Remove test cases for each package and CPU architecture + # + for Arch in gArgs.Arch: + Arch = Arch[0] + for Package in gArgs.Package: + Package = Package[0] + Log ('Remove test cases from %s from test framework installer in %s' % (Package, InstallerPath)) + RemoveDirectory ((InstallerPath, Arch, 'Test', Package)) + else: + # + # Remove the installer + # + Log ('Remove test framework installer in %s' % (InstallerPath)) + RemoveDirectory (InstallerPath) + else: + if gArgs.Package: + # + # Copy test cases for each package and CPU architcture + # + for Package in gArgs.Package: + Package = Package[0] + Log ('Add test cases from %s to test framework installer in %s' % (Package, InstallerPath)) + for Arch in gArgs.Arch: + Arch = Arch[0] + BuildOutput = NormalizePath(( + gWorkspace, + 'Build', + Package, + gArgs.BuildTarget + '_' + gArgs.ToolChain, + Arch + )) + if os.path.exists(BuildOutput): + CreateDirectory ((InstallerPath, Arch, 'Test', Package)) + Copy ((BuildOutput, '*.efi'), (InstallerPath, Arch, 'Test', Package)) + else: + # + # Copy test framework files for each CPU architcture + # + Log ('Create test framework installer in %s' % (InstallerPath)) + CreateDirectory ((InstallerPath)) + Copy ((TestFrameworkPkgPath, 'Scripts', 'SctStartup.nsh'), (InstallerPath)) + for Arch in gArgs.Arch: + Arch = Arch[0] + for Directory in ['Data', 'Dependency', 'Support', 'Test', 'Sequence', 'Report', 'Proxy']: + CreateDirectory ((InstallerPath, Arch, Directory)) + + BuildOutput = NormalizePath(( + gWorkspace, + 'Build', + 'TestFrameworkPkg', + gArgs.BuildTarget + '_' + gArgs.ToolChain, + Arch + )) + if os.path.exists(BuildOutput): + for File in ['InstallSct.efi', 'StallForKey.efi', 'Sct.efi']: + Copy ((BuildOutput, File), (InstallerPath, Arch)) + for File in ['StandardTest.efi', 'TestProfile.efi', 'TestRecovery.efi', 'TestLogging.efi']: + Copy ((BuildOutput, File), (InstallerPath, Arch, 'Support')) + + Copy ((TestFrameworkPkgPath, 'Data/Category.ini'), (InstallerPath, Arch, 'Data')) + Copy ((TestFrameworkPkgPath, 'Data/GuidFile.txt'), (InstallerPath, Arch, 'Data')) + Copy ((TestFrameworkPkgPath, 'Data/GuidFile.txt'), (InstallerPath, Arch, 'Data')) + + # + # Done + # + Log ('Done') diff --git a/TestFrameworkPkg/TestFrameworkPkg.dsc b/TestFrameworkPkg/TestFrameworkPkg.dsc index 93c8886af..b906839a1 100644 --- a/TestFrameworkPkg/TestFrameworkPkg.dsc +++ b/TestFrameworkPkg/TestFrameworkPkg.dsc @@ -22,7 +22,7 @@ SUPPORTED_ARCHITECTURES = IA32|IPF|X64|EBC|ARM BUILD_TARGETS = DEBUG|RELEASE SKUID_IDENTIFIER = DEFAULT - POSTBUILD = TestFrameworkPkg/GenFramework.cmd + POSTBUILD = python TestFrameworkPkg/GenFramework.py [LibraryClasses] UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf -- 2.13.1.windows.2