diff options
| author | ruki <[email protected]> | 2017-02-15 10:22:35 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-02-15 10:22:35 +0800 |
| commit | 73cd519a9a8130bae7f8c6101787168681e1dcd6 (patch) | |
| tree | ffb4b9381af1c30e08e8ddbb94da7e4fb04bafe3 | |
| parent | 7f135386a31972e4f4e486ae5854115b2e1af5a2 (diff) | |
rewrite objectfiles for target
| -rwxr-xr-x | docs/zh/manual.md | 11 | ||||
| -rwxr-xr-x | tests/static_library_go/xmake.lua | 6 | ||||
| -rwxr-xr-x | xmake/actions/build/kinds/object.lua | 27 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 179 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/tool/compiler.lua | 4 | ||||
| -rw-r--r-- | xmake/core/tool/compiler.lua | 4 | ||||
| -rwxr-xr-x | xmake/languages/golang/xmake.lua | 1 | ||||
| -rwxr-xr-x | xmake/plugins/lua/xmake.lua | 4 | ||||
| -rwxr-xr-x | xmake/tools/cl.lua | 4 | ||||
| -rwxr-xr-x | xmake/tools/gcc.lua | 4 | ||||
| -rwxr-xr-x | xmake/tools/go.lua | 4 | ||||
| -rwxr-xr-x | xmake/tools/ml.lua | 4 | ||||
| -rw-r--r-- | xmake/tools/swiftc.lua | 4 |
13 files changed, 155 insertions, 101 deletions
diff --git a/docs/zh/manual.md b/docs/zh/manual.md index 65f2a4388..0adfd3176 100755 --- a/docs/zh/manual.md +++ b/docs/zh/manual.md @@ -2509,7 +2509,18 @@ platform("android") #### 内置模块 +| 接口 | 描述 | 支持版本 | +| ----------------------------------------------- | -------------------------------------------- | -------- | +| [import](#import) | 导入扩展摸块 | >= 2.0.1 | +| [inherit](#inherit) | 导入并继承基类模块 | >= 2.0.1 | +| [ifelse](#ifelse) | 类似三元条件判断 | >= 2.0.1 | +| [try-catch-finally](#try-catch-finally) | 异常捕获 | >= 2.0.1 | + + ##### import + +###### 导入扩展摸块 + ##### inherit ##### ifelse ##### try-catch-finally diff --git a/tests/static_library_go/xmake.lua b/tests/static_library_go/xmake.lua index a614fe00b..fb23da6a8 100755 --- a/tests/static_library_go/xmake.lua +++ b/tests/static_library_go/xmake.lua @@ -42,9 +42,9 @@ target("test") -- add files add_files("src/*.go") - -- add links - add_links("module") - -- add link directory add_linkdirs("$(buildir)") + -- add include directory + add_includedirs("$(buildir)") + diff --git a/xmake/actions/build/kinds/object.lua b/xmake/actions/build/kinds/object.lua index fdcf6f00e..1fb1b1a68 100755 --- a/xmake/actions/build/kinds/object.lua +++ b/xmake/actions/build/kinds/object.lua @@ -83,17 +83,14 @@ function _build_object(target, buildinfo, index, sourcebatch) local objectfile = sourcebatch.objectfiles[index] local incdepfile = sourcebatch.incdepfiles[index] - -- get the source file type - local filetype = path.extension(sourcefile):lower() - -- calculate percent local percent = ((buildinfo.targetindex + (_g.sourceindex + index - 1) / _g.sourcecount) * 100 / buildinfo.targetcount) -- build the object for the *.o/obj source makefile - if filetype == ".o" or filetype == ".obj" then + if sourcebatch.sourcekind == "obj" then return _build_from_object(target, sourcefile, objectfile, percent) -- build the object for the *.[a|lib] source file - elseif filetype == ".a" or filetype == ".lib" then + elseif sourcebatch.sourcekind == "lib" then return _build_from_static(target, sourcefile, objectfile, percent) end @@ -166,7 +163,7 @@ function _build_object(target, buildinfo, index, sourcebatch) end -- build each objects from the given source batch -function _build_objects_foreach(target, buildinfo, sourcekind, sourcebatch, jobs) +function _build_each_objects(target, buildinfo, sourcekind, sourcebatch, jobs) -- make objects local index = 1 @@ -263,8 +260,8 @@ function _build_objects_foreach(target, buildinfo, sourcekind, sourcebatch, jobs _g.sourceindex = _g.sourceindex + #sourcebatch.sourcefiles end --- build multiple objects at the same time from the given source batch -function _build_objects_multiple(target, buildinfo, sourcekind, sourcebatch, jobs) +-- compile source files to single object at the same time +function _build_single_object(target, buildinfo, sourcekind, sourcebatch, jobs) -- is verbose? local verbose = option.get("verbose") @@ -291,11 +288,11 @@ function _build_objects_multiple(target, buildinfo, sourcekind, sourcebatch, job -- trace verbose info if verbose then - print(compiler.compcmd(sourcefiles, "xxx.o", target, sourcekind)) + print(compiler.compcmd(sourcefiles, objectfiles, target, sourcekind)) end -- complie them - compiler.compile(sourcefiles, "xxx.o", incdepfiles, target, sourcekind) + compiler.compile(sourcefiles, objectfiles, incdepfiles, target, sourcekind) -- update object index _g.sourceindex = _g.sourceindex + #sourcebatch.sourcefiles @@ -314,16 +311,16 @@ function build(target, buildinfo) -- build source batches for sourcekind, sourcebatch in pairs(target:sourcebatches()) do - -- support to compile multiple objects at the same time? - if compiler.feature(sourcekind, "compile:multifiles") then + -- compile source files to single object at the same time? + if type(sourcebatch.objectfiles) == "string" then - -- build multiple objects - _build_objects_multiple(target, buildinfo, sourcekind, sourcebatch, jobs) + -- build single object + _build_single_object(target, buildinfo, sourcekind, sourcebatch, jobs) else -- build each objects - _build_objects_foreach(target, buildinfo, sourcekind, sourcebatch, jobs) + _build_each_objects(target, buildinfo, sourcekind, sourcebatch, jobs) end end end diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 3c205993b..546276caf 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -222,7 +222,7 @@ function target:sourcefiles() for _, pattern in ipairs(patterns) do file, count = file:gsub(pattern[1], target.filename(pattern[2], pattern[3])) if count > 0 then - -- disable cache because the object and library files will be modified. + -- disable cache because the object and library files will be modified if them depend on previous target file cache = false end end @@ -260,55 +260,53 @@ function target:sourcefiles() return sourcefiles, not cache end --- get the object files -function target:objectfiles() +-- get object file from source file +function target:objectfile(sourcefile) - -- check - assert(self) - - -- get the source files - local sourcefiles, modified = self:sourcefiles() - assert(sourcefiles) - - -- cached? return it directly - if self._OBJECTFILES and not modified then - return self._OBJECTFILES - end + -- translate: [lib]xxx*.[a|lib] => xxx/*.[o|obj] object file + sourcefile = sourcefile:gsub(target.filename("([%w_]+)", "static"):gsub("%.", "%%.") .. "$", "%1/*") -- get the object directory local objectdir = self:objectdir() assert(objectdir and type(objectdir) == "string") - -- make object files - local i = 1 - local objectfiles = {} - for _, sourcefile in ipairs(sourcefiles) do + -- make object file + -- full file name(not base) to avoid name-clash of object file + local objectfile = string.format("%s/%s/%s/%s", objectdir, self:name(), path.directory(sourcefile), target.filename(path.filename(sourcefile), "object")) - -- translate: [lib]xxx*.[a|lib] => xxx/*.[o|obj] object file - sourcefile = sourcefile:gsub(target.filename("([%w_]+)", "static"):gsub("%.", "%%.") .. "$", "%1/*") + -- 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 + -- + objectfile = (path.translate(objectfile):gsub("%.%.", "__")) - -- make object file - -- full file name(not base) to avoid name-clash of object file - local objectfile = string.format("%s/%s/%s/%s", objectdir, self:name(), path.directory(sourcefile), target.filename(path.filename(sourcefile), "object")) + -- ok? + return objectfile +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 - -- - objectfile = (path.translate(objectfile):gsub("%.%.", "__")) +-- get the object files +function target:objectfiles() - -- save it - objectfiles[i] = objectfile - i = i + 1 + -- get source batches + local sourcebatches, modified = self:sourcebatches() + -- cached? return it directly + if self._OBJECTFILES and not modified then + return self._OBJECTFILES + end + + -- get object files from source batches + local objectfiles = {} + for sourcekind, sourcebatch in pairs(self:sourcebatches()) do + table.join2(objectfiles, sourcebatch.objectfiles) end -- cache it @@ -321,9 +319,6 @@ end -- get the header files function target:headerfiles(outputdir) - -- check - assert(self) - -- cached? return it directly if self._HEADERFILES and outputdir == nil then return self._HEADERFILES[1], self._HEADERFILES[2] @@ -387,31 +382,32 @@ function target:headerfiles(outputdir) return srcheaders, dstheaders end +-- get incdep file from object file +function target:incdepfile(objectfile) + return path.join(path.directory(objectfile), path.basename(objectfile) .. ".d") +end + -- get the dependent include files function target:incdepfiles() - -- the previous object files - local objectfiles_prev = self._OBJECTFILES - - -- the object files - local objectfiles = self:objectfiles() - + -- get source batches + local sourcebatches, modified = self:sourcebatches() + -- cached? return it directly - local modified = objectfiles_prev ~= objectfiles if self._INCDEPFILES and not modified then return self._INCDEPFILES end - -- make include files + -- get incdep files from source batches local incdepfiles = {} - for _, objectfile in ipairs(objectfiles) do - table.insert(incdepfiles, path.join(path.directory(objectfile), path.basename(objectfile) .. ".d")) + for sourcekind, sourcebatch in pairs(self:sourcebatches()) do + table.join2(incdepfiles, sourcebatch.incdepfiles) end -- cache it self._INCDEPFILES = incdepfiles - -- ok + -- ok? return incdepfiles end @@ -455,43 +451,92 @@ end -- get source batches function target:sourcebatches() + -- get source files + local sourcefiles, modified = self:sourcefiles() + -- cached? return it directly - if self._SOURCEBATCHES then - return self._SOURCEBATCHES + if self._SOURCEBATCHES and not modified then + return self._SOURCEBATCHES, false end - -- the object and source files - local objectfiles = self:objectfiles() - local sourcefiles = self:sourcefiles() - local incdepfiles = self:incdepfiles() - assert(objectfiles and sourcefiles and incdepfiles) + -- the extensional source kinds + local sourcekinds_ext = + { + [".o"] = "obj" + , [".obj"] = "obj" + , [".a"] = "lib" + , [".lib"] = "lib" + } -- make source batches for each source kinds local sourcebatches = {} - for index, sourcefile in ipairs(sourcefiles) do + for _, sourcefile in ipairs(sourcefiles) do -- get source kind local sourcekind = language.sourcekind_of(sourcefile) + if not sourcekind then + local sourcekind_ext = sourcekinds_ext[path.extension(sourcefile):lower()] + if sourcekind_ext then + sourcekind = sourcekind_ext + end + end + + -- unknown source kind + if not sourcekind then + os.raise("unknown source file: %s", sourcefile) + end -- make this batch - local sourcebatch = sourcebatches[sourcekind] or {sourcefiles = {}, objectfiles = {}, incdepfiles = {}} + local sourcebatch = sourcebatches[sourcekind] or {sourcefiles = {}} sourcebatches[sourcekind] = sourcebatch + -- add source kind to this batch + sourcebatch.sourcekind = sourcekind + -- add source file to this batch table.insert(sourcebatch.sourcefiles, sourcefile) + end + + -- insert object files to source batches + for sourcekind, sourcebatch in pairs(sourcebatches) do + + -- this batch support to compile multiple objects at the same time? + local instance = compiler.load(sourcekind) + if instance and instance:feature("compile:multifiles") then - -- add object file to this batch - table.insert(sourcebatch.objectfiles, objectfiles[index]) + -- get the first source file + local sourcefile = sourcebatch.sourcefiles[1] - -- add incdep file to this batch - table.insert(sourcebatch.incdepfiles, incdepfiles[index]) + -- insert single object file for all source files + sourcebatch.objectfiles = self:objectfile(path.join(path.directory(sourcefile), "__" .. sourcekind)) + + -- insert single incdep file for all source files + sourcebatch.incdepfiles = self:incdepfile(sourcebatch.objectfiles) + + else + + -- insert object files for each source files + sourcebatch.objectfiles = {} + sourcebatch.incdepfiles = {} + for _, sourcefile in ipairs(sourcebatch.sourcefiles) do + + -- get object file from this source file + local objectfile = self:objectfile(sourcefile) + + -- add object file to this batch + table.insert(sourcebatch.objectfiles, objectfile) + + -- add incdep file to this batch + table.insert(sourcebatch.incdepfiles, self:incdepfile(objectfile)) + end + end end -- cache it self._SOURCEBATCHES = sourcebatches -- ok? - return sourcebatches + return sourcebatches, modified end -- return module diff --git a/xmake/core/sandbox/modules/import/core/tool/compiler.lua b/xmake/core/sandbox/modules/import/core/tool/compiler.lua index 3cf003be3..7e93570b1 100644 --- a/xmake/core/sandbox/modules/import/core/tool/compiler.lua +++ b/xmake/core/sandbox/modules/import/core/tool/compiler.lua @@ -64,7 +64,7 @@ function sandbox_core_tool_compiler.compcmd(sourcefiles, objectfile, target, sou end -- compile source files -function sandbox_core_tool_compiler.compile(sourcefiles, objectfile, incdepfiles, target, sourcekind) +function sandbox_core_tool_compiler.compile(sourcefiles, objectfile, incdepfile, target, sourcekind) -- get source kind if only one source file if not sourcekind and type(sourcefiles) == "string" then @@ -78,7 +78,7 @@ function sandbox_core_tool_compiler.compile(sourcefiles, objectfile, incdepfiles end -- compile it - local ok, errors = instance:compile(sourcefiles, objectfile, incdepfiles, target) + local ok, errors = instance:compile(sourcefiles, objectfile, incdepfile, target) if not ok then raise(errors) end diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index 18af4adb4..cf0a7d56a 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -105,10 +105,10 @@ function compiler.load(sourcekind) end -- compile the source files -function compiler:compile(sourcefiles, objectfile, incdepfiles, target) +function compiler:compile(sourcefiles, objectfile, incdepfile, target) -- compile it - return sandbox.load(self:_tool().compile, sourcefiles, objectfile, incdepfiles, (self:compflags(target))) + return sandbox.load(self:_tool().compile, sourcefiles, objectfile, incdepfile, (self:compflags(target))) end -- get the compile command diff --git a/xmake/languages/golang/xmake.lua b/xmake/languages/golang/xmake.lua index 0705f92e9..12b5b84f5 100755 --- a/xmake/languages/golang/xmake.lua +++ b/xmake/languages/golang/xmake.lua @@ -55,6 +55,7 @@ language("golang") , "target.vectorexts:check" , "target.defines" , "target.undefines" + , "target.includedirs" , "platform.includedirs" , "platform.defines" , "platform.undefines" diff --git a/xmake/plugins/lua/xmake.lua b/xmake/plugins/lua/xmake.lua index fb5384bd5..abc723b3b 100755 --- a/xmake/plugins/lua/xmake.lua +++ b/xmake/plugins/lua/xmake.lua @@ -52,9 +52,9 @@ task("lua") -- import script if os.isfile(name) then - import(path.basename(name), {rootdir = path.directory(name)}).main(unpack(option.get("arguments"))) + import(path.basename(name), {rootdir = path.directory(name)}).main(unpack(option.get("arguments") or {})) else - import("scripts." .. name).main(unpack(option.get("arguments"))) + import("scripts." .. name).main(unpack(option.get("arguments") or {})) end end) diff --git a/xmake/tools/cl.lua b/xmake/tools/cl.lua index 1143bf8da..9e32839ea 100755 --- a/xmake/tools/cl.lua +++ b/xmake/tools/cl.lua @@ -301,13 +301,13 @@ function compcmd(sourcefiles, objectfile, flags) end -- complie the source file -function compile(sourcefiles, objectfile, incdepfiles, flags) +function compile(sourcefiles, objectfile, incdepfile, flags) -- only support single source file now assert(type(sourcefiles) ~= "table", "'compile:multifiles' not support!") -- for only single source file - _compile1(sourcefiles, objectfile, incdepfiles, flags) + _compile1(sourcefiles, objectfile, incdepfile, flags) end -- check the given flags diff --git a/xmake/tools/gcc.lua b/xmake/tools/gcc.lua index 0f8d5fbfa..2283a08e2 100755 --- a/xmake/tools/gcc.lua +++ b/xmake/tools/gcc.lua @@ -364,13 +364,13 @@ function compcmd(sourcefiles, objectfile, flags) end -- complie the source file -function compile(sourcefiles, objectfile, incdepfiles, flags) +function compile(sourcefiles, objectfile, incdepfile, flags) -- only support single source file now assert(type(sourcefiles) ~= "table", "'compile:multifiles' not support!") -- for only single source file - _compile1(sourcefiles, objectfile, incdepfiles, flags) + _compile1(sourcefiles, objectfile, incdepfile, flags) end -- check the given flags diff --git a/xmake/tools/go.lua b/xmake/tools/go.lua index 03997d889..9a3f45ab5 100755 --- a/xmake/tools/go.lua +++ b/xmake/tools/go.lua @@ -38,7 +38,7 @@ function init(shellname, kind) _g.kind = kind -- init arflags - _g.arflags = { "grcP" } + _g.arflags = { "grc" } -- init features _g.features = @@ -120,7 +120,7 @@ function compcmd(sourcefiles, objectfile, flags) end -- complie the source file -function compile(sourcefiles, objectfile, incdepfiles, flags) +function compile(sourcefiles, objectfile, incdepfile, flags) -- ensure the object directory os.mkdir(path.directory(objectfile)) diff --git a/xmake/tools/ml.lua b/xmake/tools/ml.lua index f866ba629..95cff1d95 100755 --- a/xmake/tools/ml.lua +++ b/xmake/tools/ml.lua @@ -135,13 +135,13 @@ function compcmd(sourcefiles, objectfile, flags) end -- complie the source file -function compile(sourcefiles, objectfile, incdepfiles, flags) +function compile(sourcefiles, objectfile, incdepfile, flags) -- only support single source file now assert(type(sourcefiles) ~= "table", "'compile:multifiles' not support!") -- for only single source file - _compile1(sourcefiles, objectfile, incdepfiles, flags) + _compile1(sourcefiles, objectfile, incdepfile, flags) end -- check the given flags function check(flags) diff --git a/xmake/tools/swiftc.lua b/xmake/tools/swiftc.lua index 54441f34d..04e32f922 100644 --- a/xmake/tools/swiftc.lua +++ b/xmake/tools/swiftc.lua @@ -217,13 +217,13 @@ function compcmd(sourcefiles, objectfile, flags) end -- complie the source file -function compile(sourcefiles, objectfile, incdepfiles, flags) +function compile(sourcefiles, objectfile, incdepfile, flags) -- only support single source file now assert(type(sourcefiles) ~= "table", "'compile:multifiles' not support!") -- for only single source file - _compile1(sourcefiles, objectfile, incdepfiles, flags) + _compile1(sourcefiles, objectfile, incdepfile, flags) end -- check the given flags |
