Spdk/scripts/genconfig.py
paul luse 17538bdc67 add (c) and SPDX header to python files as needed
per Intel policy to include file commit date using git cmd
below.  The policy does not apply to non-Intel (C) notices.

git log --follow -C90% --format=%ad --date default <file> | tail -1

and then pull just the year from the result.

Intel copyrights were not added to files where Intel either had
no contribution ot the contribution lacked substance (ie license
header updates, formatting changes, etc)

Note that several files in this patch didn't end the license/(c)
block with a blank comment line so these were added as the vast
majority of files do have this last blank line.  Simply there for
consistency.

Signed-off-by: paul luse <paul.e.luse@intel.com>
Change-Id: I6cd3f18d1b469d5ef249d26ddb2923ca6b970bd4
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15208
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
2022-11-10 08:28:53 +00:00

51 lines
1.4 KiB
Python
Executable File

#!/usr/bin/env python3
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (C) 2016 Intel Corporation
# All rights reserved.
#
import os
import re
import sys
comment = re.compile(r'^\s*#')
assign = re.compile(r'^\s*([a-zA-Z0-9_]+)\s*(\?)?=\s*([^#]*)')
args = os.environ.copy()
for arg in sys.argv:
m = assign.match(arg)
if m:
var = m.group(1).strip()
val = m.group(3).strip()
args[var] = val
defs = {}
try:
with open("mk/config.mk") as f:
for line in f:
line = line.strip()
if not comment.match(line):
m = assign.match(line)
if m:
var = m.group(1).strip()
default = m.group(3).strip()
val = default
if var in args:
val = args[var]
if default.lower() == 'y' or default.lower() == 'n':
if val.lower() == 'y':
defs["SPDK_{0}".format(var)] = 1
else:
defs["SPDK_{0}".format(var)] = 0
else:
strval = val.replace('"', '\"')
defs["SPDK_{0}".format(var)] = strval
except IOError:
print("mk/config.mk not found")
for key, value in sorted(defs.items()):
if value == 0:
print("#undef {0}".format(key))
else:
print("#define {0} {1}".format(key, value))