Skip to content

Optimize python script #1565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions .pytool/CISettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,62 +38,62 @@ def RetrieveCommandLineOptions(self, args):
# ####################################################################################### #

def GetPackagesSupported(self):
''' return iterable of edk2 packages supported by this build.
These should be edk2 workspace relative paths '''
""" return iterable of edk2 packages supported by this build.
These should be edk2 workspace relative paths """

return ("SurfaceDuo1Pkg","SurfaceDuo2Pkg")
return "SurfaceDuo1Pkg", "SurfaceDuo2Pkg"

def GetArchitecturesSupported(self):
''' return iterable of edk2 architectures supported by this build '''
return ("AARCH64")
""" return iterable of edk2 architectures supported by this build """
return "AARCH64"

def GetTargetsSupported(self):
''' return iterable of edk2 target tags supported by this build '''
return ("DEBUG", "RELEASE", "NO-TARGET", "NOOPT")
""" return iterable of edk2 target tags supported by this build """
return "DEBUG", "RELEASE", "NO-TARGET", "NOOPT"

# ####################################################################################### #
# Verify and Save requested Ci Build Config #
# ####################################################################################### #

def SetPackages(self, list_of_requested_packages):
''' Confirm the requested package list is valid and configure SettingsManager
""" Confirm the requested package list is valid and configure SettingsManager
to build the requested packages.

Raise UnsupportedException if a requested_package is not supported
'''
"""
unsupported = set(list_of_requested_packages) - \
set(self.GetPackagesSupported())
if(len(unsupported) > 0):
if len(unsupported) > 0:
logging.critical(
"Unsupported Package Requested: " + " ".join(unsupported))
raise Exception("Unsupported Package Requested: " +
" ".join(unsupported))
self.ActualPackages = list_of_requested_packages

def SetArchitectures(self, list_of_requested_architectures):
''' Confirm the requests architecture list is valid and configure SettingsManager
""" Confirm the requests architecture list is valid and configure SettingsManager
to run only the requested architectures.

