From e4addbbdbf11a2b1d5b3ab786257876702fa7552 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Tue, 9 Jan 2024 16:09:57 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E6=9B=B4=E6=96=B0ohos.py,=E7=94=9F?= =?UTF-8?q?=E6=88=90zip=E6=96=87=E4=BB=B6=E6=97=B6=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E6=AD=A3=E5=88=99=E8=A1=A8=E8=BE=BE=E5=BC=8F=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- attachment/repos/bootstrap/ohos.py | 97 +++++++++++++++++++----------- 1 file changed, 62 insertions(+), 35 deletions(-) diff --git a/attachment/repos/bootstrap/ohos.py b/attachment/repos/bootstrap/ohos.py index 7687acbeb8..002f2c2536 100644 --- a/attachment/repos/bootstrap/ohos.py +++ b/attachment/repos/bootstrap/ohos.py @@ -26,12 +26,12 @@ import sys import zipfile from datetime import datetime -SUPPORT_BUILD_NAMES = ("clean", "config", "har", "compile", "zip") +SUPPORT_BUILD_NAMES = ("clean", "config", "har", "compile", "zip", "zip2") SUPPORT_BUILD_TYPES = ("debug", "profile", "release") DIR_ROOT = os.path.abspath(os.path.join(sys.argv[0], os.pardir)) OS_NAME = platform.system().lower() -PATH_SEP = ";" if OS_NAME.startswith("win") else ":" - +IS_WINDOWS = OS_NAME.startswith("win") +PATH_SEP = ";" if IS_WINDOWS else ":" logging.basicConfig( format="%(levelname)s:%(asctime)s: %(message)s", datefmt="%Y-%d-%m %H:%M:%S", @@ -48,7 +48,7 @@ def safeGetPath(filePath, isDirectory=True): return os.path.abspath(filePath) -TIME_STR = datetime.now().strftime("%H%M") +TIME_STR = datetime.now().strftime("%Y%m%d-%H%M") DIR_OUTPUTS = safeGetPath( "%s/outputs/%s" % (DIR_ROOT, datetime.now().strftime("%Y%m%d")) ) @@ -154,17 +154,20 @@ def engineConfig(buildInfo, extraParam=""): + lastPath ) unixCommand = "" - if (platform.system() != "Windows"): - unixCommand = ("--target-sysroot %s " % os.path.join(OHOS_NDK_HOME, "sysroot") - + "--target-toolchain %s " % os.path.join(OHOS_NDK_HOME, "llvm") - + "--target-triple %s " % buildInfo.targetTriple) + if not IS_WINDOWS: + unixCommand = ( + "--target-sysroot %s " % os.path.join(OHOS_NDK_HOME, "sysroot") + + "--target-toolchain %s " % os.path.join(OHOS_NDK_HOME, "llvm") + + "--target-triple %s " % buildInfo.targetTriple + ) OPT = "--unoptimized --no-lto " if buildInfo.buildType == "debug" else "" runCommand( "%s " % os.path.join("src", "flutter", "tools", "gn") - + "--ohos " + unixCommand + + "--ohos " + "--ohos-cpu %s " % buildInfo.targetArch + "--runtime-mode %s " % buildInfo.buildType + OPT + + unixCommand + "--no-goma " + "--no-prebuilt-dart-sdk " + "--embedder-for-target " @@ -227,22 +230,30 @@ def harBuild(buildInfo): ) -def isPathValid(filepath, filename, includeDir, excludeDir): - for dir in includeDir: - if dir in filepath: +def isPathValid(filepath, filename, includes, excludes): + fileOrigin = filepath + os.path.sep + filename + for regex in includes: + if re.search(regex, fileOrigin): return True - if includeDir != []: + if includes != []: return False - for dir in excludeDir: - if dir in filepath: + for regex in excludes: + if re.search(regex, fileOrigin): return False return True -def zipFileDir(fileIn, fileName, prefixInZip="", includeDir=[], excludeDir=[]): +def zipFileDir( + fileIn, + fileName, + prefixInZip="", + includes=[], + excludes=[], + useZip2=False, +): logging.info( - "fileIn= %s, fileName= %s, prefixInZip= %s, includeDir= %s, excludeDir= %s" - % (fileIn, fileName, prefixInZip, includeDir, excludeDir) + "fileIn= %s, fileName= %s, prefixInZip= %s, includes= %s, excludes= %s" + % (fileIn, fileName, prefixInZip, includes, excludes) ) fileOut1 = os.path.abspath("%s/%s.zip" % (DIR_OUTPUTS, fileName)) fileOut2 = os.path.abspath("%s/%s-unstripped.zip" % (DIR_OUTPUTS, fileName)) @@ -252,29 +263,42 @@ def zipFileDir(fileIn, fileName, prefixInZip="", includeDir=[], excludeDir=[]): fpath = path.replace(fileIn, "")[1:] pPath = prefixInZip + os.sep + fpath for filename in filenames: - if isPathValid(fpath, filename, includeDir, excludeDir): - zip1.write( - os.path.join(path, filename), os.path.join(pPath, filename) - ) - else: - zip2.write( - os.path.join(path, filename), os.path.join(pPath, filename) - ) + path1 = os.path.join(path, filename) + path2 = os.path.join(pPath, filename) + if isPathValid(fpath, filename, includes, excludes): + zip1.write(path1, path2) + elif useZip2: + zip2.write(path1, path2) + + if not useZip2: + os.remove(fileOut2) -def zipFiles(buildInfo): +def zipFiles(buildInfo, useZip2=False): logging.info("zipFiles buildInfo=%s" % buildInfo) + sdkInt = int(getNdkHome()[-9:-7]) outputName = getOutput(buildInfo) fileIn = os.path.abspath("%s/src/out/%s" % (DIR_ROOT, outputName)) - fileName = "%s-%s-%s-%s" % ( - outputName, - TIME_STR, + fileName = "ohos_api%s_%s-%s-%s-%s" % ( + sdkInt, + buildInfo.buildType, OS_NAME, platform.machine(), + TIME_STR, ) prefixInZip = os.path.join("src", "out", outputName) - dirArray = ["obj", "exe.unstripped", "so.unstripped"] - zipFileDir(fileIn, fileName, prefixInZip, excludeDir=dirArray) + if IS_WINDOWS: + excludes = [ + ".*\.ilk", + ".*\.pdb", + ] + else: + excludes = [ + "obj", + "exe.unstripped", + "so.unstripped", + ] + zipFileDir(fileIn, fileName, prefixInZip, excludes=excludes, useZip2=useZip2) def addParseParam(parser): @@ -347,19 +371,22 @@ def buildByNameAndType(args): engineCompile(buildInfo) elif "zip" == buildName: zipFiles(buildInfo) + elif "zip2" == buildName: + zipFiles(buildInfo, True) else: logging.warning("Other name=%s" % buildName) -def main(): +def ohos_main(): parser = argparse.ArgumentParser() addParseParam(parser) args = parser.parse_args() checkEnvironment() updateCode(args) buildByNameAndType(args) - logging.info("main() finish.") + logging.info("ohos_main() finish.") return 0 -exit(main()) +if __name__ == "__main__": + exit(ohos_main()) -- Gitee From 15d2e9ca8a249731867aa82ab3358b9f7bd3243d Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Fri, 12 Jan 2024 10:18:53 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E5=9C=A8ndk=E7=9B=AE=E5=BD=95,=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E7=B3=BB=E7=BB=9F=E7=B1=BB=E5=9E=8B=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E5=AF=B9=E5=BA=94=E7=9A=84native?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- attachment/repos/bootstrap/ohos.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/attachment/repos/bootstrap/ohos.py b/attachment/repos/bootstrap/ohos.py index 002f2c2536..a24ddff61a 100644 --- a/attachment/repos/bootstrap/ohos.py +++ b/attachment/repos/bootstrap/ohos.py @@ -104,8 +104,28 @@ def engineClean(buildInfo): shutil.rmtree(target, ignore_errors=True) +def findFile(path, search, results): + if not os.path.exists(path): + return + for item in os.listdir(path): + cur_path = os.path.join(path, item) + if os.path.isdir(cur_path): + if cur_path.endswith(search): + results.append(cur_path) + findFile(os.path.join(path, item), search, results) + + +def findNativeInCurrentDir(): + os_dir = "mac" if OS_NAME == "darwin" else OS_NAME + dirs = [] + findFile(os.path.join("ndk", os_dir), "native", dirs) + return dirs[0] if len(dirs) != 0 else "" + + def getNdkHome(): OHOS_NDK_HOME = os.getenv("OHOS_NDK_HOME") + if not OHOS_NDK_HOME: + OHOS_NDK_HOME = findNativeInCurrentDir() if not OHOS_NDK_HOME: OHOS_SDK_HOME = os.getenv("OHOS_SDK_HOME") if not OHOS_SDK_HOME: -- Gitee From 69fdf877665950465b1a8cb5d5434c27b2a7ed02 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Fri, 12 Jan 2024 10:51:59 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E4=BC=98=E5=85=88=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E8=B7=AF=E5=BE=84=E4=B8=8B=E7=9A=84depot=5Ft?= =?UTF-8?q?ools?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- attachment/repos/bootstrap/ohos.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/attachment/repos/bootstrap/ohos.py b/attachment/repos/bootstrap/ohos.py index a24ddff61a..14e0f02825 100644 --- a/attachment/repos/bootstrap/ohos.py +++ b/attachment/repos/bootstrap/ohos.py @@ -111,7 +111,7 @@ def findFile(path, search, results): cur_path = os.path.join(path, item) if os.path.isdir(cur_path): if cur_path.endswith(search): - results.append(cur_path) + results.append(os.path.abspath(cur_path)) findFile(os.path.join(path, item), search, results) @@ -171,6 +171,7 @@ def engineConfig(buildInfo, extraParam=""): os.environ["PATH"] = ( "%s%s" % (os.path.join(OHOS_NDK_HOME, "build-tools", "cmake", "bin"), PATH_SEP) + "%s%s" % (os.path.join(OHOS_NDK_HOME, "build-tools", "llvm", "bin"), PATH_SEP) + + "%s%s" % (os.path.abspath("depot_tools"), PATH_SEP) + lastPath ) unixCommand = "" -- Gitee From 072c9277869d0ddc93ff32187d6240612204d94f Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Fri, 12 Jan 2024 19:50:27 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BF=E7=BC=96=E8=AF=91=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- attachment/scripts/ohos_setup.py | 7 ++++--- attachment/scripts/ohos_setup_pre.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/attachment/scripts/ohos_setup.py b/attachment/scripts/ohos_setup.py index b6e1b53101..4bb80b246b 100644 --- a/attachment/scripts/ohos_setup.py +++ b/attachment/scripts/ohos_setup.py @@ -85,15 +85,16 @@ def doTask(task, log=False): pass -def parse_config(config_file="{}/scripts/config.json".format(ROOT)): +def parse_config(config_file="{}/scripts/config.json".format(ROOT), useStash=True): log = False if (len(sys.argv) > 1): if(sys.argv[1] == '-v'): log = True with open(config_file) as json_file: data = json.load(json_file) - for task in data: - stashChanges(task, log) + if useStash: + for task in data: + stashChanges(task, log) for task in data: doTask(task, log) diff --git a/attachment/scripts/ohos_setup_pre.py b/attachment/scripts/ohos_setup_pre.py index f1239d5f6a..9d13a27fac 100644 --- a/attachment/scripts/ohos_setup_pre.py +++ b/attachment/scripts/ohos_setup_pre.py @@ -15,4 +15,4 @@ import ohos_setup # 在预编译脚本中使用的配置 -ohos_setup.parse_config("{}/scripts/config_pre.json".format(ohos_setup.ROOT)) +ohos_setup.parse_config("{}/scripts/config_pre.json".format(ohos_setup.ROOT), useStash=False) -- Gitee From 048b579b45eaffa5cf64c2a30c27ba1b966f9f9e Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Sat, 13 Jan 2024 09:41:08 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E9=BB=98=E8=AE=A4=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E6=94=B9=E4=B8=BA=20config=20compile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- attachment/repos/bootstrap/ohos.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/attachment/repos/bootstrap/ohos.py b/attachment/repos/bootstrap/ohos.py index 14e0f02825..54bb19ce5e 100644 --- a/attachment/repos/bootstrap/ohos.py +++ b/attachment/repos/bootstrap/ohos.py @@ -111,7 +111,7 @@ def findFile(path, search, results): cur_path = os.path.join(path, item) if os.path.isdir(cur_path): if cur_path.endswith(search): - results.append(os.path.abspath(cur_path)) + results.append(cur_path) findFile(os.path.join(path, item), search, results) @@ -373,7 +373,7 @@ def checkEnvironment(): def buildByNameAndType(args): - buildNames = args.name if args.branch or args.name else ["config", "compile", "har"] + buildNames = args.name if args.branch or args.name else ["config", "compile"] buildTypes = args.type for buildType in SUPPORT_BUILD_TYPES: if not buildType in buildTypes: -- Gitee From 4dc47de000d2198c9167e5a2622636f70c306a03 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Sat, 13 Jan 2024 17:46:22 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BC=95=E7=94=A8?= =?UTF-8?q?=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- attachment/repos/bootstrap/ohos.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/attachment/repos/bootstrap/ohos.py b/attachment/repos/bootstrap/ohos.py index 54bb19ce5e..7a1c796b4e 100644 --- a/attachment/repos/bootstrap/ohos.py +++ b/attachment/repos/bootstrap/ohos.py @@ -111,8 +111,8 @@ def findFile(path, search, results): cur_path = os.path.join(path, item) if os.path.isdir(cur_path): if cur_path.endswith(search): - results.append(cur_path) - findFile(os.path.join(path, item), search, results) + results.append(os.path.abspath(cur_path)) + findFile(cur_path, search, results) def findNativeInCurrentDir(): -- Gitee