summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-05-17 08:26:16 +0800
committerruki <[email protected]>2017-05-17 08:26:16 +0800
commit807c7db15fa3a5e640ecde32ede9e72c4d64391c (patch)
tree1ff7f32ba10ab23be15aff70167267996625c9f8
parentc354c862526c9a149060639057bca380128a147a (diff)
improve find_program cache
-rw-r--r--xmake/core/project/cache.lua12
-rw-r--r--xmake/core/project/project.lua19
-rw-r--r--xmake/core/sandbox/modules/import/core/project/project.lua4
-rw-r--r--xmake/core/sandbox/modules/import/lib/detect/find_program.lua15
4 files changed, 39 insertions, 11 deletions
diff --git a/xmake/core/project/cache.lua b/xmake/core/project/cache.lua
index 1b3b63c7f..d96f12e00 100644
--- a/xmake/core/project/cache.lua
+++ b/xmake/core/project/cache.lua
@@ -56,6 +56,13 @@ function cache._instance(scopename)
-- init instance
local instance = table.inherit(cache)
+ -- memory cache?
+ if scopename:startswith("memory.") then
+ instance._CACHEDATA = instance._CACHEDATA or {__version = xmake._VERSION_SHORT}
+ instances[scopename] = instance
+ return instance
+ end
+
-- check scopename
if not scopename:find("local%.") and not scopename:find("global%.") then
os.raise("invalid cache scope: %s", scopename)
@@ -110,6 +117,11 @@ function cache:flush()
-- flush the version
self._CACHEDATA.__version = xmake._VERSION_SHORT
+ -- memory cache? ignore it directly
+ if not self._CACHEPATH then
+ return true
+ end
+
-- save to file
return io.save(self._CACHEPATH, self._CACHEDATA)
end
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index 5fdc43636..6dff6d1a4 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -365,6 +365,13 @@ function project._load_target_deps(target, targets)
return table.unique(deptargets)
end
+-- get the project file
+function project.file()
+
+ -- get it
+ return xmake._PROJECT_FILE
+end
+
-- get the project directory
function project.directory()
@@ -420,7 +427,7 @@ function project.get(name)
assert(interp)
-- load infos
- infos = interp:load(xmake._PROJECT_FILE, nil, true, true)
+ infos = interp:load(project.file(), nil, true, true)
project._INFOS = infos
end
@@ -444,7 +451,7 @@ function project.load()
end
-- load targets
- local results, errors = interp:load(xmake._PROJECT_FILE, "target", true, true)
+ local results, errors = interp:load(project.file(), "target", true, true)
if not results then
return false, errors
end
@@ -505,7 +512,7 @@ function project.options(enable_filter)
assert(interp)
-- load the options from the the project file
- local results, errors = interp:load(xmake._PROJECT_FILE, "option", true, enable_filter)
+ local results, errors = interp:load(project.file(), "option", true, enable_filter)
if not results then
return nil, errors
end
@@ -538,12 +545,12 @@ function project.tasks()
assert(interp)
-- the project file is not found?
- if not os.isfile(xmake._PROJECT_FILE) then
+ if not os.isfile(project.file()) then
return {}, nil
end
-- load the tasks from the the project file
- local results, errors = interp:load(xmake._PROJECT_FILE, "task", true, true)
+ local results, errors = interp:load(project.file(), "task", true, true)
if not results then
return nil, errors
end
@@ -569,7 +576,7 @@ function project.menu()
-- attempt to load options from the project file
local options = nil
local errors = nil
- if os.isfile(xmake._PROJECT_FILE) then
+ if os.isfile(project.file()) then
options, errors = project.options(false)
end
diff --git a/xmake/core/sandbox/modules/import/core/project/project.lua b/xmake/core/sandbox/modules/import/core/project/project.lua
index 56257fbc2..2b5643e90 100644
--- a/xmake/core/sandbox/modules/import/core/project/project.lua
+++ b/xmake/core/sandbox/modules/import/core/project/project.lua
@@ -73,14 +73,14 @@ end
function sandbox_core_project.file()
-- get it
- return xmake._PROJECT_FILE
+ return project.file()
end
-- get the project directory
function sandbox_core_project.directory()
-- get it
- return xmake._PROJECT_DIR
+ return project.directory()
end
-- get the project mtimes
diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua
index 2399c717b..3e9a378e2 100644
--- a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua
+++ b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua
@@ -31,12 +31,11 @@ local path = require("base/path")
local table = require("base/table")
local utils = require("base/utils")
local option = require("base/option")
+local cache = require("project/cache")
+local project = require("project/project")
local sandbox = require("sandbox/sandbox")
local raise = require("sandbox/modules/raise")
--- the cache info
-local cacheinfo = cacheinfo or {}
-
-- check program
function sandbox_lib_detect_find_program._check(program, check)
@@ -92,8 +91,14 @@ end
-- @return the program name or path
--
function sandbox_lib_detect_find_program.main(name, dirs, check)
+
+ -- TODO get version info
+
+ -- get detect cache
+ local detectcache = cache(utils.ifelse(os.isfile(project.file()), "local.detect", "memory.detect"))
-- attempt to get result from cache first
+ local cacheinfo = detectcache:get("find_program") or {}
local result = cacheinfo[name]
if result then
return result
@@ -116,6 +121,10 @@ function sandbox_lib_detect_find_program.main(name, dirs, check)
end
end
+ -- save cache info
+ detectcache:set("find_program", cacheinfo)
+ detectcache:flush()
+
-- ok?
return result
end