Raise Exception if a list_of_requested_architectures is not supported
'''
"""
unsupported = set(list_of_requested_architectures) - \
set(self.GetArchitecturesSupported())
if(len(unsupported) > 0):
if len(unsupported) > 0:
logging.critical(
"Unsupported Architecture Requested: " + " ".join(unsupported))
raise Exception(
"Unsupported Architecture Requested: " + " ".join(unsupported))
self.ActualArchitectures = list_of_requested_architectures

def SetTargets(self, list_of_requested_target):
''' Confirm the request target list is valid and configure SettingsManager
""" Confirm the request target list is valid and configure SettingsManager
to run only the requested targets.

Raise UnsupportedException if a requested_target is not supported
'''
"""
unsupported = set(list_of_requested_target) - \
set(self.GetTargetsSupported())
if(len(unsupported) > 0):
if len(unsupported) > 0:
logging.critical(
"Unsupported Targets Requested: " + " ".join(unsupported))
raise Exception("Unsupported Targets Requested: " +
Expand All @@ -105,7 +105,7 @@ def SetTargets(self, list_of_requested_target):
# ####################################################################################### #

def GetActiveScopes(self):
''' return tuple containing scopes that should be active for this process '''
""" return tuple containing scopes that should be active for this process """
scopes = ("cibuild", "edk2-build", "host-based-test")

self.ActualToolChainTag = shell_environment.GetBuildVars().GetValue("TOOL_CHAIN_TAG", "")
Expand All @@ -121,9 +121,9 @@ def GetActiveScopes(self):
return scopes

def GetRequiredSubmodules(self):
''' return iterable containing RequiredSubmodule objects.
""" return iterable containing RequiredSubmodule objects.
If no RequiredSubmodules return an empty iterable
'''
"""
rs = []

# To avoid maintenance of this file for every new submodule
Expand All @@ -149,7 +149,7 @@ def GetName(self):
return "AndromedaPkg"

def GetDependencies(self):
''' Return Git Repository Dependencies
""" Return Git Repository Dependencies

Return an iterable of dictionary objects with the following fields
{
Expand All @@ -160,11 +160,11 @@ def GetDependencies(self):
Full: <optional> Boolean to do shallow or Full checkout. (default is False)
ReferencePath: <optional> Workspace relative path to git repo to use as "reference"
}
'''
"""
return []

def GetPackagesPath(self):
''' Return a list of workspace relative paths that should be mapped as edk2 PackagesPath '''
""" Return a list of workspace relative paths that should be mapped as edk2 PackagesPath """

# Include all submodule paths
result = ["Platforms"]
Expand All @@ -174,9 +174,9 @@ def GetPackagesPath(self):
return result

def GetWorkspaceRoot(self):
''' get WorkspacePath '''
""" get WorkspacePath """
return os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

def FilterPackagesToTest(self, changedFilesList: list, potentialPackagesList: list) -> list:
''' Filter potential packages to test based on changed files. '''
""" Filter potential packages to test based on changed files. """
return []
107 changes: 57 additions & 50 deletions Platforms/SurfaceDuo1Pkg/PlatformBuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,26 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: BSD-2-Clause-Patent
##
import datetime
import logging
import os
import uuid
from io import StringIO
from pathlib import Path

from edk2toolext.environment import shell_environment
from edk2toolext.environment.uefi_build import UefiBuilder
from edk2toolext.invocables.edk2_parse import ParseSettingsManager
from edk2toolext.invocables.edk2_platform_build import BuildSettingsManager
from edk2toolext.invocables.edk2_pr_eval import PrEvalSettingsManager
from edk2toolext.invocables.edk2_setup import (RequiredSubmodule,
SetupSettingsManager)
from edk2toolext.invocables.edk2_update import UpdateSettingsManager
from edk2toolext.invocables.edk2_parse import ParseSettingsManager
from edk2toollib.utility_functions import RunCmd

# ####################################################################################### #
# Common Configuration #
# ####################################################################################### #
class CommonPlatform():
''' Common settings for this platform. Define static data here and use

# ####################################################################################### #
# Common Configuration #
# ####################################################################################### #
class CommonPlatform:
""" Common settings for this platform. Define static data here and use
for the different parts of stuart
'''
"""
PackagesSupported = ("SurfaceDuo1Pkg",)
ArchSupported = ("AARCH64",)
TargetsSupported = ("DEBUG", "RELEASE", "NOOPT")
Expand All @@ -46,23 +42,24 @@ class CommonPlatform():
"Silicon/QC/Sm8150"
)


# ####################################################################################### #
# Configuration for Update & Setup #
# ####################################################################################### #


class SettingsManager(UpdateSettingsManager, SetupSettingsManager, PrEvalSettingsManager, ParseSettingsManager):

def GetPackagesSupported(self):
''' return iterable of edk2 packages supported by this build.
These should be edk2 workspace relative paths '''
""" return iterable of edk2 packages supported by this build.
These should be edk2 workspace relative paths """
return CommonPlatform.PackagesSupported

def GetArchitecturesSupported(self):
''' return iterable of edk2 architectures supported by this build '''
""" return iterable of edk2 architectures supported by this build """
return CommonPlatform.ArchSupported

def GetTargetsSupported(self):
''' return iterable of edk2 target tags supported by this build '''
""" return iterable of edk2 target tags supported by this build """
return CommonPlatform.TargetsSupported

def GetRequiredSubmodules(self):
Expand All @@ -85,32 +82,32 @@ def GetRequiredSubmodules(self):
]

