summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-03-11 22:57:43 +0800
committerruki <[email protected]>2019-03-11 11:46:24 +0800
commit6e4c9f31810a9b5053b2d0b72056fd5552bcd8b4 (patch)
treee7240807f555fd8412823b69d76afe3387e7eb49
parente6b992ae11a7a2fce3239e4e35b19240eff3ccf7 (diff)
save package manifest
-rw-r--r--xmake/actions/require/impl/action/install.lua7
-rw-r--r--xmake/core/base/string.lua6
-rw-r--r--xmake/core/package/package.lua51
3 files changed, 53 insertions, 11 deletions
diff --git a/xmake/actions/require/impl/action/install.lua b/xmake/actions/require/impl/action/install.lua
index a1026de12..f90ed27ae 100644
--- a/xmake/actions/require/impl/action/install.lua
+++ b/xmake/actions/require/impl/action/install.lua
@@ -87,8 +87,7 @@ function main(package)
else
-- build and install package to the install directory
- local installedfile = path.join(package:installdir(), "installed.txt")
- if not os.isfile(installedfile) then
+ if not package:manifest_load() then
-- clean install directory first
os.tryrm(package:installdir())
@@ -101,8 +100,8 @@ function main(package)
end
end
- -- mark as installed
- io.writefile(installedfile, "")
+ -- save the package info to the manifest file
+ package:manifest_save()
end
-- test it
diff --git a/xmake/core/base/string.lua b/xmake/core/base/string.lua
index c3f3958d5..cf6f7b124 100644
--- a/xmake/core/base/string.lua
+++ b/xmake/core/base/string.lua
@@ -43,7 +43,9 @@ function string._makestr(object, deflate, serialize, level)
if deflate then
s = s .. "{"
else
- s = s .. "\n"
+ if level > 0 then
+ s = s .. "\n"
+ end
for l = 1, level do
s = s .. " "
end
@@ -69,7 +71,7 @@ function string._makestr(object, deflate, serialize, level)
-- make key = value
if type(k) == "string" then
- if serialize then
+ if serialize and not k:match("^%a[%w_]+$") then
k = string.format("[%q]", k)
end
if deflate then
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 625969b89..f213cb234 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -222,18 +222,59 @@ end
-- get the installed directory of this package
function _instance:installdir(...)
-
- -- make the given install directory
local name = self:name():lower():gsub("::", "_")
local dir = path.join(package.installdir(), name:sub(1, 1):lower(), name, self:version_str(), self:buildhash(), ...)
-
- -- ensure the install directory
if not os.isdir(dir) then
os.mkdir(dir)
end
return dir
end
+-- get the manifest file of this package
+function _instance:manifest_file()
+ return path.join(self:installdir(), "manifest.txt")
+end
+
+-- load the manifest file of this package
+function _instance:manifest_load()
+ local manifest_file = self:manifest_file()
+ if os.isfile(manifest_file) then
+ local manifest, errors = io.load(manifest_file)
+ if not manifest then
+ os.raise(errors)
+ end
+ return manifest
+ end
+end
+
+-- save the manifest file of this package
+function _instance:manifest_save()
+
+ -- make manifest
+ local manifest = {}
+ manifest.name = self:name()
+ manifest.description = self:description()
+ manifest.version = self:version_str()
+ manifest.kind = self:kind()
+ manifest.plat = self:plat()
+ manifest.arch = self:arch()
+ manifest.mode = self:mode()
+ manifest.configs = self:configs()
+ local repo = self:repo()
+ if repo then
+ manifest.repo = {}
+ manifest.repo.name = repo:name()
+ manifest.repo.url = repo:url()
+ manifest.repo.branch = repo:branch()
+ end
+
+ -- save manifest
+ local ok, errors = io.save(self:manifest_file(), manifest)
+ if not ok then
+ os.raise(errors)
+ end
+end
+
-- get prefix variables
function _instance:getvar(name)
-- TODO
@@ -653,7 +694,7 @@ end
-- the install directory
function package.installdir()
- return path.join(global.directory(), "installed")
+ return path.join(global.directory(), "packages")
end
-- get environment variables