From 90a04f0505c9352aa8db2d76ccc963b33fbf3b1d Mon Sep 17 00:00:00 2001 From: xqyjlj Date: Wed, 11 Oct 2023 16:03:59 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20use=20rootfs.prefixdir?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/cpp/xmake.lua | 5 ++-- apps/zlib/xmake.lua | 3 +- tools/scripts/tasks/smart-rootfs/on_run.lua | 33 +++++++++++++++++---- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/apps/cpp/xmake.lua b/apps/cpp/xmake.lua index d00367d..6e36034 100644 --- a/apps/cpp/xmake.lua +++ b/apps/cpp/xmake.lua @@ -12,7 +12,7 @@ -- -- Copyright (C) 2022-2023 RT-Thread Development Team -- --- @author xqyjlj +-- @author xqyjlj -- @file xmake.lua -- -- Change Logs: @@ -22,9 +22,10 @@ -- add_rules("mode.debug", "mode.release") -target("cpp") +target("cpp_tc") do add_rules("rt.cpp") add_files("*.cpp") + add_values("rt.rootfs.prefixdir", "/tc") end target_end() diff --git a/apps/zlib/xmake.lua b/apps/zlib/xmake.lua index 1060a2c..34aa0a1 100644 --- a/apps/zlib/xmake.lua +++ b/apps/zlib/xmake.lua @@ -25,9 +25,10 @@ add_rules("mode.debug", "mode.release") add_requires("zlib") -target("zlib") +target("zlib_tc") do add_files("*.c") add_packages("zlib") + add_values("rt.rootfs.prefixdir", "/tc") end target_end() diff --git a/tools/scripts/tasks/smart-rootfs/on_run.lua b/tools/scripts/tasks/smart-rootfs/on_run.lua index e9f2c60..b5f1018 100644 --- a/tools/scripts/tasks/smart-rootfs/on_run.lua +++ b/tools/scripts/tasks/smart-rootfs/on_run.lua @@ -12,7 +12,7 @@ -- -- Copyright (C) 2023-2023 RT-Thread Development Team -- --- @author xqyjlj +-- @author xqyjlj -- @file on_run.lua -- -- Change Logs: @@ -33,19 +33,33 @@ function create_dir(dir) end end +function make_link(srcpath, dstpath) + print(dstpath) + if not os.exists(dstpath) then + os.ln(srcpath, dstpath) + end +end + function create_rootfs(rootfs) create_dir(path.join(rootfs, "bin")) create_dir(path.join(rootfs, "dev")) + create_dir(path.join(rootfs, "dev", "shm")) create_dir(path.join(rootfs, "etc")) - create_dir(path.join(rootfs, "kernel")) create_dir(path.join(rootfs, "lib")) create_dir(path.join(rootfs, "proc")) create_dir(path.join(rootfs, "mnt")) create_dir(path.join(rootfs, "services")) create_dir(path.join(rootfs, "tmp")) create_dir(path.join(rootfs, "usr")) - create_dir(path.join(rootfs, "var", "persistence")) - create_dir(path.join(rootfs, "var", "run")) + create_dir(path.join(rootfs, "var")) + create_dir(path.join(rootfs, "run")) + create_dir(path.join(rootfs, "root")) + + if os.host() == "linux" then + local olddir = os.cd(rootfs) + make_link("../run", path.join(rootfs, "var", "run")) + os.cd(olddir) + end end function deploy_package(rootfs) @@ -66,7 +80,7 @@ function deploy_package(rootfs) local package_rootfs = path.join(repodir, "packages", packagename:sub(1, 1), packagename, "rootfs") if os.isdir(package_rootfs) then for _, filedir in ipairs(os.filedirs(package_rootfs .. "/*")) do - os.vrunv("cp", {"-rfv", filedir, rootfs}) + os.vrunv("cp", {"-rfv", filedir, rootfs}) -- TODO: need support windows end end end @@ -97,7 +111,14 @@ function deploy_target(rootfs) local srcpath = target:targetfile() local artifact_dir = path.join(config.buildir(), config.plat(), config.arch(), config.mode()) targetfile = path.relative(targetfile, artifact_dir) - local dstpath = path.join(rootfs, "bin", targetfile) + + local prefixdir = target:values("rt.rootfs.prefixdir") + local dstpath + if prefixdir then + dstpath = path.join(rootfs, prefixdir, targetfile) + else + dstpath = path.join(rootfs, "bin", targetfile) + end cprint("${dim}> copy %s to %s", srcpath, dstpath) os.cp(srcpath, dstpath) end