From 85ee266ab2147978b5ebeb50037c056f6e7e6d5e Mon Sep 17 00:00:00 2001 From: Emilio Monti Date: Thu, 30 May 2013 18:22:41 +0100 Subject: [PATCH] Add scripts to sinchronize mbed.org libraries with mbed SDK --- workspace_tools/libraries.py | 12 ++--- workspace_tools/paths.py | 7 ++- workspace_tools/synch.py | 100 +++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 10 deletions(-) create mode 100644 workspace_tools/synch.py diff --git a/workspace_tools/libraries.py b/workspace_tools/libraries.py index e4af53002e..894f4cfc0d 100644 --- a/workspace_tools/libraries.py +++ b/workspace_tools/libraries.py @@ -13,9 +13,9 @@ LIBRARIES = [ { "id": "NXP_mbed", "name": "mbed", - "source_dir": [join(VENDOR_NXP, "capi"), MBED_CAPI, MBED_CPP], + "source_dir": [join(VENDOR_NXP, "capi"), MBED_SRC], "build_dir": MBED_LIBRARIES, - "dependencies": [MBED_LIBRARIES], + "dependencies": [MBED_LIBRARIES, MBED_SRC], "supported": DEFAULT_SUPPORT }, # ARM @@ -28,9 +28,9 @@ LIBRARIES = [ { "id": "ARM_mbed", "name": "mbed", - "source_dir": [join(VENDOR_ARM, "capi"), MBED_CAPI, MBED_CPP], + "source_dir": [join(VENDOR_ARM, "capi"), MBED_SRC], "build_dir": MBED_LIBRARIES, - "dependencies": [MBED_LIBRARIES], + "dependencies": [MBED_LIBRARIES, MBED_SRC], "supported": DEFAULT_SUPPORT }, # Freescale @@ -43,9 +43,9 @@ LIBRARIES = [ { "id": "Freescale_mbed", "name": "mbed", - "source_dir": [join(VENDOR_FREESCALE, "capi"), MBED_CAPI, MBED_CPP], + "source_dir": [join(VENDOR_FREESCALE, "capi"), MBED_SRC], "build_dir": MBED_LIBRARIES, - "dependencies": [MBED_LIBRARIES], + "dependencies": [MBED_LIBRARIES, MBED_SRC], "supported": DEFAULT_SUPPORT }, diff --git a/workspace_tools/paths.py b/workspace_tools/paths.py index 9a31c57bae..b760fb2999 100644 --- a/workspace_tools/paths.py +++ b/workspace_tools/paths.py @@ -11,8 +11,7 @@ TOOLS_DATA = join(TOOLS, "data") # mbed libraries MBED_BASE = join(LIB_DIR, "mbed") -MBED_CAPI = join(MBED_BASE, "capi") -MBED_CPP = join(MBED_BASE, "cpp") +MBED_SRC = join(MBED_BASE, "src") MBED_RPC = join(MBED_BASE, "rpc") # Vendors directories @@ -37,12 +36,12 @@ RTOS_LIBRARIES = join(BUILD_DIR, "rtos") # TCP/IP NET = join(LIB_DIR, "net") -ETH_SOURCES = join(NET, "EthernetInterface") +ETH_SOURCES = join(NET, "eth") LWIP_SOURCES = join(NET, "lwip") VODAFONE_SOURCES = join(NET, "VodafoneUSBModem") NET_LIBRARIES = join(BUILD_DIR, "net") -ETH_LIBRARY = join(NET_LIBRARIES, "EthernetInterface") +ETH_LIBRARY = join(NET_LIBRARIES, "eth") VODAFONE_LIBRARY = join(NET_LIBRARIES, "VodafoneUSBModem") # FS diff --git a/workspace_tools/synch.py b/workspace_tools/synch.py new file mode 100644 index 0000000000..9af25b2934 --- /dev/null +++ b/workspace_tools/synch.py @@ -0,0 +1,100 @@ +""" One repository to update them all +On mbed.org the mbed SDK is split up in multiple repositories, this script takes +care of updating them all. +""" +import sys +from copy import copy +from os import walk, remove, makedirs +from os.path import join, abspath, dirname, relpath, exists, splitext +from shutil import copyfile + +ROOT = abspath(join(dirname(__file__), "..")) +sys.path.append(ROOT) + +from workspace_tools.settings import MBED_ORG_PATH, MBED_ORG_USER +from workspace_tools.paths import LIB_DIR +from workspace_tools.utils import cmd + + +MBED_OFFICIAL = "http://217.140.101.22/users/mbed_official/code/%s/" + +REPOSITORIES = ( + ("mbed-src" , "mbed/src"), + ("mbed-NXP" , "mbed/vendor/NXP"), + ("mbed-Freescale", "mbed/vendor/Freescale"), + ("mbed-rpc" , "mbed/rpc"), + + ("mbed-rtos", "rtos"), + ("mbed-dsp" , "dsp"), + + ("lwip" , "net/lwip/lwip"), + ("lwip-sys", "net/lwip/lwip-sys"), + ("Socket" , "net/lwip/Socket"), + + ("lwip-eth" , "net/eth/lwip-eth"), + ("EthernetInterface", "net/eth/EthernetInterface"), + + ("USBDevice", "USBDevice"), + ("USBHost", "USBHost"), +) + + +def synch_repositories(repositories): + if not exists(MBED_ORG_PATH): + makedirs(MBED_ORG_PATH) + + for remote, local in repositories: + print '\n=== Updating "%s" ===' % remote + remote_path = join(MBED_ORG_PATH, remote) + local_path = join(LIB_DIR, local) + + # checkout remote repository + if not exists(remote_path): + cmd(['hg', 'clone', MBED_OFFICIAL % remote], cwd=MBED_ORG_PATH) + + # copy files from local to remote + for root, dirs, files in walk(local_path): + for d in copy(dirs): + if d.startswith('.'): + dirs.remove(d) + + for file in files: + if splitext(file)[1] == '.json': continue + + local_file = join(root, file) + rel_path = relpath(local_file, local_path) + remote_file = join(remote_path, rel_path) + + remote_dir = dirname(remote_file) + if not exists(remote_dir): + makedirs(remote_dir) + + copyfile(local_file, remote_file) + + # remove remote files that do not exist in local + for root, dirs, files in walk(remote_path): + for d in copy(dirs): + if d.startswith('.'): + dirs.remove(d) + + for file in files: + if splitext(file)[1] == '.lib': continue + + remote_file = join(root, file) + rel_path = relpath(remote_file, remote_path) + local_file = join(local_path, rel_path) + if not exists(local_file): + remove(remote_file) + print "remove: %s" % remote_file + + # Actual Mercurial synch + cmd(['hg', 'addremove'], cwd=remote_path) + cmd(['hg', 'status'], verbose=True, cwd=remote_path) + commit = raw_input("Do you want to commit and push? Y/N: ") + if commit == 'Y': + cmd(['hg', 'commit', '-u', MBED_ORG_USER], verbose=True, cwd=remote_path) + cmd(['hg', 'push'], verbose=True, cwd=remote_path) + + +if __name__ == '__main__': + synch_repositories(REPOSITORIES)