summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-06-16 22:02:35 +0800
committerruki <[email protected]>2019-06-16 22:02:35 +0800
commitad9dd8db9d6cf6d04157fd14d6e4593409729217 (patch)
tree34d13ce18db0f5409da8b8e64639d2b8c3ef8da8
parent1d38d2d275f1a9ff9a4d65fc4ea6c66a990f4978 (diff)
improve object and depend dirs and clean action
-rw-r--r--xmake/actions/build/kinds/object.lua2
-rw-r--r--xmake/actions/clean/main.lua28
-rw-r--r--xmake/core/project/target.lua204
-rw-r--r--xmake/rules/cuda/devlink/xmake.lua8
-rw-r--r--xmake/rules/lex_yacc/lex/xmake.lua7
-rw-r--r--xmake/rules/lex_yacc/yacc/xmake.lua7
-rw-r--r--xmake/rules/qt/env/xmake.lua6
-rw-r--r--xmake/rules/qt/moc/xmake.lua2
-rw-r--r--xmake/rules/qt/qrc/xmake.lua2
-rw-r--r--xmake/rules/qt/ui/xmake.lua2
10 files changed, 181 insertions, 87 deletions
diff --git a/xmake/actions/build/kinds/object.lua b/xmake/actions/build/kinds/object.lua
index 543d44478..445fb7c46 100644
--- a/xmake/actions/build/kinds/object.lua
+++ b/xmake/actions/build/kinds/object.lua
@@ -249,7 +249,7 @@ function _build_pcheaderfiles(target)
-- init sourcefile, objectfile and dependfile
local sourcefile = pcheaderfile
local objectfile = target:pcoutputfile(langkind)
- local dependfile = objectfile .. ".d"
+ local dependfile = target:dependfile(objectfile)
local sourcekind = language.langkinds()[langkind]
-- init source batch
diff --git a/xmake/actions/clean/main.lua b/xmake/actions/clean/main.lua
index 36235321e..dcdd26a13 100644
--- a/xmake/actions/clean/main.lua
+++ b/xmake/actions/clean/main.lua
@@ -39,9 +39,6 @@ function _do_clean_target(target)
-- remove the target file
remove_files(target:targetfile())
- -- remove the target dependent file if exists
- remove_files(target:dependfile())
-
-- remove the symbol file
remove_files(target:symbolfile())
@@ -49,12 +46,6 @@ function _do_clean_target(target)
remove_files(target:pcoutputfile("c"))
remove_files(target:pcoutputfile("cxx"))
- -- remove the object files
- remove_files(target:objectfiles())
-
- -- remove the depend files
- remove_files(target:dependfiles())
-
-- TODO remove the header files (deprecated)
local _, dstheaders = target:headers()
remove_files(dstheaders)
@@ -64,6 +55,25 @@ function _do_clean_target(target)
-- TODO remove the config.h file (deprecated)
remove_files(target:configheader())
+
+ -- remove all dependent files for each platform
+ remove_files(target:dependir({root = true}))
+
+ -- remove all object files for each platform
+ remove_files(target:objectdir({root = true}))
+
+ -- remove all autogen files for each platform
+ remove_files(target:autogendir({root = true}))
+ else
+
+ -- remove dependent files for the current platform
+ remove_files(target:dependir())
+
+ -- remove object files for the current platform
+ remove_files(target:objectdir())
+
+ -- remove autogen files for the current platform
+ remove_files(target:autogendir())
end
end
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index fbb6f734c..1745e08a4 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -604,58 +604,113 @@ function _instance:pkgconfig(pkgname)
end
-- get the object files directory
-function _instance:objectdir(onlyroot)
+function _instance:objectdir(opt)
-- the object directory
local objectdir = self:get("objectdir")
if not objectdir then
- objectdir = path.join(config.buildir(), ".objs", self:name())
+ objectdir = path.join(config.buildir(), ".objs")
end
+ objectdir = path.join(objectdir, self:name())
- -- only in the root directory?
- if not onlyroot then
-
- -- append plat sub-directory
- local plat = config.get("plat")
- if plat then
- objectdir = path.join(objectdir, plat)
- end
+ -- get root directory of target
+ if opt and opt.root then
+ return objectdir
+ end
- -- append arch sub-directory
- local arch = config.get("arch")
- if arch then
- objectdir = path.join(objectdir, arch)
- end
+ -- append plat sub-directory
+ local plat = config.get("plat")
+ if plat then
+ objectdir = path.join(objectdir, plat)
+ end
- -- append mode sub-directory
- local mode = config.get("mode")
- if mode then
- objectdir = path.join(objectdir, mode)
- end
+ -- append arch sub-directory
+ local arch = config.get("arch")
+ if arch then
+ objectdir = path.join(objectdir, arch)
end
- -- ok?
+ -- append mode sub-directory
+ local mode = config.get("mode")
+ if mode then
+ objectdir = path.join(objectdir, mode)
+ end
return objectdir
end
-- get the dependent files directory
-function _instance:dependir()
+function _instance:dependir(opt)
-- init the dependent directory
local dependir = self:get("dependir")
if not dependir then
- dependir = path.join(config.buildir(), ".deps", self:name())
+ dependir = path.join(config.buildir(), ".deps")
+ end
+ dependir = path.join(dependir, self:name())
+
+ -- get root directory of target
+ if opt and opt.root then
+ return dependir
+ end
+
+ -- append plat sub-directory
+ local plat = config.get("plat")
+ if plat then
+ dependir = path.join(dependir, plat)
+ end
+
+ -- append arch sub-directory
+ local arch = config.get("arch")
+ if arch then
+ dependir = path.join(dependir, arch)
+ end
+
+ -- append mode sub-directory
+ local mode = config.get("mode")
+ if mode then
+ dependir = path.join(dependir, mode)
end
return dependir
end
+-- get the autogen files directory
+function _instance:autogendir(opt)
+
+ -- the autogen directory
+ local autogendir = path.join(config.buildir(), ".gens", self:name())
+
+ -- get root directory of target
+ if opt and opt.root then
+ return autogendir
+ end
+
+ -- append plat sub-directory
+ local plat = config.get("plat")
+ if plat then
+ autogendir = path.join(autogendir, plat)
+ end
+
+ -- append arch sub-directory
+ local arch = config.get("arch")
+ if arch then
+ autogendir = path.join(autogendir, arch)
+ end
+
+ -- append mode sub-directory
+ local mode = config.get("mode")
+ if mode then
+ autogendir = path.join(autogendir, mode)
+ end
+ return autogendir
+end
+
-- get the target kind
function _instance:targetkind()
return self:get("kind") or "phony"
end
-- get the target directory
-function _instance:targetdir(onlyroot)
+function _instance:targetdir()
-- the target directory
local targetdir = self:get("targetdir")
@@ -663,25 +718,23 @@ function _instance:targetdir(onlyroot)
-- get build directory
targetdir = config.buildir()
- if not onlyroot then
- -- append plat sub-directory
- local plat = config.get("plat")
- if plat then
- targetdir = path.join(targetdir, plat)
- end
+ -- append plat sub-directory
+ local plat = config.get("plat")
+ if plat then
+ targetdir = path.join(targetdir, plat)
+ end
- -- append arch sub-directory
- local arch = config.get("arch")
- if arch then
- targetdir = path.join(targetdir, arch)
- end
+ -- append arch sub-directory
+ local arch = config.get("arch")
+ if arch then
+ targetdir = path.join(targetdir, arch)
+ end
- -- append mode sub-directory
- local mode = config.get("mode")
- if mode then
- targetdir = path.join(targetdir, mode)
- end
+ -- append mode sub-directory
+ local mode = config.get("mode")
+ if mode then
+ targetdir = path.join(targetdir, mode)
end
end
@@ -957,6 +1010,19 @@ function _instance:objectfile(sourcefile)
-- translate: [lib]xxx*.[a|lib] => xxx/*.[o|obj] object file
sourcefile = sourcefile:gsub(target.filename("([%%w%%-_]+)", "static"):gsub("%.", "%%.") .. "$", "%1/*")
+ -- get relative directory in the autogen directory
+ local relativedir = nil
+ local origindir = path.directory(path.absolute(sourcefile))
+ local autogendir = path.absolute(self:autogendir())
+ if origindir:startswith(autogendir) then
+ relativedir = path.join("gens", path.relative(origindir, autogendir))
+ end
+
+ -- get relative directory in the source directory
+ if not relativedir then
+ relativedir = path.directory(sourcefile)
+ end
+
-- translate path
--
-- .e.g
@@ -969,15 +1035,14 @@ function _instance:objectfile(sourcefile)
--
-- we need replace '..' to '__' in this case
--
- local sourcedir = path.directory(sourcefile)
- if path.is_absolute(sourcedir) and os.host() == "windows" then
- sourcedir = sourcedir:gsub(":[\\/]*", '\\') -- replace C:\xxx\ => C\xxx\
+ if path.is_absolute(relativedir) and os.host() == "windows" then
+ relativedir = relativedir:gsub(":[\\/]*", '\\') -- replace C:\xxx\ => C\xxx\
end
- sourcedir = sourcedir:gsub("%.%.", "__")
+ relativedir = relativedir:gsub("%.%.", "__")
-- make object file
-- full file name(not base) to avoid name-clash of object file
- return path.join(self:objectdir(), sourcedir, target.filename(path.filename(sourcefile), "object"))
+ return path.join(self:objectdir(), relativedir, target.filename(path.filename(sourcefile), "object"))
end
-- get the object files
@@ -1129,11 +1194,52 @@ end
function _instance:dependfile(objectfile)
-- get the dependent original file and directory, @note relative to the root directory
- local originfile = objectfile and objectfile or self:targetfile(true)
- local origindir = objectfile and self:objectdir(true) or self:targetdir(true)
+ local originfile = path.absolute(objectfile and objectfile or self:targetfile())
+ local origindir = path.directory(originfile)
+
+ -- get relative directory in the object directory
+ local relativedir = nil
+ local objectdir = path.absolute(self:objectdir())
+ if origindir:startswith(objectdir) then
+ relativedir = path.relative(origindir, objectdir)
+ end
+
+ -- get relative directory in the target directory
+ if not relativedir then
+ local targetdir = path.absolute(self:targetdir())
+ if origindir:startswith(targetdir) then
+ relativedir = path.relative(origindir, targetdir)
+ end
+ end
+
+ -- get relative directory in the autogen directory
+ if not relativedir then
+ local autogendir = path.absolute(self:autogendir())
+ if origindir:startswith(autogendir) then
+ relativedir = path.join("gens", path.relative(origindir, autogendir))
+ end
+ end
+
+ -- get relative directory in the build directory
+ if not relativedir then
+ local buildir = path.absolute(config.buildir())
+ if origindir:startswith(buildir) then
+ relativedir = path.join("build", path.relative(origindir, buildir))
+ end
+ end
- -- get the relative directory
- local relativedir = path.directory(path.relative(originfile, origindir))
+ -- get relative directory in the project directory
+ if not relativedir then
+ local projectdir = os.projectdir()
+ if origindir:startswith(projectdir) then
+ relativedir = path.relative(origindir, projectdir)
+ end
+ end
+
+ -- get the relative directory from the origin file
+ if not relativedir then
+ relativedir = origindir
+ end
if path.is_absolute(relativedir) and os.host() == "windows" then
relativedir = relativedir:gsub(":[\\/]*", '\\') -- replace C:\xxx\ => C\xxx\
end
diff --git a/xmake/rules/cuda/devlink/xmake.lua b/xmake/rules/cuda/devlink/xmake.lua
index db3ea59c1..0416b9abe 100644
--- a/xmake/rules/cuda/devlink/xmake.lua
+++ b/xmake/rules/cuda/devlink/xmake.lua
@@ -58,7 +58,7 @@ rule("cuda.devlink")
local linkflags = linkinst:linkflags({target = target, configs = {force = {culdflags = culdflags}}})
-- get target file
- local targetfile = target:objectfile(path.join(".cuda", "devlink", target:basename() .. "_gpucode.cu"))
+ local targetfile = target:objectfile(path.join("rules", "cuda", "devlink", target:basename() .. "_gpucode.cu"))
-- get object files
local objectfiles = nil
@@ -113,9 +113,3 @@ rule("cuda.devlink")
depend.save(dependinfo, dependfile)
end)
- -- clean files
- after_clean(function (target)
- import("private.action.clean.remove_files")
- remove_files(target:objectfile(path.join(".cuda", "devlink", target:basename() .. "_gpucode.cu")))
- remove_files(target:dependfile(targetfile))
- end)
diff --git a/xmake/rules/lex_yacc/lex/xmake.lua b/xmake/rules/lex_yacc/lex/xmake.lua
index ccaea4d74..b9176b3c4 100644
--- a/xmake/rules/lex_yacc/lex/xmake.lua
+++ b/xmake/rules/lex_yacc/lex/xmake.lua
@@ -58,7 +58,7 @@ rule("lex")
local extension = path.extension(sourcefile_lex)
-- get c/c++ source file for lex
- local sourcefile_cx = path.join(config.buildir(), ".lex_yacc", target:name(), path.basename(sourcefile_lex) .. (extension == ".ll" and ".cpp" or ".c"))
+ local sourcefile_cx = path.join(target:autogendir(), "rules", "lex_yacc", path.basename(sourcefile_lex) .. (extension == ".ll" and ".cpp" or ".c"))
local sourcefile_dir = path.directory(sourcefile_cx)
-- get object file
@@ -114,8 +114,3 @@ rule("lex")
depend.save(dependinfo, dependfile)
end)
- -- clean files
- after_clean(function (target)
- import("core.project.config")
- os.tryrm(path.join(config.buildir(), ".lex_yacc", target:name()))
- end)
diff --git a/xmake/rules/lex_yacc/yacc/xmake.lua b/xmake/rules/lex_yacc/yacc/xmake.lua
index d94d68122..dbd12bb93 100644
--- a/xmake/rules/lex_yacc/yacc/xmake.lua
+++ b/xmake/rules/lex_yacc/yacc/xmake.lua
@@ -58,7 +58,7 @@ rule("yacc")
local extension = path.extension(sourcefile_yacc)
-- get c/c++ source file for yacc
- local sourcefile_cx = path.join(config.buildir(), ".lex_yacc", target:name(), path.basename(sourcefile_yacc) .. ".tab" .. (extension == ".yy" and ".cpp" or ".c"))
+ local sourcefile_cx = path.join(target:autogendir(), "rules", "lex_yacc", path.basename(sourcefile_yacc) .. ".tab" .. (extension == ".yy" and ".cpp" or ".c"))
local sourcefile_dir = path.directory(sourcefile_cx)
-- get object file
@@ -114,8 +114,3 @@ rule("yacc")
depend.save(dependinfo, dependfile)
end)
- -- clean files
- after_clean(function (target)
- import("core.project.config")
- os.tryrm(path.join(config.buildir(), ".lex_yacc", target:name()))
- end)
diff --git a/xmake/rules/qt/env/xmake.lua b/xmake/rules/qt/env/xmake.lua
index ec5fe06f2..565bebf07 100644
--- a/xmake/rules/qt/env/xmake.lua
+++ b/xmake/rules/qt/env/xmake.lua
@@ -37,9 +37,3 @@ rule("qt.env")
end
end)
- -- clean files
- after_clean(function (target)
- import("core.project.config")
- import("private.action.clean.remove_files")
- remove_files(path.join(config.buildir(), ".qt"))
- end)
diff --git a/xmake/rules/qt/moc/xmake.lua b/xmake/rules/qt/moc/xmake.lua
index 40be6bf07..e0c4c96f0 100644
--- a/xmake/rules/qt/moc/xmake.lua
+++ b/xmake/rules/qt/moc/xmake.lua
@@ -50,7 +50,7 @@ rule("qt.moc")
import("core.project.depend")
-- get c++ source file for moc
- local sourcefile_moc = path.join(config.buildir(), ".qt", "moc", target:name(), "moc_" .. path.basename(headerfile_moc) .. ".cpp")
+ local sourcefile_moc = path.join(target:autogendir(), "rules", "qt", "moc", "moc_" .. path.basename(headerfile_moc) .. ".cpp")
-- get object file
local objectfile = target:objectfile(sourcefile_moc)
diff --git a/xmake/rules/qt/qrc/xmake.lua b/xmake/rules/qt/qrc/xmake.lua
index 24a8a4b3a..7a6653ab2 100644
--- a/xmake/rules/qt/qrc/xmake.lua
+++ b/xmake/rules/qt/qrc/xmake.lua
@@ -52,7 +52,7 @@ rule("qt.qrc")
local rcc = target:data("qt.rcc")
-- get c++ source file for qrc
- local sourcefile_cpp = path.join(config.buildir(), ".qt", "qrc", target:name(), path.basename(sourcefile_qrc) .. ".cpp")
+ local sourcefile_cpp = path.join(target:autogendir(), "rules", "qt", "qrc", path.basename(sourcefile_qrc) .. ".cpp")
local sourcefile_dir = path.directory(sourcefile_cpp)
-- get object file
diff --git a/xmake/rules/qt/ui/xmake.lua b/xmake/rules/qt/ui/xmake.lua
index 59a14c5af..3d6f2f12d 100644
--- a/xmake/rules/qt/ui/xmake.lua
+++ b/xmake/rules/qt/ui/xmake.lua
@@ -51,7 +51,7 @@ rule("qt.ui")
local uic = target:data("qt.uic")
-- get c++ header file for ui
- local headerfile_ui = path.join(config.buildir(), ".qt", "ui", target:name(), "ui_" .. path.basename(sourcefile_ui) .. ".h")
+ local headerfile_ui = path.join(target:autogendir(), "rules", "qt", "ui", "ui_" .. path.basename(sourcefile_ui) .. ".h")
local headerfile_dir = path.directory(headerfile_ui)
-- add includedirs