Skip to content

Commit

Permalink
Merge pull request #41 from xqyjlj/rootfs.prefixdir-dev
Browse files Browse the repository at this point in the history
✨ feat: use rootfs.prefixdir
  • Loading branch information
BernardXiong authored Oct 18, 2023
2 parents 1af8438 + 90a04f0 commit 8df3f42
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
5 changes: 3 additions & 2 deletions apps/cpp/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
--
-- Copyright (C) 2022-2023 RT-Thread Development Team
--
-- @author xqyjlj
-- @author xqyjlj
-- @file xmake.lua
--
-- Change Logs:
Expand All @@ -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()
3 changes: 2 additions & 1 deletion apps/zlib/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
33 changes: 27 additions & 6 deletions tools/scripts/tasks/smart-rootfs/on_run.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
--
-- Copyright (C) 2023-2023 RT-Thread Development Team
--
-- @author xqyjlj
-- @author xqyjlj
-- @file on_run.lua
--
-- Change Logs:
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8df3f42

Please sign in to comment.