-
Notifications
You must be signed in to change notification settings - Fork 36
/
msvc.lua
111 lines (96 loc) · 2.66 KB
/
msvc.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
local find_msvc = require "env.find_msvc"
local fs = require "bee.filesystem"
local fsutil = require "fsutil"
local globals = require "globals"
local m = {}
local env
local prefix
local ArchAlias = {
x86_64 = "x64",
x86 = "x86",
}
local function getConsoleCP()
local f = io.popen("chcp", "r")
if f then
local data = f:read "a"
return data:match "%d+"
end
end
local function readEnvConfig()
local EnvConfig = fsutil.join(WORKDIR, globals.builddir, "env.lua")
local f <close> = assert(io.open(EnvConfig, "r"))
local data = assert(f:read "a")
local config = assert(load(data, "t", nil))()
f:close()
return config
end
local function writeEnvConfig(data)
local EnvConfig = fsutil.join(WORKDIR, globals.builddir, "env.lua")
local f <close> = assert(io.open(EnvConfig, "w"))
f:write(data)
end
local function updateEnvConfig()
if not env then
local config = readEnvConfig()
env = config.env
prefix = config.prefix
end
end
function m.hasEnvConfig()
local EnvConfig = fsutil.join(WORKDIR, globals.builddir, "env.lua")
return fs.exists(EnvConfig)
end
function m.cleanEnvConfig()
local EnvConfig = fsutil.join(WORKDIR, globals.builddir, "env.lua")
fs.remove(EnvConfig)
end
function m.createEnvConfig(arch, rebuild)
local console_cp = getConsoleCP()
if not rebuild and m.hasEnvConfig() then
local config = readEnvConfig()
if config.arch == arch
and (not console_cp or config.console_cp == console_cp)
and config.toolspath and fs.exists(config.toolspath)
then
env = config.env
prefix = config.prefix
return
end
end
local winsdk = find_msvc.findwinsdk()
env = find_msvc.environment(winsdk, ArchAlias[arch])
prefix = find_msvc.prefix(env)
local s = {}
s[#s+1] = "return {"
s[#s+1] = ("arch=%q,"):format(arch)
s[#s+1] = ("toolspath=%q,"):format(find_msvc.toolspath())
s[#s+1] = ("console_cp=%q,"):format(console_cp)
if winsdk then
s[#s+1] = ("winsdk=%q,"):format(winsdk)
end
s[#s+1] = ("prefix=%q,"):format(prefix)
s[#s+1] = "env={"
for name, value in pairs(env) do
s[#s+1] = ("%s=%q,"):format(name, value)
end
s[#s+1] = "},"
s[#s+1] = "}"
s[#s+1] = ""
writeEnvConfig(table.concat(s, "\n"))
end
function m.getEnv()
updateEnvConfig()
return env
end
function m.getPrefix()
updateEnvConfig()
return prefix
end
function m.archAlias(arch)
return ArchAlias[arch]
end
m.binpath = find_msvc.binpath
m.vcrtpath = find_msvc.vcrtpath
m.ucrtpath = find_msvc.ucrtpath
m.llvmpath = find_msvc.llvmpath
return m