mirror of https://github.com/ARMmbed/mbed-os.git
				
				
				
			Merge pull request #3208 from bridadan/examples-clone-deploy
[example tests] Adding a clone and a deploy step to allow optimizations in CI.pull/3220/head
						commit
						79abaab02e
					
				| 
						 | 
					@ -26,6 +26,10 @@ def main():
 | 
				
			||||||
    subparsers = parser.add_subparsers()
 | 
					    subparsers = parser.add_subparsers()
 | 
				
			||||||
    import_cmd = subparsers.add_parser("import")
 | 
					    import_cmd = subparsers.add_parser("import")
 | 
				
			||||||
    import_cmd.set_defaults(fn=do_import)
 | 
					    import_cmd.set_defaults(fn=do_import)
 | 
				
			||||||
 | 
					    clone_cmd = subparsers.add_parser("clone")
 | 
				
			||||||
 | 
					    clone_cmd.set_defaults(fn=do_clone)
 | 
				
			||||||
 | 
					    deploy_cmd = subparsers.add_parser("deploy")
 | 
				
			||||||
 | 
					    deploy_cmd.set_defaults(fn=do_deploy)
 | 
				
			||||||
    version_cmd = subparsers.add_parser("tag")
 | 
					    version_cmd = subparsers.add_parser("tag")
 | 
				
			||||||
    version_cmd.add_argument("tag")
 | 
					    version_cmd.add_argument("tag")
 | 
				
			||||||
    version_cmd.set_defaults(fn=do_versionning)
 | 
					    version_cmd.set_defaults(fn=do_versionning)
 | 
				
			||||||