def SetArchitectures(self, list_of_requested_architectures):
''' Confirm the requests architecture list is valid and configure SettingsManager
""" Confirm the requests architecture list is valid and configure SettingsManager
to run only the requested architectures.

Raise Exception if a list_of_requested_architectures is not supported
'''
"""
unsupported = set(list_of_requested_architectures) - \
set(self.GetArchitecturesSupported())
if(len(unsupported) > 0):
set(self.GetArchitecturesSupported())
if len(unsupported) > 0:
errorString = (
"Unsupported Architecture Requested: " + " ".join(unsupported))
logging.critical( errorString )
raise Exception( errorString )
"Unsupported Architecture Requested: " + " ".join(unsupported))
logging.critical(errorString)
raise Exception(errorString)
self.ActualArchitectures = list_of_requested_architectures

def GetWorkspaceRoot(self):
''' get WorkspacePath '''
""" get WorkspacePath """
return CommonPlatform.WorkspaceRoot

def GetActiveScopes(self):
''' return tuple containing scopes that should be active for this process '''
""" return tuple containing scopes that should be active for this process """
return CommonPlatform.Scopes

def FilterPackagesToTest(self, changedFilesList: list, potentialPackagesList: list) -> list:
''' Filter other cases that this package should be built
""" Filter other cases that this package should be built
based on changed files. This should cover things that can't
be detected as dependencies. '''
be detected as dependencies. """
build_these_packages = []
possible_packages = potentialPackagesList.copy()
for f in changedFilesList:
Expand All @@ -128,48 +125,51 @@ def FilterPackagesToTest(self, changedFilesList: list, potentialPackagesList: li
return build_these_packages

def GetPlatformDscAndConfig(self) -> tuple:
''' If a platform desires to provide its DSC then Policy 4 will evaluate if
""" If a platform desires to provide its DSC then Policy 4 will evaluate if
any of the changes will be built in the dsc.

The tuple should be (<workspace relative path to dsc file>, <input dictionary of dsc key value pairs>)
'''
return ("SurfaceDuo1Pkg/SurfaceDuo1.dsc", {})
"""
return "SurfaceDuo1Pkg/SurfaceDuo1.dsc", {}

def GetName(self):
return "SurfaceDuo1"

def GetPackagesPath(self):
''' Return a list of paths that should be mapped as edk2 PackagesPath '''
""" Return a list of paths that should be mapped as edk2 PackagesPath """
return CommonPlatform.PackagesPath

# ####################################################################################### #
# Actual Configuration for Platform Build #
# ####################################################################################### #


class PlatformBuilder(UefiBuilder, BuildSettingsManager):
def __init__(self):
UefiBuilder.__init__(self)

def AddCommandLineOptions(self, parserObj):
''' Add command line options to the argparser '''
""" Add command line options to the argparser """

# In an effort to support common server based builds this parameter is added. It is
# checked for correctness but is never uses as this platform only supports a single set of
# architectures.
parserObj.add_argument('-a', "--arch", dest="build_arch", type=str, default="AARCH64",
help="Optional - CSV of architecture to build. AARCH64 is used for PEI and "
"DXE and is the only valid option for this platform.")
help="Optional - CSV of architecture to build. AARCH64 is used for PEI and "
"DXE and is the only valid option for this platform.")

def RetrieveCommandLineOptions(self, args):
''' Retrieve command line options from the argparser '''
""" Retrieve command line options from the argparser """
if args.build_arch.upper() != "AARCH64":
raise Exception("Invalid Arch Specified. Please see comments in PlatformBuild.py::PlatformBuilder::AddCommandLineOptions")
raise Exception(
"Invalid Arch Specified. Please see comments in PlatformBuild.py::PlatformBuilder::AddCommandLineOptions")

def GetWorkspaceRoot(self):
''' get WorkspacePath '''
""" get WorkspacePath """
return CommonPlatform.WorkspaceRoot

def GetPackagesPath(self):
''' Return a list of paths that should be mapped as edk2 PackagesPath '''
""" Return a list of paths that should be mapped as edk2 PackagesPath """
result = [
shell_environment.GetBuildVars().GetValue("FEATURE_CONFIG_PATH", "")
]
Expand All @@ -178,11 +178,11 @@ def GetPackagesPath(self):
return result

def GetActiveScopes(self):
''' return tuple containing scopes that should be active for this process '''
""" return tuple containing scopes that should be active for this process """
return CommonPlatform.Scopes

