summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-08-31 22:11:00 +0800
committerruki <[email protected]>2019-08-31 22:11:00 +0800
commit9b62ca9a3bdccb9a37f80a6dd943dfd13a502a32 (patch)
tree34f3b6fc417b0ec5cc73c722244527290f3a13d3
parente7ab648aa0bb953391204c6f081519421118e1d0 (diff)
fix all codes about sourcebatches
-rw-r--r--xmake/plugins/project/clang/compile_commands.lua24
-rw-r--r--xmake/plugins/project/clang/compile_flags.lua24
-rw-r--r--xmake/plugins/project/make/makefile.lua69
-rw-r--r--xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua11
-rw-r--r--xmake/plugins/project/vstudio/impl/vs201x.lua5
-rw-r--r--xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua10
-rw-r--r--xmake/rules/cuda/devlink/xmake.lua4
7 files changed, 39 insertions, 108 deletions
diff --git a/xmake/plugins/project/clang/compile_commands.lua b/xmake/plugins/project/clang/compile_commands.lua
index 4c81c2890..a9f1adf93 100644
--- a/xmake/plugins/project/clang/compile_commands.lua
+++ b/xmake/plugins/project/clang/compile_commands.lua
@@ -55,21 +55,12 @@ function _make_object(jsonfile, target, sourcefile, objectfile)
_g.firstline = false
end
--- make each objects
-function _make_each_objects(jsonfile, target, sourcekind, sourcebatch)
+-- make objects
+function _make_objects(jsonfile, target, sourcekind, sourcebatch)
for index, objectfile in ipairs(sourcebatch.objectfiles) do
_make_object(jsonfile, target, sourcebatch.sourcefiles[index], objectfile)
end
end
-
--- make single object
-function _make_single_object(jsonfile, target, sourcekind, sourcebatch)
-
- -- not supported now, ignore it directly
- for _, sourcefile in ipairs(table.wrap(sourcebatch.sourcefiles)) do
- cprint("${bright color.warning}warning: ${clear}ignore[%s]: %s", target:name(), sourcefile)
- end
-end
-- make target
function _make_target(jsonfile, target)
@@ -80,13 +71,10 @@ function _make_target(jsonfile, target)
target:set("pcxxheader", nil)
-- build source batches
- for sourcekind, sourcebatch in pairs(target:sourcebatches()) do
- if not sourcebatch.rulename then
- if type(sourcebatch.objectfiles) == "string" then
- _make_single_object(jsonfile, target, sourcekind, sourcebatch)
- else
- _make_each_objects(jsonfile, target, sourcekind, sourcebatch)
- end
+ for _, sourcebatch in pairs(target:sourcebatches()) do
+ local sourcekind = sourcebatch.sourcekind
+ if sourcekind then
+ _make_objects(jsonfile, target, sourcekind, sourcebatch)
end
end
end
diff --git a/xmake/plugins/project/clang/compile_flags.lua b/xmake/plugins/project/clang/compile_flags.lua
index de557c818..d6205700d 100644
--- a/xmake/plugins/project/clang/compile_flags.lua
+++ b/xmake/plugins/project/clang/compile_flags.lua
@@ -48,21 +48,12 @@ function _make_object(target, sourcefile, objectfile)
_g.firstline = false
end
--- make each objects
-function _make_each_objects(target, sourcekind, sourcebatch)
+-- make objects
+function _make_objects(target, sourcekind, sourcebatch)
for index, objectfile in ipairs(sourcebatch.objectfiles) do
_make_object(target, sourcebatch.sourcefiles[index], objectfile)
end
end
-
--- make single object
-function _make_single_object(target, sourcekind, sourcebatch)
-
- -- not supported now, ignore it directly
- for _, sourcefile in ipairs(table.wrap(sourcebatch.sourcefiles)) do
- cprint("${bright yellow}warning: ${default yellow}ignore[%s]: %s", target:name(), sourcefile)
- end
-end
-- make target
function _make_target(target)
@@ -73,13 +64,10 @@ function _make_target(target)
target:set("pcxxheader", nil)
-- build source batches
- for sourcekind, sourcebatch in pairs(target:sourcebatches()) do
- if not sourcebatch.rulename then
- if type(sourcebatch.objectfiles) == "string" then
- _make_single_object(target, sourcekind, sourcebatch)
- else
- _make_each_objects(target, sourcekind, sourcebatch)
- end
+ for _, sourcebatch in pairs(target:sourcebatches()) do
+ local sourcekind = sourcebatch.sourcekind
+ if sourcekind then
+ _make_objects(target, sourcekind, sourcebatch)
end
end
end
diff --git a/xmake/plugins/project/make/makefile.lua b/xmake/plugins/project/make/makefile.lua
index cc15a914f..6b90fc914 100644
--- a/xmake/plugins/project/make/makefile.lua
+++ b/xmake/plugins/project/make/makefile.lua
@@ -209,63 +209,14 @@ function _make_object(makefile, target, sourcefile, objectfile, sourceflags)
makefile:print("")
end
--- make each objects
-function _make_each_objects(makefile, target, sourcekind, sourcebatch, sourceflags)
+-- make objects
+function _make_objects(makefile, target, sourcekind, sourcebatch, sourceflags)
-- make them
for index, objectfile in ipairs(sourcebatch.objectfiles) do
_make_object(makefile, target, sourcebatch.sourcefiles[index], objectfile, sourceflags)
end
end
-
--- make single object
-function _make_single_object(makefile, target, sourcekind, sourcebatch, sourceflags)
-
- -- get source and object files
- local sourcefiles = sourcebatch.sourcefiles
- local objectfiles = sourcebatch.objectfiles
- local dependfiles = sourcebatch.dependfiles
-
- -- get program
- local program = platform.tool(sourcekind)
-
- -- make command
- local macro = "$(" .. target:name() .. '_' .. sourcekind:upper() .. ")"
- local command = compiler.compcmd(sourcefiles, objectfiles, {compflags = macro})
-
- -- replace program to $(XX)
- local p, e = command:find(program, 1, true)
- if p then
- command = format("%s$(%s)%s", command:sub(1, p - 1), sourcekind:upper(), command:sub(e + 1))
- end
-
- -- replace ccache to $(CCACHE)
- local ccache = false
- p, e = command:find("ccache", 1, true)
- if p then
- command = format("%s$(%s)%s", command:sub(1, p - 1), "CCACHE", command:sub(e + 1))
- ccache = true
- end
-
- -- make head
- makefile:printf("%s:", objectfiles)
-
- -- make dependence
- for _, sourcefile in ipairs(sourcefiles) do
- makefile:printf(" %s", sourcefile)
- end
- makefile:print("")
-
- -- make body
- for _, sourcefile in ipairs(sourcefiles) do
- makefile:print("\t@echo %scompiling.$(mode) %s", ifelse(ccache, "ccache ", ""), sourcefile)
- end
- _mkdir(makefile, path.directory(objectfiles))
- makefile:writef("\t@%s > %s 2>&1\n", command, _logfile())
-
- -- make tail
- makefile:print("")
-end
-- make phony
function _make_phony(makefile, target)
@@ -360,15 +311,12 @@ function _make_target(makefile, target, targetflags)
makefile:print("")
-- build source batches
- for sourcekind, sourcebatch in pairs(target:sourcebatches()) do
- if not sourcebatch.rulename then
+ for _, sourcebatch in pairs(target:sourcebatches()) do
+ local sourcekind = sourcebatch.sourcekind
+ if sourcekind then
-- compile source files to single object at once
local sourceflags = targetflags[target:name() .. '_' .. sourcekind:upper()]
- if type(sourcebatch.objectfiles) == "string" then
- _make_single_object(makefile, target, sourcekind, sourcebatch, sourceflags)
- else
- _make_each_objects(makefile, target, sourcekind, sourcebatch, sourceflags)
- end
+ _make_objects(makefile, target, sourcekind, sourcebatch, sourceflags)
end
end
end
@@ -412,8 +360,9 @@ function _make_all(makefile)
local targetflags = {}
for targetname, target in pairs(project.targets()) do
if not target:isphony() then
- for sourcekind, sourcebatch in pairs(target:sourcebatches()) do
- if not sourcebatch.rulename then
+ for _, sourcebatch in pairs(target:sourcebatches()) do
+ local sourcekind = sourcebatch.sourcekind
+ if sourcekind then
local commonflags, sourceflags = _make_common_flags(target, sourcekind, sourcebatch)
makefile:print("%s_%s=%s", targetname, sourcekind:upper(), os.args(commonflags))
targetflags[targetname .. '_' .. sourcekind:upper()] = sourceflags
diff --git a/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua b/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua
index 106b97709..149330276 100644
--- a/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua
+++ b/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua
@@ -251,8 +251,9 @@ function _make_configurations(vcprojfile, vsinfo, target, vcprojdir)
-- save compiler flags
local compflags=nil
- for sourcekind, sourcebatch in pairs(target:sourcebatches()) do
- if not sourcebatch.rulename then
+ for _, sourcebatch in pairs(target:sourcebatches()) do
+ local sourcekind = sourcebatch.sourcekind
+ if sourcekind then
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
local flags = compiler.compflags(sourcefile, {target = target})
if sourcekind == "cc" or sourcekind == "cxx" then
@@ -526,7 +527,8 @@ function _make_files(vcprojfile, vsinfo, target, vcprojdir)
local sourcebatches = target:sourcebatches()
-- c/cxx files
vcprojfile:enter("<Filter Name=\"Source Files\">")
- for sourcekind, sourcebatch in pairs(sourcebatches) do
+ for _, sourcebatch in pairs(sourcebatches) do
+ local sourcekind = sourcebatch.sourcekind
if sourcekind ~= "mrc" then
local objectfiles = sourcebatch.objectfiles
for idx, sourcefile in ipairs(sourcebatch.sourcefiles) do
@@ -540,7 +542,8 @@ function _make_files(vcprojfile, vsinfo, target, vcprojdir)
-- *.rc files
vcprojfile:enter("<Filter Name=\"Resource Files\">")
- for sourcekind, sourcebatch in pairs(sourcebatches) do
+ for _, sourcebatch in pairs(sourcebatches) do
+ local sourcekind = sourcebatch.sourcekind
if sourcekind == "mrc" then
local objectfiles = sourcebatch.objectfiles
for idx, sourcefile in ipairs(sourcebatch.sourcefiles) do
diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua
index af0a18d0c..4d68019bb 100644
--- a/xmake/plugins/project/vstudio/impl/vs201x.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x.lua
@@ -74,8 +74,9 @@ function _make_targetinfo(mode, arch, target)
local firstcompflags = nil
targetinfo.compflags = {}
targetinfo.compargvs = {}
- for sourcekind, sourcebatch in pairs(target:sourcebatches()) do
- if not sourcebatch.rulename then
+ for _, sourcebatch in pairs(target:sourcebatches()) do
+ local sourcekind = sourcebatch.sourcekind
+ if sourcekind then
for idx, sourcefile in ipairs(sourcebatch.sourcefiles) do
local compflags = compiler.compflags(sourcefile, {target = target})
if not firstcompflags and (sourcekind == "cc" or sourcekind == "cxx") then
diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
index 8f6549281..65a6bad0a 100644
--- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
@@ -457,8 +457,9 @@ function _make_common_items(vcxprojfile, vsinfo, target, vcxprojdir)
local files_count = 0
local first_flags = nil
targetinfo.sourceflags = {}
- for sourcekind, sourcebatch in pairs(targetinfo.sourcebatches) do
- if not sourcebatch.rulename and (sourcekind == "cc" or sourcekind == "cxx" or sourcekind == "as" or sourcekind == "mrc") then
+ for _, sourcebatch in pairs(targetinfo.sourcebatches) do
+ local sourcekind = sourcebatch.sourcekind
+ if (sourcekind == "cc" or sourcekind == "cxx" or sourcekind == "as" or sourcekind == "mrc") then
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
-- make compiler flags
@@ -715,8 +716,9 @@ function _make_source_files(vcxprojfile, vsinfo, target, vcxprojdir)
-- make source file infos
local sourceinfos = {}
for _, targetinfo in ipairs(target.info) do
- for sourcekind, sourcebatch in pairs(targetinfo.sourcebatches) do
- if not sourcebatch.rulename and (sourcekind == "cc" or sourcekind == "cxx" or sourcekind == "as" or sourcekind == "mrc") then
+ for _, sourcebatch in pairs(targetinfo.sourcebatches) do
+ local sourcekind = sourcebatch.sourcekind
+ if (sourcekind == "cc" or sourcekind == "cxx" or sourcekind == "as" or sourcekind == "mrc") then
local objectfiles = sourcebatch.objectfiles
for idx, sourcefile in ipairs(sourcebatch.sourcefiles) do
local objectfile = objectfiles[idx]
diff --git a/xmake/rules/cuda/devlink/xmake.lua b/xmake/rules/cuda/devlink/xmake.lua
index 2854bc0d7..83a719381 100644
--- a/xmake/rules/cuda/devlink/xmake.lua
+++ b/xmake/rules/cuda/devlink/xmake.lua
@@ -65,8 +65,8 @@ rule("cuda.devlink")
-- get object files
local objectfiles = nil
- for sourcekind, sourcebatch in pairs(target:sourcebatches()) do
- if sourcekind == "cu" then
+ for _, sourcebatch in pairs(target:sourcebatches()) do
+ if sourcebatch.sourcekind == "cu" then
objectfiles = sourcebatch.objectfiles
end
end