From 41fd60f624099dffcc4d1e9ef36f1232b7ddf3f9 Mon Sep 17 00:00:00 2001 From: vignanreddy574 Date: Wed, 26 Jun 2024 18:22:30 -0700 Subject: [PATCH] SetupDataPkg/Tools/setup.py: Expand script to publish binaries for ReadUefiVarsToConfVarList, WriteConfVarListToUefiVars. (#368) --- .gitignore | 4 +- SetupDataPkg/Tools/setup.py | 104 +++++++++++++++++++++++++++--------- 2 files changed, 82 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index f412f3de..70de1df8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +*.nuspec /Build/ .DS_Store *_extdep/ @@ -14,4 +15,5 @@ BuildConfig.conf _TEMP_*/ /Conf/ -**/Include/Generated \ No newline at end of file +**/Include/Generated +MuSignTools.nuspec \ No newline at end of file diff --git a/SetupDataPkg/Tools/setup.py b/SetupDataPkg/Tools/setup.py index 39ed3212..e95311e7 100644 --- a/SetupDataPkg/Tools/setup.py +++ b/SetupDataPkg/Tools/setup.py @@ -1,5 +1,5 @@ # @file -# Setup script to publish binary ConfigEditor. +# Setup script to publish binaries for ConfigEditor, ReadUefiVarsToConfVarList, and WriteConfVarListToUefiVars. # # Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: BSD-2-Clause-Patent @@ -12,45 +12,99 @@ import PyInstaller.__main__ +def build_executable(script_name, script_path, conf_folder_path, output_file_path): + print( + f"Building executable for script: {script_name} at path: {script_path}" + ) # Debugging line + args = [script_path, "--clean", "--onefile"] + + if conf_folder_path is not None: + for subdir, _, files in os.walk(conf_folder_path): + for file in files: + sub_path = os.path.join(subdir, file) + rel_path = os.path.relpath(subdir, conf_folder_path) + args.append( + f"--add-data={sub_path + os.pathsep + os.path.join('ConfDefinitions', rel_path)}" + ) + + if output_file_path is not None: + if os.path.isdir(output_file_path): + args.append(f"--distpath={output_file_path}") + else: + print( + "The specified output file path does not exist or is not a directory." + ) + return -1 + + PyInstaller.__main__.run(args) + + # # main script function # def main(): + parser = argparse.ArgumentParser( + description="Create executables for ConfigEditor, ReadUefiVarsToConfVarList, and WriteConfVarListToUefiVars" + ) - parser = argparse.ArgumentParser(description='Create single executable for Configuration Editor') - - parser.add_argument("--ConfFolderPath", dest="ConfFolderPath", help="Absolute path to all configuration " - "definitions to be embedded, subfolder structure will be kept", default=None) - parser.add_argument("--OutputFilePath", dest="OutputFilePath", help="Absolute path to output executable, default " - "will be./dist/", default=None) + parser.add_argument( + "script", + choices=[ + "ConfigEditor", + "ReadUefiVarsToConfVarList", + "WriteConfVarListToUefiVars", + "all", + ], + help="Specify which script to build or 'all' to build all scripts", + ) + parser.add_argument( + "--ConfFolderPath", + dest="ConfFolderPath", + help="Absolute path to all configuration definitions to be embedded, subfolder structure will be kept", + default=None, + ) + parser.add_argument( + "--OutputFilePath", + dest="OutputFilePath", + help="Absolute path to output executable, default will be ./dist/", + default=None, + ) options = parser.parse_args() - args = [os.path.join(os.path.dirname(os.path.realpath(__file__)), "ConfigEditor.py")] - args.append("--clean") - args.append("--onefile") - - if options.ConfFolderPath is not None: - for subdir, _, files in os.walk(options.ConfFolderPath): - for file in files: - sub_path = os.path.join(subdir, file) - rel_path = os.path.relpath(subdir, options.ConfFolderPath) - args.append(f"--add-data={sub_path + os.pathsep + os.path.join('ConfDefinitions', rel_path)}") + base_dir = os.path.dirname(os.path.abspath(__file__)) + scripts = { + "ConfigEditor": os.path.join(base_dir, "ConfigEditor.py"), + "ReadUefiVarsToConfVarList": os.path.join( + base_dir, "ReadUefiVarsToConfVarList.py" + ), + "WriteConfVarListToUefiVars": os.path.join( + base_dir, "WriteConfVarListToUefiVars.py" + ), + } - if options.OutputFilePath is not None: - if os.path.isdir: - args.append(f"--distpath={options.OutputFilePath}") - else: - return -1 + for key, value in scripts.items(): + print(f"Script {key}: {value}") # Debugging line - PyInstaller.__main__.run(args) + if options.script == "all": + for script_name, script_path in scripts.items(): + build_executable( + script_name, script_path, options.ConfFolderPath, options.OutputFilePath + ) + else: + build_executable( + options.script, + scripts[options.script], + options.ConfFolderPath, + options.OutputFilePath, + ) return 0 -if __name__ == '__main__': +if __name__ == "__main__": # setup main console as logger - logger = logging.getLogger('') + logger = logging.getLogger("") logger.setLevel(logging.DEBUG) formatter = logging.Formatter("%(levelname)s - %(message)s") console = logging.StreamHandler()