-
Notifications
You must be signed in to change notification settings - Fork 2
/
package.lua
84 lines (68 loc) · 1.87 KB
/
package.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
---
-- Package management module
-- Legacy "Package" API.
-- Copyright (c) 2014-2017 Blizzard Entertainment
---
local p = premake
local m = p.modules.packagemanager
package = package or {}
---
-- get a previously imported package by name.
---
function package.get(name)
local result = p.packagemanager.getPackage(name)
if not result then
p.error("Package was not imported; use 'import { ['" .. name .. "'] = 'version' }'.")
end
return result
end
---
-- See if a previously imported package was imported.
---
function package.isimported(name)
return p.packagemanager.getPackage(name) ~= nil
end
---
-- check package version. Comparisions take the form of ">=5.0" (5.0 or later),
-- "5.0" (5.0 or later), ">=5.0 <6.0" (5.0 or later but not 6.0 or later).
---
function package.require(name, checks)
local pkg = p.packagemanager.getPackage(name)
if pkg == nil then
p.error("Package was not imported; use 'import { ['" .. name .. "'] = 'version' }'.")
end
if not p.checkVersion(pkg.version, checks) then
p.error("Package version '" .. pkg.version .. "' does not meet '" .. checks .. "' requirement.")
end
end
---
-- Import a set of packages.
---
function import(tbl)
if package.current then
p.error('Packages cannot import other package, only the top-level workspace can do that')
end
return p.packagemanager.import(tbl)
end
---
-- Get an option for a package.
---
function getpackageoption(name, option)
return p.packagemanager.getPackageOption(name, option)
end
---
-- Execute all test scripts
---
function includePackageTests()
local wks = p.api.scope.workspace
if wks == nil then
p.error("No workspace in scope.", 3)
end
-- go through each variant that is loaded, and execute the initializer.
for name, pkg in pairs(wks.package_cache) do
-- don't process aliases.
if name == pkg.name then
pkg:includeTests()
end
end
end