From 7b26abe69c353d4f70adca27c4625e3c77c74684 Mon Sep 17 00:00:00 2001 From: alichinese Date: Wed, 23 Nov 2022 14:40:51 +0800 Subject: [PATCH] compile: add script to create manifest xml * add a python script named manifest.py to create manifest.xml * add a if code before cp manifest.xml to some other directory Signed-off-by: lixinyu --- script/embedded/compile/build.sh | 3 ++ script/embedded/compile/manifest.py | 80 +++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 script/embedded/compile/manifest.py diff --git a/script/embedded/compile/build.sh b/script/embedded/compile/build.sh index d9aafbe..f2d9cdf 100755 --- a/script/embedded/compile/build.sh +++ b/script/embedded/compile/build.sh @@ -115,6 +115,9 @@ rm -rf * ln -sf ../"${datetime}" "${datetime}" popd popd +if [ ! -f "${SRC_DIR}/manifest.xml" ]; then + python3 {SCRIPTS_DIR}/manifest.py ${SRC_DIR} +fi cp -a "${SRC_DIR}"/manifest.xml "${TOP_OUTPUT_DIR}/${datetime}/source-list/" create_checksum_for_release "${TOP_OUTPUT_DIR}/${datetime}" echo "INFO: ALL successfully!" diff --git a/script/embedded/compile/manifest.py b/script/embedded/compile/manifest.py new file mode 100644 index 0000000..77b623f --- /dev/null +++ b/script/embedded/compile/manifest.py @@ -0,0 +1,80 @@ +import os +import sys + +import git + +class Manifest(object): + + @staticmethod + def get_repo_param(repo_dir : str): + try: + repo = git.Repo(repo_dir) + except: + return None + + path = dir + remote = repo.remote() + repoName = remote.url.replace("https://gitee.com/", "") + revision = repo.head.commit + if "src-openeuler" in remote.url: + group = "src-openeuler" + else: + group = "openeuler" + + try: + branch = repo.active_branch.name + except TypeError: + for tag in repo.tags: + if tag.commit == repo.head.commit: + branch = tag.name + break + except Exception as e: + return None + + return { + 'repo_name': repoName, + 'path': path, + 'revision': revision, + 'group': group, + 'branch': branch + } + + def exec(self, src_dir): + if os.path.exists(os.path.join(src_dir, 'manifest.xml')): + os.remove(os.path.join(src_dir, 'manifest.xml')) + + os.mknod(os.path.join(src_dir, 'manifest.xml')) + + yocto = self.get_repo_param(repo_dir = os.path.join(src_dir, 'yocto-meta-openeuler')) + if yocto == None: + raise("there is no yocto-meta-openeuler") + + with open(os.path.join(src_dir, 'manifest.xml'), 'a+') as f: + f.write('\n') + f.write('\n') + f.write(' \n') + f.write(' \n'.format(yocto["branch"])) + + dirList = os.listdir(src_dir) + for dir in dirList: + if dir == "yocto-meta-openeuler": + continue + repoParam = self.get_repo_param(repo_dir = os.path.join(src_dir, dir)) + if repoParam == None: + continue + wline = " ".format(repoParam['repo_name'], repoParam['path'], repoParam['revision'], repoParam['group'], repoParam['branch']) + f.write(wline+"\n") + + wline = " ".format(yocto['repo_name'], yocto['path'], yocto['revision'], yocto['group'], yocto['branch']) + f.write("") + +def main(): + if sys.argv[1:2] == "": + raise("please entry src directory") + + manifest = Manifest() + manifest.exec(src_dir = sys.argv[1:2]) + print("manifest create successful in {}".format(sys.argv[1:2])) + +if __name__ == "__main__": + main() \ No newline at end of file -- Gitee