summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-09-13 23:13:53 +0800
committerruki <[email protected]>2017-09-13 13:23:21 +0800
commit421042632a667802b8a50580c83342d5282893c8 (patch)
tree388a5c0997ee41bc7ce8000b296befee937e2d8e
parent93b2fbf41ca193a025a3bd96c946570b425f281c (diff)
fix config header for package requires
-rw-r--r--xmake/actions/build/main.lua3
-rw-r--r--xmake/actions/config/configheader.lua4
-rw-r--r--xmake/actions/config/main.lua28
-rw-r--r--xmake/actions/require/install.lua56
-rw-r--r--xmake/core/project/option.lua13
-rw-r--r--xmake/plugins/project/vstudio/impl/vs201x.lua6
6 files changed, 65 insertions, 45 deletions
diff --git a/xmake/actions/build/main.lua b/xmake/actions/build/main.lua
index 4f8fc4cfd..6206e5e4e 100644
--- a/xmake/actions/build/main.lua
+++ b/xmake/actions/build/main.lua
@@ -39,9 +39,6 @@ function main()
-- config it first
task.run("config", {target = targetname})
- -- require all dependences
- task.run("require")
-
-- enter project directory
local oldir = os.cd(project.directory())
diff --git a/xmake/actions/config/configheader.lua b/xmake/actions/config/configheader.lua
index 9e39eee9d..df2573341 100644
--- a/xmake/actions/config/configheader.lua
+++ b/xmake/actions/config/configheader.lua
@@ -126,8 +126,8 @@ function _make_for_target_with_deps(targetname)
end
end
--- make the config.h
-function make()
+-- the main entry function
+function main()
-- the target name
local targetname = option.get("target")
diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua
index 401015efc..47c3c14ef 100644
--- a/xmake/actions/config/main.lua
+++ b/xmake/actions/config/main.lua
@@ -31,7 +31,8 @@ import("core.platform.platform")
import("core.project.cache", {nocache = true})
import("lib.detect.cache", {alias = "detectcache"})
import("scanner")
-import("configheader")
+import("configheader", {alias = "generate_configheader"})
+import("actions.require.install", {alias = "install_requires", rootdir = os.programdir()})
-- filter option
function _option_filter(name)
@@ -259,6 +260,21 @@ function main()
-- check target
_check_target(targetname)
+ -- install and update requires and config header
+ if recheck then
+
+ -- install requires
+ install_requires()
+
+ -- generate config header
+ generate_configheader()
+ end
+
+ -- dump config
+ if option.get("verbose") then
+ config.dump()
+ end
+
-- save options and configure for the given target
config.save(targetname)
cache.set("options_" .. targetname, options)
@@ -273,14 +289,4 @@ function main()
-- flush cache
cache.flush()
-
- -- make the config.h
- if recheck then
- configheader.make()
- end
-
- -- dump config
- if option.get("verbose") then
- config.dump()
- end
end
diff --git a/xmake/actions/require/install.lua b/xmake/actions/require/install.lua
index 57573e1c1..5192eb952 100644
--- a/xmake/actions/require/install.lua
+++ b/xmake/actions/require/install.lua
@@ -33,35 +33,39 @@ import("environment")
-- attach package to option
function _attach_to_option(instance, opt)
- opt:add((instance:fetch()))
- local orderdeps = instance:orderdeps()
- if orderdeps then
- local total = #orderdeps
- for idx, _ in ipairs(orderdeps) do
- local dep = orderdeps[total + 1 - idx]
- opt:add((dep:fetch()))
+
+ -- disable this option if this package is optional and missing
+ if _g.optional_missing[instance:fullname()] then
+ opt:enable(false)
+ else
+
+ -- add this package info to option
+ opt:add(instance:fetch())
+
+ -- add all dependent packages info to option
+ local orderdeps = instance:orderdeps()
+ if orderdeps then
+ local total = #orderdeps
+ for idx, _ in ipairs(orderdeps) do
+ local dep = orderdeps[total + 1 - idx]
+ if dep then
+ opt:add((dep:fetch()))
+ end
+ end
end
end
+
+ -- update option info to the cache file
+ opt:save()
end
-- attach all packages to targets
function _attach_to_targets(packages)
- -- get all local paclages
- local packages_local = {}
for _, instance in ipairs(packages) do
- packages_local[instance:fullname()] = instance
- end
-
- -- add all local packages to targets
- for _, target in pairs(project.targets()) do
- for _, opt in ipairs(target:options()) do
- if opt:enabled() then
- local instance = packages_local[opt:name()]
- if instance then
- _attach_to_option(instance, opt)
- end
- end
+ local opt = project.option(instance:fullname())
+ if opt and opt:enabled() then
+ _attach_to_option(instance, opt)
end
end
end
@@ -71,9 +75,12 @@ function _check_missing_packages(packages)
-- get all missing packages
local packages_missing = {}
+ local optional_missing = {}
for _, instance in ipairs(packages) do
- if not instance:exists() and not instance:requireinfo().optional then
- if #instance:urls() > 0 or instance:from("system") then
+ if not instance:exists() and (#instance:urls() > 0 or instance:from("system")) then
+ if instance:requireinfo().optional then
+ optional_missing[instance:fullname()] = instance
+ else
table.insert(packages_missing, instance:fullname())
end
end
@@ -83,6 +90,9 @@ function _check_missing_packages(packages)
if #packages_missing > 0 then
raise("The packages(%s) not found!", table.concat(packages_missing, ", "))
end
+
+ -- save the optional missing packages
+ _g.optional_missing = optional_missing
end
-- install packages
diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua
index 46aa9376b..286326575 100644
--- a/xmake/core/project/option.lua
+++ b/xmake/core/project/option.lua
@@ -228,11 +228,18 @@ function option:enabled()
end
-- enable or disable this option
-function option:enable(enabled)
+--
+-- @param enabled enable option?
+-- @param opt the argument options, .e.g {readonly = true, force = false}
+--
+function option:enable(enabled, opt)
+
+ -- init options
+ opt = opt or {}
-- enable or disable this option?
- if not config.readonly(self:name()) then
- config.set(self:name(), enabled)
+ if not config.readonly(self:name()) or opt.force then
+ config.set(self:name(), enabled, opt)
end
-- save or clear this option in cache
diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua
index 4c50c1936..6cbb036ab 100644
--- a/xmake/plugins/project/vstudio/impl/vs201x.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x.lua
@@ -33,7 +33,7 @@ import("core.tool.linker")
import("vs201x_solution")
import("vs201x_vcxproj")
import("vs201x_vcxproj_filters")
-import("actions.config.configheader", {rootdir = os.programdir()})
+import("actions.config.configheader", {alias = "generate_configheader", rootdir = os.programdir()})
-- make target info
function _make_targetinfo(mode, arch, target)
@@ -181,8 +181,8 @@ function make(outputdir, vsinfo)
-- reload platform
platform.load(config.plat())
- -- remake configheader
- configheader.make()
+ -- re-generate configheader
+ generate_configheader()
end
-- ensure to enter project directory