Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve rules and generators #1245

Merged
merged 14 commits into from
Feb 20, 2021
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ winenv/
*.7z
*.run

# for compiler
compile_commands.json

# Makefile generation
/core/xmake.config.h
/core/.config.mak
Expand Down
37 changes: 35 additions & 2 deletions xmake/actions/build/kinds/object.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import("core.project.rule")
import("core.project.config")
import("core.project.project")
import("private.async.runjobs")
import("private.utils.batchcmds")

-- add batch jobs for the custom rule
function _add_batchjobs_for_rule(batchjobs, rootjob, target, sourcebatch, suffix)
Expand All @@ -32,7 +33,7 @@ function _add_batchjobs_for_rule(batchjobs, rootjob, target, sourcebatch, suffix
local rulename = assert(sourcebatch.rulename, "unknown rule for sourcebatch!")
local ruleinst = assert(project.rule(rulename) or rule.rule(rulename), "unknown rule: %s", rulename)

-- add batch jobs
-- add batch jobs for xx_build_files
local scriptname = "build_files" .. (suffix and ("_" .. suffix) or "")
local script = ruleinst:script(scriptname)
if script then
Expand All @@ -43,7 +44,10 @@ function _add_batchjobs_for_rule(batchjobs, rootjob, target, sourcebatch, suffix
script(target, sourcebatch, {progress = (index * 100) / total})
end, rootjob)
end
else
end

-- add batch jobs for xx_build_file
if not script then
scriptname = "build_file" .. (suffix and ("_" .. suffix) or "")
script = ruleinst:script(scriptname)
if script then
Expand All @@ -55,6 +59,35 @@ function _add_batchjobs_for_rule(batchjobs, rootjob, target, sourcebatch, suffix
end
end
end

-- add batch jobs for xx_buildcmd_files
if not script then
scriptname = "buildcmd_files" .. (suffix and ("_" .. suffix) or "")
script = ruleinst:script(scriptname)
if script then
batchjobs:addjob("rule/" .. rulename .. "/" .. scriptname, function (index, total)
local batchcmds_ = batchcmds.new({target = target})
script(target, batchcmds_, sourcebatch, {progress = (index * 100) / total})
batchcmds_:runcmds({dryrun = option.get("dry-run")})
end, rootjob)
end
end

-- add batch jobs for xx_buildcmd_file
if not script then
scriptname = "buildcmd_file" .. (suffix and ("_" .. suffix) or "")
script = ruleinst:script(scriptname)
if script then
local sourcekind = sourcebatch.sourcekind
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
batchjobs:addjob(sourcefile, function (index, total)
local batchcmds_ = batchcmds.new({target = target})
script(target, batchcmds_, sourcefile, {sourcekind = sourcekind, progress = (index * 100) / total})
batchcmds_:runcmds({dryrun = option.get("dry-run")})
end, rootjob)
end
end
end
end

-- add batch jobs for target
Expand Down
9 changes: 9 additions & 0 deletions xmake/core/project/rule.lua
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ function rule.apis()
, "rule.on_package"
, "rule.on_install"
, "rule.on_uninstall"
, "rule.on_buildcmd"
, "rule.on_buildcmd_file"
, "rule.on_buildcmd_files"
-- rule.before_xxx
, "rule.before_run"
, "rule.before_load"
Expand All @@ -184,6 +187,9 @@ function rule.apis()
, "rule.before_package"
, "rule.before_install"
, "rule.before_uninstall"
, "rule.before_buildcmd"
, "rule.before_buildcmd_file"
, "rule.before_buildcmd_files"
-- rule.after_xxx
, "rule.after_run"
, "rule.after_load"
Expand All @@ -195,6 +201,9 @@ function rule.apis()
, "rule.after_package"
, "rule.after_install"
, "rule.after_uninstall"
, "rule.after_buildcmd"
, "rule.after_buildcmd_file"
, "rule.after_buildcmd_files"
}
}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ function main(requires, opt)
-- fetch and register packages (with system) from local first
runjobs("fetch_packages", function (index)
local instance = packages[index]
if instance and (not option.get("force") or (option.get("shallow") and instance:is_toplevel())) then
if instance and (not option.get("force") or (option.get("shallow") and not instance:is_toplevel())) then
instance:envs_enter()
instance:fetch()
instance:envs_leave()
Expand Down
Loading