Skip to content

Commit

Permalink
Add cflags argument
Browse files Browse the repository at this point in the history
Allows setting object file cflags to change metadata to prevent warnings (on
ARM32 etc.)

Signed-off-by: Callum Farmer <[email protected]>
  • Loading branch information
gmbr3 committed Sep 28, 2023
1 parent 87ba253 commit 747b2f9
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions uswid/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def _save_efi_pefile(identity: uSwidIdentity, filepath: str) -> None:


def _save_efi_objcopy(
identity: uSwidIdentity, filepath: str, cc: Optional[str], objcopy: str
identity: uSwidIdentity, filepath: str, cc: Optional[str], cflags: str, objcopy: str
) -> None:
"""modify EFI file using objcopy"""
objcopy_full = shutil.which(objcopy)
Expand All @@ -125,7 +125,7 @@ def _save_efi_objcopy(
if not os.path.exists(filepath):
if not cc:
raise NotSupportedError("compiler is required for missing section")
subprocess.run([cc, "-x", "c", "-c", "-o", filepath, "/dev/null"], check=True)
subprocess.run([cc, "-x", "c", "-c", "-o", filepath, "/dev/null"] + cflags.split(" "), check=True)

# save to file?
try:
Expand Down Expand Up @@ -214,6 +214,7 @@ def main():
parser = argparse.ArgumentParser(prog="uswid", description="Generate CoSWID metadata")
parser.add_argument("--version", action="version", version="%(prog)s " + importlib_metadata.version("uswid"))
parser.add_argument("--cc", default="gcc", help="Compiler to use for empty object")
parser.add_argument("--cflags", default="", help="C compiler flags to be used by CC")
parser.add_argument("--binfile", default=None, help=argparse.SUPPRESS)
parser.add_argument("--rawfile", default=None, help=argparse.SUPPRESS)
parser.add_argument("--inifile", default=None, help=argparse.SUPPRESS)
Expand Down Expand Up @@ -377,7 +378,7 @@ def main():
print("cannot save PE when no default identity")
sys.exit(1)
if args.objcopy:
_save_efi_objcopy(identity_pe, filepath, args.cc, args.objcopy)
_save_efi_objcopy(identity_pe, filepath, args.cc, args.cflags, args.objcopy)
else:
_save_efi_pefile(identity_pe, filepath)
elif fmt in [
Expand Down

0 comments on commit 747b2f9

Please sign in to comment.