Nordic stack and drivers for the mbed BLE API

Dependents:   Sensen-classic-v8-IAQ_copy_4

Fork of nRF51822 by Nordic Semiconductor

Committer:
amithy
Date:
Fri Nov 10 20:27:44 2017 +0000
Revision:
639:7f459d371b75
Parent:
638:c90ae1400bf2
t

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Vincent Coubard 638:c90ae1400bf2 1 #!/usr/bin/env python
Vincent Coubard 638:c90ae1400bf2 2
Vincent Coubard 638:c90ae1400bf2 3 # Copyright (c) 2015-2016 ARM Limited
Vincent Coubard 638:c90ae1400bf2 4 # SPDX-License-Identifier: Apache-2.0
Vincent Coubard 638:c90ae1400bf2 5 #
Vincent Coubard 638:c90ae1400bf2 6 # Licensed under the Apache License, Version 2.0 (the "License");
Vincent Coubard 638:c90ae1400bf2 7 # you may not use this file except in compliance with the License.
Vincent Coubard 638:c90ae1400bf2 8 # You may obtain a copy of the License at
Vincent Coubard 638:c90ae1400bf2 9 #
Vincent Coubard 638:c90ae1400bf2 10 # http://www.apache.org/licenses/LICENSE-2.0
Vincent Coubard 638:c90ae1400bf2 11 #
Vincent Coubard 638:c90ae1400bf2 12 # Unless required by applicable law or agreed to in writing, software
Vincent Coubard 638:c90ae1400bf2 13 # distributed under the License is distributed on an "AS IS" BASIS,
Vincent Coubard 638:c90ae1400bf2 14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Vincent Coubard 638:c90ae1400bf2 15 # See the License for the specific language governing permissions and
Vincent Coubard 638:c90ae1400bf2 16 # limitations under the License.
Vincent Coubard 638:c90ae1400bf2 17
Vincent Coubard 638:c90ae1400bf2 18 import os, shutil, json, pprint, sys
Vincent Coubard 638:c90ae1400bf2 19 from collections import OrderedDict
Vincent Coubard 638:c90ae1400bf2 20
Vincent Coubard 638:c90ae1400bf2 21 help_text = """
Vincent Coubard 638:c90ae1400bf2 22 Usage: python {} [options] <full-noridc-sdk-path> <nrf51-sdk-yotta-module-path>
Vincent Coubard 638:c90ae1400bf2 23 options: --purge : to delete all existing files and start again
Vincent Coubard 638:c90ae1400bf2 24 --dry-run : to list the files to be copied but not actually copy them
Vincent Coubard 638:c90ae1400bf2 25 """.format(os.path.basename(__file__))
Vincent Coubard 638:c90ae1400bf2 26
Vincent Coubard 638:c90ae1400bf2 27 # exclude path to avoid confusion over files of the same name
Vincent Coubard 638:c90ae1400bf2 28 exclude_path = ["examples", "SVD", "s110", "s120", "s210", "s310", "nrf_soc_nosd", "serialization/connectivity",
Vincent Coubard 638:c90ae1400bf2 29 'components/libraries/hci/config', 'components/libraries/bootloader_dfu/ble_transport']
Vincent Coubard 638:c90ae1400bf2 30
Vincent Coubard 638:c90ae1400bf2 31 def find(name, path):
Vincent Coubard 638:c90ae1400bf2 32 paths = []
Vincent Coubard 638:c90ae1400bf2 33 for root, dirs, files in os.walk(path):
Vincent Coubard 638:c90ae1400bf2 34 if True not in [x in root for x in exclude_path]:
Vincent Coubard 638:c90ae1400bf2 35 if name in files:
Vincent Coubard 638:c90ae1400bf2 36 paths.append(os.path.join(root, name))
Vincent Coubard 638:c90ae1400bf2 37
Vincent Coubard 638:c90ae1400bf2 38 if len(paths) == 0:
Vincent Coubard 638:c90ae1400bf2 39 print "-"*30
Vincent Coubard 638:c90ae1400bf2 40 print "Warning! No {} found!!!!".format(name)
Vincent Coubard 638:c90ae1400bf2 41 print "-"*30
Vincent Coubard 638:c90ae1400bf2 42 return None
Vincent Coubard 638:c90ae1400bf2 43 elif len(paths) > 1:
Vincent Coubard 638:c90ae1400bf2 44 print "-"*30
Vincent Coubard 638:c90ae1400bf2 45 print "Warning! More than one {} found!!!!".format(name)
Vincent Coubard 638:c90ae1400bf2 46 print paths
Vincent Coubard 638:c90ae1400bf2 47 print "-"*30
Vincent Coubard 638:c90ae1400bf2 48 return None
Vincent Coubard 638:c90ae1400bf2 49 else:
Vincent Coubard 638:c90ae1400bf2 50 return paths[0]
Vincent Coubard 638:c90ae1400bf2 51
Vincent Coubard 638:c90ae1400bf2 52 def find_dir(dir_name, path):
Vincent Coubard 638:c90ae1400bf2 53 paths = []
Vincent Coubard 638:c90ae1400bf2 54 for root, dirs, files in os.walk(path):
Vincent Coubard 638:c90ae1400bf2 55 if dir_name in root:
Vincent Coubard 638:c90ae1400bf2 56 for fn in files:
Vincent Coubard 638:c90ae1400bf2 57 paths.append(os.path.join(root, fn))
Vincent Coubard 638:c90ae1400bf2 58 return paths
Vincent Coubard 638:c90ae1400bf2 59
Vincent Coubard 638:c90ae1400bf2 60 if __name__ == "__main__":
Vincent Coubard 638:c90ae1400bf2 61 # define source and destination of copy
Vincent Coubard 638:c90ae1400bf2 62 arg_valid = True
Vincent Coubard 638:c90ae1400bf2 63 if len(sys.argv) not in [3, 4]:
Vincent Coubard 638:c90ae1400bf2 64 arg_valid = False
Vincent Coubard 638:c90ae1400bf2 65 else:
Vincent Coubard 638:c90ae1400bf2 66 src_folder = sys.argv[-2]
Vincent Coubard 638:c90ae1400bf2 67 yt_module_dir = sys.argv[-1]
Vincent Coubard 638:c90ae1400bf2 68
Vincent Coubard 638:c90ae1400bf2 69 for d in [src_folder, yt_module_dir]:
Vincent Coubard 638:c90ae1400bf2 70 if not os.path.isdir(d):
Vincent Coubard 638:c90ae1400bf2 71 arg_valid = False
Vincent Coubard 638:c90ae1400bf2 72 print src_folder, "is not a folder"
Vincent Coubard 638:c90ae1400bf2 73
Vincent Coubard 638:c90ae1400bf2 74 purge = ("--purge" in sys.argv)
Vincent Coubard 638:c90ae1400bf2 75 dry_run = ("--dry-run" in sys.argv)
Vincent Coubard 638:c90ae1400bf2 76
Vincent Coubard 638:c90ae1400bf2 77 if not arg_valid:
Vincent Coubard 638:c90ae1400bf2 78 print help_text
Vincent Coubard 638:c90ae1400bf2 79 sys.exit(1)
Vincent Coubard 638:c90ae1400bf2 80
Vincent Coubard 638:c90ae1400bf2 81 dst_folder = os.path.join(yt_module_dir, "source/nordic_sdk")
Vincent Coubard 638:c90ae1400bf2 82
Vincent Coubard 638:c90ae1400bf2 83 # build a file_list from required_files.txt
Vincent Coubard 638:c90ae1400bf2 84 file_list = []
Vincent Coubard 638:c90ae1400bf2 85 with open("required_files.txt", "r") as fd:
Vincent Coubard 638:c90ae1400bf2 86 for line in fd:
Vincent Coubard 638:c90ae1400bf2 87 line = line.strip()
Vincent Coubard 638:c90ae1400bf2 88 if line.startswith("D "):
Vincent Coubard 638:c90ae1400bf2 89 directory = line.split(" ")[-1]
Vincent Coubard 638:c90ae1400bf2 90 file_list += find_dir(directory, src_folder)
Vincent Coubard 638:c90ae1400bf2 91 elif not line.startswith("#") and line != '':
Vincent Coubard 638:c90ae1400bf2 92 fn = os.path.basename(line).strip()
Vincent Coubard 638:c90ae1400bf2 93 fn = find(fn, src_folder)
Vincent Coubard 638:c90ae1400bf2 94 file_list.append(fn)
Vincent Coubard 638:c90ae1400bf2 95
Vincent Coubard 638:c90ae1400bf2 96 # remove everything from the destination folder
Vincent Coubard 638:c90ae1400bf2 97 if purge and not dry_run and os.path.exists(dst_folder):
Vincent Coubard 638:c90ae1400bf2 98 shutil.rmtree(dst_folder)
Vincent Coubard 638:c90ae1400bf2 99
Vincent Coubard 638:c90ae1400bf2 100 # copy files
Vincent Coubard 638:c90ae1400bf2 101 extra_includes = []
Vincent Coubard 638:c90ae1400bf2 102 for src in file_list:
Vincent Coubard 638:c90ae1400bf2 103 if src:
Vincent Coubard 638:c90ae1400bf2 104 rel_dst = os.path.relpath(src, src_folder)
Vincent Coubard 638:c90ae1400bf2 105 dst = os.path.join(dst_folder, rel_dst)
Vincent Coubard 638:c90ae1400bf2 106 print src, "->", dst
Vincent Coubard 638:c90ae1400bf2 107
Vincent Coubard 638:c90ae1400bf2 108 directory = os.path.dirname(dst)
Vincent Coubard 638:c90ae1400bf2 109 if not os.path.exists(directory):
Vincent Coubard 638:c90ae1400bf2 110 print "Creating directory:", directory
Vincent Coubard 638:c90ae1400bf2 111 if not dry_run:
Vincent Coubard 638:c90ae1400bf2 112 os.makedirs(directory)
Vincent Coubard 638:c90ae1400bf2 113 if not os.path.isfile(dst):
Vincent Coubard 638:c90ae1400bf2 114 print "Copying file", dst
Vincent Coubard 638:c90ae1400bf2 115 if not dry_run:
Vincent Coubard 638:c90ae1400bf2 116 shutil.copyfile(src, dst)
Vincent Coubard 638:c90ae1400bf2 117
Vincent Coubard 638:c90ae1400bf2 118 # build a list of extra includes to be added to module.json
Vincent Coubard 638:c90ae1400bf2 119 if dst.endswith(".h"):
Vincent Coubard 638:c90ae1400bf2 120 inc_rel_path = os.path.relpath(dst, yt_module_dir)
Vincent Coubard 638:c90ae1400bf2 121 inc_dir_path = os.path.dirname(inc_rel_path)
Vincent Coubard 638:c90ae1400bf2 122 if inc_dir_path not in extra_includes:
Vincent Coubard 638:c90ae1400bf2 123 extra_includes.append(inc_dir_path)
Vincent Coubard 638:c90ae1400bf2 124
Vincent Coubard 638:c90ae1400bf2 125 # write extraIncludes in the module.json file
Vincent Coubard 638:c90ae1400bf2 126 mod_json = os.path.join(yt_module_dir, "module.json")
Vincent Coubard 638:c90ae1400bf2 127 print "-"*30
Vincent Coubard 638:c90ae1400bf2 128 print "Writing extra_includes to {}".format(mod_json)
Vincent Coubard 638:c90ae1400bf2 129 print "-"*30
Vincent Coubard 638:c90ae1400bf2 130 for n in sorted(extra_includes):
Vincent Coubard 638:c90ae1400bf2 131 print n
Vincent Coubard 638:c90ae1400bf2 132
Vincent Coubard 638:c90ae1400bf2 133 if not dry_run:
Vincent Coubard 638:c90ae1400bf2 134 with open(mod_json, 'r+') as fd:
Vincent Coubard 638:c90ae1400bf2 135 jobj = json.loads(fd.read(), object_pairs_hook=OrderedDict)
Vincent Coubard 638:c90ae1400bf2 136 jobj['extraIncludes'] = sorted(extra_includes)
Vincent Coubard 638:c90ae1400bf2 137 jdump = json.dumps(jobj, indent=2, separators=(',', ': '))
Vincent Coubard 638:c90ae1400bf2 138 fd.seek(0)
Vincent Coubard 638:c90ae1400bf2 139 fd.write(jdump)
Vincent Coubard 638:c90ae1400bf2 140 fd.write("\n")
Vincent Coubard 638:c90ae1400bf2 141 fd.truncate()