Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Compare sdk_config files

Hi!

What is the easiest way to compare two sdk_config files? Some tools, etc. Why do I need it:

  1. My idea is to use "$NRF_SDK/config/nrf52840/config/sdk_config.h" as base config and don't change it. All changed parameters ("diff") put into "app_config.h". Usually it's not a lot of changes compared to the base configuration, but if i need to see it in "modified" (compared to the base) sdk_config - it's very hard. Now I have projects with "modified" sdk_config files, I want to get "diff". 
  2. It would be useful for sdk examples to see "diff".

I hope my explanation is understandable. Thanks for answers and suggestions in advance.

  • Yes, at some point in the future we can only hope a major SDK update will enforce users having to upgrade their apps to non-legacy ...  

  • Your post should be required reading for all Nordic users. This is still a problem in SDK 17. Absolutely horrible architecture. And telling people that they can use an app_config.h file when they really can't?

    Nordic, if you really want to support legacy systems, you should have a separate include file for that, and document it.

    Also, this architecture makes it extremely difficult to port a project to a newer SDK. 

  • Here is a Python script to show the difference between two sdk_config.h files:

    import re
    from argparse import ArgumentParser
    from pprint import pprint
    
    arg_parser = ArgumentParser(description="Nordic SDK sdk_config.h diff utility")
    arg_parser.add_argument('-o', '--output', default="def")
    arg_parser.add_argument('-i2', '--ignore2', action='store_true')
    arg_parser.add_argument('file1')
    arg_parser.add_argument('file2')
    args = arg_parser.parse_args()
    
    pattern = re.compile(r'\s?#define\s+(\w*)\s+(\w*)\s*')
    
    def read_file(name):
    	defs = {}
    	file = open(name, "r")
    	for line in file:
    		match = pattern.match(line)
    		if match:
    			if match.group(1) == "SDK_CONFIG_H":
    				continue
    			defs[match.group(1)] = match.group(2)
    	return defs
    
    d1 = read_file(args.file1)
    d2 = read_file(args.file2)
    
    diff = {}
    
    # find items in d1 which are different in d2, including non existent
    for k, v1 in d1.items():
    	v2 = d2.get(k)
    	if v2 != v1:
    		diff[k] = [v1, v2]
    
    # find items which are in d2 but not d1
    for k, v2 in d2.items():
    	v1 = d1.get(k)
    	if not v1:
    		diff[k] = [v1, v2]
    
    # output
    if args.output == "pprint":
    	pprint(diff)
    elif args.output == "list":
    	for k in sorted(diff):
    		print(k, diff[k])
    elif args.output == "def":
    	for k in sorted(diff):
    		if diff[k][0] and diff[k][1]:
    			print("#define", k, diff[k][1], "// was:", diff[k][0])
    		elif not diff[k][0]:
    			print("#define", k, diff[k][1], "// not set in file 1")
    		elif not diff[k][1] and diff[k][0] != "0":
    			if not args.ignore2:
    				print("#define", k, "0 // not set in file 2, was:", diff[k][0])

  • I made a python script to pretty print the differences between sdk_config.h files.

    It looks like this:

    $ ./compare_sdkconfig.py examples/sdk_config_1.h examples/sdk_config_2.h
    ╒════════════════════════════════════╤═══════════════════╤═══════════════════╕
    │ Define                             │   examples/sdk_co │ examples/sdk_co   │
    │                                    │          nfig_1.h │ nfig_2.h          │
    ╞════════════════════════════════════╪═══════════════════╪═══════════════════╡
    │ NRF_RADIO_ANTENNA_COUNT            │                12 │ 3                 │
    ├────────────────────────────────────┼───────────────────┼───────────────────┤
    │ DTM_ANOMALY_172_TIMER_IRQ_PRIORITY │                 2 │ None              │
    ╘════════════════════════════════════╧═══════════════════╧═══════════════════╛

    You can find the script here: github.com/.../nrf_sdk_sdkconfig_diff

Related