summaryrefslogtreecommitdiff
path: root/xmake/core/project/target.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2020-06-12 22:34:48 +0800
committerruki <[email protected]>2020-06-12 09:28:51 +0800
commitcf1df0402b2fdcb1c6d8d4f35385f153a036dc24 (patch)
tree353270c8ba9680160686ca26a4fa54b7e909a08a /xmake/core/project/target.lua
parent2daaee9087bf3a503831d8dfb141baa328cbac43 (diff)
improve protobuf
Diffstat (limited to 'xmake/core/project/target.lua')
-rw-r--r--xmake/core/project/target.lua74
1 files changed, 39 insertions, 35 deletions
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 1538d7930..af9e194e9 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -802,6 +802,43 @@ function _instance:autogendir(opt)
return autogendir
end
+-- get the autogen file path from the given source file path
+function _instance:autogenfile(sourcefile, opt)
+
+ -- 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.
+ --
+ -- src/xxx.c
+ -- project/xmake.lua
+ -- build/.objs
+ -- build/.gens
+ --
+ -- objectfile: project/build/.objs/xxxx/../../xxx.c will be out of range for objectdir
+ -- autogenfile: project/build/.gens/xxxx/../../xxx.c will be out of range for autogendir
+ --
+ -- we need replace '..' to '__' in this case
+ --
+ if path.is_absolute(relativedir) and os.host() == "windows" then
+ relativedir = relativedir:gsub(":[\\/]*", '\\') -- replace C:\xxx\ => C\xxx\
+ end
+ relativedir = relativedir:gsub("%.%.", "__")
+ return path.join((opt and opt.rootdir) and opt.rootdir or self:autogendir(), relativedir, (opt and opt.filename) and opt.filename or path.filename(sourcefile))
+end
+
-- get the target kind
function _instance:targetkind()
return self:get("kind") or "phony"
@@ -1081,41 +1118,8 @@ function _instance:sourcefiles()
end
-- get object file from source file
-function _instance:objectfile(sourcefile, sourcekind)
-
- -- 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.
- --
- -- src/xxx.c
- -- project/xmake.lua
- -- build/.objs
- --
- -- objectfile: project/build/.objs/xxxx/../../xxx.c will be out of range for objectdir
- --
- -- we need replace '..' to '__' in this case
- --
- if path.is_absolute(relativedir) and os.host() == "windows" then
- relativedir = relativedir:gsub(":[\\/]*", '\\') -- replace C:\xxx\ => C\xxx\
- end
- relativedir = relativedir:gsub("%.%.", "__")
-
- -- make object file
- -- full file name(not base) to avoid name-clash of object file
- return path.join(self:objectdir(), relativedir, target.filename(path.filename(sourcefile), "object"))
+function _instance:objectfile(sourcefile)
+ return self:autogenfile(sourcefile, {rootdir = self:objectdir(), filename = target.filename(path.filename(sourcefile), "object")})
end
-- get the object files