def GetName(self):
''' Get the name of the repo, platform, or product being build '''
""" Get the name of the repo, platform, or product being build """
''' Used for naming the log file, among others '''
return "SurfaceDuo1Pkg"

Expand Down Expand Up @@ -218,12 +218,17 @@ def SetPlatformEnv(self):
self.env.SetValue("BLD_*_BUILDID_STRING", "Unknown", "Default")
# Default turn on build reporting.
self.env.SetValue("BUILDREPORTING", "TRUE", "Enabling build report")
self.env.SetValue("BUILDREPORT_TYPES", "PCD DEPEX FLASH BUILD_FLAGS LIBRARY FIXED_ADDRESS HASH", "Setting build report types")
self.env.SetValue("BUILDREPORT_TYPES", "PCD DEPEX FLASH BUILD_FLAGS LIBRARY FIXED_ADDRESS HASH",
"Setting build report types")
self.env.SetValue("BLD_*_MEMORY_PROTECTION", "TRUE", "Default")
# Include the MFCI test cert by default, override on the commandline with "BLD_*_SHIP_MODE=TRUE" if you want the retail MFCI cert
self.env.SetValue("BLD_*_SHIP_MODE", "FALSE", "Default")
self.env.SetValue("CONF_AUTOGEN_INCLUDE_PATH", self.edk2path.GetAbsolutePathOnThisSystemFromEdk2RelativePath("Platforms", "AndromedaPkg", "Include"), "Platform Defined")
self.env.SetValue("MU_SCHEMA_DIR", self.edk2path.GetAbsolutePathOnThisSystemFromEdk2RelativePath("Platforms", "AndromedaPkg", "CfgData"), "Platform Defined")
self.env.SetValue("CONF_AUTOGEN_INCLUDE_PATH",
self.edk2path.GetAbsolutePathOnThisSystemFromEdk2RelativePath("Platforms", "AndromedaPkg",
"Include"), "Platform Defined")
self.env.SetValue("MU_SCHEMA_DIR",
self.edk2path.GetAbsolutePathOnThisSystemFromEdk2RelativePath("Platforms", "AndromedaPkg",
"CfgData"), "Platform Defined")
self.env.SetValue("MU_SCHEMA_FILE_NAME", "AndromedaPkgCfgData.xml", "Platform Hardcoded")

return 0
Expand All @@ -237,18 +242,20 @@ def PlatformPostBuild(self):
def FlashRomImage(self):
return 0


if __name__ == "__main__":
import argparse
import sys

from edk2toolext.invocables.edk2_platform_build import Edk2PlatformBuild
from edk2toolext.invocables.edk2_setup import Edk2PlatformSetup
from edk2toolext.invocables.edk2_update import Edk2Update

print("Invoking Stuart")
print(" ) _ _")
print(" ( (^)-~-(^)")
print("__,-.\_( 0 0 )__,-.___")
print(" 'W' \ / 'W'")
print(r"__,-.\_( 0 0 )__,-.___")
print(r" 'W' \ / 'W'")
print(" >o<")
SCRIPT_PATH = os.path.relpath(__file__)
parser = argparse.ArgumentParser(add_help=False)
Expand All @@ -262,11 +269,11 @@ def FlashRomImage(self):
new_args = new_args + remaining
sys.argv = new_args
if args.setup:
print("Running stuart_setup -c " + SCRIPT_PATH)
print(f"Running stuart_setup -c {SCRIPT_PATH}")
Edk2PlatformSetup().Invoke()
elif args.update:
print("Running stuart_update -c " + SCRIPT_PATH)
print(f"Running stuart_update -c {SCRIPT_PATH}")
Edk2Update().Invoke()
else:
print("Running stuart_build -c " + SCRIPT_PATH)
Edk2PlatformBuild().Invoke()
print(f"Running stuart_build -c {SCRIPT_PATH}")
Edk2PlatformBuild().Invoke()
Loading
Loading