def main(): args = parse_command_line() root_dir = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) config.config_init(args.version, args.revision, args.version_name, args.sdk_root_path, args.sdk_version, root_dir) sdk = Sdk(config.ARTIFACTS_ROOT, config.SDK_VERSION) # Assumes that source root dir is .. since build.py is ran in directory build_scripts patch_dir = os.path.join(root_dir, 'patches') try: if args.clean: clean.clean_all(sdk) if args.create_patch_filename: sdk.prepare_sdk() old_path = sdk.path tempdir_path = None try: tempdir_path = tempfile.mkdtemp(prefix='nordicsemi') sdk.path = os.path.join(tempdir_path, "orig_sdk") sdk.prepare_sdk() p = Patch(patch_dir=patch_dir, apply_patch_root_dir=sdk.path, strip=0 # The old patches has 4 more components ) p.create_patch(tempdir_path, old_path, os.path.join(patch_dir, args.create_patch_filename)) finally: sdk.path = old_path shutil.rmtree(tempdir_path) if args.dependencies: sdk.prepare_sdk() patch_tag_file = posixpath.join(sdk.path, ".patched") if os.path.exists(patch_tag_file): logger.info("Patches are already applied to this SDK, skipping patching") else: open(patch_tag_file, 'w').close() p = Patch(patch_dir=patch_dir, apply_patch_root_dir=sdk.path, strip=0 # The old patches has 4 more components ) p.apply_patches(dry_run=False) if args.build: serialization_dll.build() if args.test: error_code = tests.do_testing() if error_code != 0: return error_code if args.package: package_release() if args.examples: examples.build_examples() except Exception, ex: logger.exception(ex) return -1