| 
						 | 
					@ -64,6 +68,18 @@ def do_import(_, config):
 | 
				
			||||||
    return 0
 | 
					    return 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def do_clone(_, config):
 | 
				
			||||||
 | 
					    """Do the clone step of this process"""
 | 
				
			||||||
 | 
					    lib.clone_repos(config)
 | 
				
			||||||
 | 
					    return 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def do_deploy(_, config):
 | 
				
			||||||
 | 
					    """Do the deploy step of this process"""
 | 
				
			||||||
 | 
					    lib.deploy_repos(config)
 | 
				
			||||||
 | 
					    return 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def do_compile(args, config):
 | 
					def do_compile(args, config):
 | 
				
			||||||
    """Do the compile step"""
 | 
					    """Do the compile step"""
 | 
				
			||||||
    results = {}
 | 
					    results = {}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -136,35 +136,79 @@ def get_repo_list(example):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Args:
 | 
					    Args:
 | 
				
			||||||
    example - Example for which the repo list is requested
 | 
					    example - Example for which the repo list is requested
 | 
				
			||||||
    repos - The list of repos contained within that example in the json file 
 | 
					    repos - The list of repos and types contained within that example in the json file
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    repos = []
 | 
					    repos = []
 | 
				
			||||||
    if len(example['mbed']) > 0:
 | 
					    if len(example['mbed']) > 0:
 | 
				
			||||||
        for repo in example['mbed']:
 | 
					        for repo in example['mbed']:
 | 
				
			||||||
            repos.append(repo)
 | 
					            repos.append({
 | 
				
			||||||
 | 
					                'repo': repo,
 | 
				
			||||||
 | 
					                'type': 'hg'
 | 
				
			||||||
 | 
					            })
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        repos.append(example['github'])
 | 
					        repos.append({
 | 
				
			||||||
 | 
					            'repo': example['github'],
 | 
				
			||||||
 | 
					            'type': 'git'
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
    return repos
 | 
					    return repos
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def source_repos(config):
 | 
					def source_repos(config):
 | 
				
			||||||
    """ Clones each of the repos associated with the specific examples name from the 
 | 
					    """ Imports each of the repos and its dependencies (.lib files) associated
 | 
				
			||||||
        json config file. Note if there is already a clone of the repo then it will first
 | 
					        with the specific examples name from the json config file. Note if
 | 
				
			||||||
        be removed to ensure a clean, up to date cloning.
 | 
					        there is already a clone of the repo then it will first be removed to
 | 
				
			||||||
 | 
					        ensure a clean, up to date cloning.
 | 
				
			||||||
    Args:
 | 
					    Args:
 | 
				
			||||||
    config - the json object imported from the file. 
 | 
					    config - the json object imported from the file. 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    print("\nImporting example repos....\n")
 | 
					    print("\nImporting example repos....\n")
 | 
				
			||||||
    for example in config['examples']:
 | 
					    for example in config['examples']:
 | 
				
			||||||
        for repo in get_repo_list(example):
 | 
					        for repo_info in get_repo_list(example):
 | 
				
			||||||
            name = basename(repo)
 | 
					            name = basename(repo_info['repo'])
 | 
				
			||||||
            if os.path.exists(name):
 | 
					            if os.path.exists(name):
 | 
				
			||||||
                print("'%s' example directory already exists. Deleting..." % name)
 | 
					                print("'%s' example directory already exists. Deleting..." % name)
 | 
				
			||||||
                rmtree(name)
 | 
					                rmtree(name)
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
            subprocess.call(["mbed-cli", "import", repo])
 | 
					            subprocess.call(["mbed-cli", "import", repo_info['repo']])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def clone_repos(config):
 | 
				
			||||||
 | 
					    """ Clones each of the repos associated with the specific examples name from the
 | 
				
			||||||
 | 
					        json config file. Note if there is already a clone of the repo then it will first
 | 
				
			||||||
 | 
					        be removed to ensure a clean, up to date cloning.
 | 
				
			||||||
 | 
					    Args:
 | 
				
			||||||
 | 
					    config - the json object imported from the file.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    print("\nCloning example repos....\n")
 | 
				
			||||||
 | 
					    for example in config['examples']:
 | 
				
			||||||
 | 
					        for repo_info in get_repo_list(example):
 | 
				
			||||||
 | 
					            name = basename(repo_info['repo'])
 | 
				
			||||||
 | 
					            if os.path.exists(name):
 | 
				
			||||||
 | 
					                print("'%s' example directory already exists. Deleting..." % name)
 | 
				
			||||||
 | 
					                rmtree(name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            subprocess.call([repo_info['type'], "clone", repo_info['repo']])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def deploy_repos(config):
 | 
				
			||||||
 | 
					    """ If the example directory exists as provided by the json config file,
 | 
				
			||||||
 | 
					        pull in the examples dependencies by using `mbed-cli deploy`.
 | 
				
			||||||
 | 
					    Args:
 | 
				
			||||||
 | 
					    config - the json object imported from the file.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    print("\nDeploying example repos....\n")
 | 
				
			||||||
 | 
					    for example in config['examples']:
 | 
				
			||||||
 | 
					        for repo_info in get_repo_list(example):
 | 
				
			||||||
 | 
					            name = basename(repo_info['repo'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if os.path.exists(name):
 | 
				
			||||||
 | 
					                os.chdir(name)
 | 
				
			||||||
 | 
					                subprocess.call(["mbed-cli", "deploy"])
 | 
				
			||||||
 | 
					                os.chdir("..")
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
 | 
					                print("'%s' example directory doesn't exist. Skipping..." % name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_num_failures(results, export=False):
 | 
					def get_num_failures(results, export=False):
 | 
				
			||||||
| 
						 | 
					@ -220,8 +264,8 @@ def export_repos(config, ides):
 | 
				
			||||||
        exported = True
 | 
					        exported = True
 | 
				
			||||||
        pass_status = True
 | 
					        pass_status = True
 | 
				
			||||||
        if example['export']:
 | 
					        if example['export']:
 | 
				
			||||||
            for repo in get_repo_list(example):
 | 
					            for repo_info in get_repo_list(example):
 | 
				
			||||||
                example_project_name = basename(repo)
 | 
					                example_project_name = basename(repo_info['repo'])
 | 
				
			||||||
                os.chdir(example_project_name)
 | 
					                os.chdir(example_project_name)
 | 
				
			||||||
                # Check that the target, IDE, and features combinations are valid and return a
 | 
					                # Check that the target, IDE, and features combinations are valid and return a
 | 
				
			||||||
                # list of valid combinations to work through
 | 
					                # list of valid combinations to work through
 | 
				
			||||||
| 
						 | 
					@ -299,8 +343,9 @@ def compile_repos(config, toolchains):
 | 
				
			||||||
            if len(example['toolchains']) > 0:
 | 
					            if len(example['toolchains']) > 0:
 | 
				
			||||||
                toolchains = example['toolchains']
 | 
					                toolchains = example['toolchains']
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
            for repo in get_repo_list(example):
 | 
					            for repo_info in get_repo_list(example):
 | 
				
			||||||
                os.chdir(basename(repo))
 | 
					                name = basename(repo_info['repo'])
 | 
				
			||||||
 | 
					                os.chdir(name)
 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
                # Check that the target, toolchain and features combinations are valid and return a 
 | 
					                # Check that the target, toolchain and features combinations are valid and return a 
 | 
				
			||||||
                # list of valid combinations to work through
 | 
					                # list of valid combinations to work through
 | 
				
			||||||
| 
						 | 
					@ -309,7 +354,7 @@ def compile_repos(config, toolchains):
 | 
				
			||||||
                    proc = subprocess.Popen(["mbed-cli", "compile", "-t", toolchain,
 | 
					                    proc = subprocess.Popen(["mbed-cli", "compile", "-t", toolchain,
 | 
				
			||||||
                                             "-m", target, "--silent"])
 | 
					                                             "-m", target, "--silent"])
 | 
				
			||||||
                    proc.wait()
 | 
					                    proc.wait()
 | 
				
			||||||
                    example_summary = "{} {} {}".format(basename(repo), target, toolchain)
 | 
					                    example_summary = "{} {} {}".format(name, target, toolchain)
 | 
				
			||||||
                    if proc.returncode:
 | 
					                    if proc.returncode:
 | 
				
			||||||
                        failures.append(example_summary)
 | 
					                        failures.append(example_summary)
 | 
				
			||||||
                    else:
 | 
					                    else:
 | 
				
			||||||
| 
						 | 
					@ -339,8 +384,8 @@ def update_mbedos_version(config, tag):
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    print("Updating mbed-os in examples to version %s\n" % tag)
 | 
					    print("Updating mbed-os in examples to version %s\n" % tag)
 | 
				
			||||||
    for example in config['examples']:
 | 
					    for example in config['examples']:
 | 
				
			||||||
        for repo in get_repo_list(example):
 | 
					        for repo_info in get_repo_list(example):
 | 
				
			||||||
            update_dir =  basename(repo) + "/mbed-os"
 | 
					            update_dir =  basename(repo_info['repo']) + "/mbed-os"
 | 
				
			||||||
            print("\nChanging dir to %s\n" % update_dir)
 | 
					            print("\nChanging dir to %s\n" % update_dir)
 | 
				
			||||||
            os.chdir(update_dir)
 | 
					            os.chdir(update_dir)
 | 
				
			||||||
            subprocess.call(["mbed-cli", "update", tag, "--clean"])
 | 
					            subprocess.call(["mbed-cli", "update", tag, "--clean"])
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue