Skip to content

Commit

Permalink
SetupDataPkg/Tools/setup.py: Expand script to publish binaries for Re…
Browse files Browse the repository at this point in the history
…adUefiVarsToConfVarList, WriteConfVarListToUefiVars. (#368)
  • Loading branch information
vignan-devops authored Jun 27, 2024
1 parent ae0f15a commit 41fd60f
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 26 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.nuspec
/Build/
.DS_Store
*_extdep/
Expand All @@ -14,4 +15,5 @@ BuildConfig.conf

_TEMP_*/
/Conf/
**/Include/Generated
**/Include/Generated
MuSignTools.nuspec
104 changes: 79 additions & 25 deletions SetupDataPkg/Tools/setup.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
Expand Down

0 comments on commit 41fd60f

Please sign in to comment.