auto-formatted target.json

pull/1830/head
Jimmy Brisson 2016-06-01 14:37:49 -05:00
parent ca8ae5c5d6
commit 76e6c885a2
2 changed files with 36 additions and 52 deletions

View File

@ -37,9 +37,7 @@
}, },
"LPCTarget": { "LPCTarget": {
"inherits": ["Target"], "inherits": ["Target"],
"post_binary_hook": { "post_binary_hook": {"function": "LPCTargetCode.lpc_patch"},
"function": "LPCTargetCode.lpc_patch"
},
"public": false "public": false
}, },
"LPC11C24": { "LPC11C24": {
@ -1491,13 +1489,7 @@
"SAMR21G18A": { "SAMR21G18A": {
"inherits": ["Target"], "inherits": ["Target"],
"core": "Cortex-M0+", "core": "Cortex-M0+",
"macros": [ "macros": ["__SAMR21G18A__", "I2C_MASTER_CALLBACK_MODE=true", "EXTINT_CALLBACK_MODE=true", "USART_CALLBACK_MODE=true", "TC_ASYNC=true"],
"__SAMR21G18A__",
"I2C_MASTER_CALLBACK_MODE=true",
"EXTINT_CALLBACK_MODE=true",
"USART_CALLBACK_MODE=true",
"TC_ASYNC=true"
],
"extra_labels": ["Atmel", "SAM_CortexM0P", "SAMR21"], "extra_labels": ["Atmel", "SAM_CortexM0P", "SAMR21"],
"supported_toolchains": ["GCC_ARM", "ARM", "uARM"], "supported_toolchains": ["GCC_ARM", "ARM", "uARM"],
"progen": {"target": "samr21g18a"} "progen": {"target": "samr21g18a"}
@ -1505,13 +1497,7 @@
"SAMD21J18A": { "SAMD21J18A": {
"inherits": ["Target"], "inherits": ["Target"],
"core": "Cortex-M0+", "core": "Cortex-M0+",
"macros": [ "macros": ["__SAMD21J18A__", "I2C_MASTER_CALLBACK_MODE=true", "EXTINT_CALLBACK_MODE=true", "USART_CALLBACK_MODE=true", "TC_ASYNC=true"],
"__SAMD21J18A__",
"I2C_MASTER_CALLBACK_MODE=true",
"EXTINT_CALLBACK_MODE=true",
"USART_CALLBACK_MODE=true",
"TC_ASYNC=true"
],
"extra_labels": ["Atmel", "SAM_CortexM0P", "SAMD21"], "extra_labels": ["Atmel", "SAM_CortexM0P", "SAMD21"],
"supported_toolchains": ["GCC_ARM", "ARM", "uARM"], "supported_toolchains": ["GCC_ARM", "ARM", "uARM"],
"progen": {"target": "samd21j18a"} "progen": {"target": "samd21j18a"}
@ -1519,13 +1505,7 @@
"SAMD21G18A": { "SAMD21G18A": {
"inherits": ["Target"], "inherits": ["Target"],
"core": "Cortex-M0+", "core": "Cortex-M0+",
"macros": [ "macros": ["__SAMD21G18A__", "I2C_MASTER_CALLBACK_MODE=true", "EXTINT_CALLBACK_MODE=true", "USART_CALLBACK_MODE=true", "TC_ASYNC=true"],
"__SAMD21G18A__",
"I2C_MASTER_CALLBACK_MODE=true",
"EXTINT_CALLBACK_MODE=true",
"USART_CALLBACK_MODE=true",
"TC_ASYNC=true"
],
"extra_labels": ["Atmel", "SAM_CortexM0P", "SAMD21"], "extra_labels": ["Atmel", "SAM_CortexM0P", "SAMD21"],
"supported_toolchains": ["GCC_ARM", "ARM", "uARM"], "supported_toolchains": ["GCC_ARM", "ARM", "uARM"],
"progen": {"target": "samd21g18a"} "progen": {"target": "samd21g18a"}
@ -1533,13 +1513,7 @@
"SAML21J18A": { "SAML21J18A": {
"inherits": ["Target"], "inherits": ["Target"],
"core": "Cortex-M0+", "core": "Cortex-M0+",
"macros": [ "macros": ["__SAML21J18A__", "I2C_MASTER_CALLBACK_MODE=true", "EXTINT_CALLBACK_MODE=true", "USART_CALLBACK_MODE=true", "TC_ASYNC=true"],
"__SAML21J18A__",
"I2C_MASTER_CALLBACK_MODE=true",
"EXTINT_CALLBACK_MODE=true",
"USART_CALLBACK_MODE=true",
"TC_ASYNC=true"
],
"extra_labels": ["Atmel", "SAM_CortexM0P", "SAML21"], "extra_labels": ["Atmel", "SAM_CortexM0P", "SAML21"],
"supported_toolchains": ["GCC_ARM", "ARM", "uARM"], "supported_toolchains": ["GCC_ARM", "ARM", "uARM"],
"progen": {"target": "samr21j18a"}, "progen": {"target": "samr21j18a"},

View File

@ -94,6 +94,18 @@ def parse_attributes(path) :
m = re.match(attr_matcher, line) m = re.match(attr_matcher, line)
if m: yield m.group(1) if m: yield m.group(1)
remove_matcher = re.compile('^#define\W+DEVICE_(\w+)\W+[10].*$')
def remove_attributes(path) :
with open(path) as input :
remainder = filter(lambda l: not re.match(remove_matcher, l), input)
with open(path,"wb") as output :
output.truncate(0)
output.write("// The 'provides' section in 'target.json' is now used"+
" to create the device's hardware preprocessor switches.\n")
output.write("// Check the 'provides' section of the target description"+
" in 'targets.json' for more details.\n")
output.writelines(remainder)
def user_select(things, message) : def user_select(things, message) :
print(message) print(message)
for thing, number in zip(things, range(len(things))): for thing, number in zip(things, range(len(things))):
@ -148,10 +160,8 @@ def add_to_targets(targets, device_file, verbose=False, remove=False) :
for t in target : for t in target :
targets[t]["features"] = sorted(list(set(targets[t].setdefault("features",[]) + attrs))) targets[t]["features"] = sorted(list(set(targets[t].setdefault("features",[]) + attrs)))
if verbose : print("[VERBOSE] target {} now features {}".format(t, attrs)) if verbose : print("[VERBOSE] target {} now features {}".format(t, attrs))
if remove : if remove is True:
global git_processes remove_attributes(device_file)
git = Popen(['git', 'rm', device_file])
git_processes.append(git)
if __name__ == '__main__' : if __name__ == '__main__' :
import argparse import argparse
@ -166,8 +176,8 @@ if __name__ == '__main__' :
' to convert from device.h format to a piece of targets.json') ' to convert from device.h format to a piece of targets.json')
parser.add_argument('-v', '--verbose', action='store_true', parser.add_argument('-v', '--verbose', action='store_true',
help="print out every target that is updated in the targets.json") help="print out every target that is updated in the targets.json")
parser.add_argument('-g', '--git-rm', action='store_true', parser.add_argument('-r', '--rm', action='store_true',
help="call git rm on every device.h file") help="remove the used attributes from a device.h file")
args = parser.parse_args() args = parser.parse_args()
if not args.target and not args.file and not args.all : if not args.target and not args.file and not args.all :
print("[WARNING] no action specified; auto-formatting targets.json") print("[WARNING] no action specified; auto-formatting targets.json")
@ -186,17 +196,17 @@ if __name__ == '__main__' :
for target in args.target : for target in args.target :
device_file = find(target, os.curdir) device_file = find(target, os.curdir)
if device_file : if device_file :
add_to_targets(targets, device_file, verbose=args.verbose, remove=args.git_rm) add_to_targets(targets, device_file, verbose=args.verbose, remove=args.rm)
else : else :
print("[WARNING] could not locate a device file for target {}".format(target)) print("[WARNING] could not locate a device file for target {}".format(target))
if args.file : if args.file :
for file in args.file : for file in args.file :
add_to_targets(targets, file, verbose=args.verbose, remove=args.git_rm) add_to_targets(targets, file, verbose=args.verbose, remove=args.rm)
if args.all : if args.all :
for file in find_all_devices(os.curdir, verbose=args.verbose) : for file in find_all_devices(os.curdir, verbose=args.verbose) :
add_to_targets(targets, file, verbose=args.verbose, remove=args.git_rm) add_to_targets(targets, file, verbose=args.verbose, remove=args.rm)
dump(targets_file_name, targets) dump(targets_file_name, targets)