@@ -139,18 +139,39 @@ function _get_envsdir_builtin()
139
139
return path .join (os .programdir (), " scripts" , " xrepo" , " envs" )
140
140
end
141
141
142
- -- get bound environment or packages
143
- function _get_boundenv (opt )
142
+ -- get envfironment files
143
+ function _get_envfiles ()
144
+ local envfiles = {}
145
+ for _ , envsdir in ipairs ({_get_envsdir (), _get_envsdir_builtin ()}) do
146
+ for _ , envfile in ipairs (os .files (path .join (envsdir , " *.lua" ))) do
147
+ envfiles [path .basename (envfile )] = envfile
148
+ end
149
+ end
150
+ return envfiles
151
+ end
152
+
153
+ -- get bound environment files or packages
154
+ function _get_boundenvs (opt )
155
+ local packages = {}
156
+ local files = {}
144
157
local bind = (opt and opt .bind ) or option .get (" bind" )
145
158
if bind then
146
- for _ , envsdir in ipairs ({_get_envsdir (), _get_envsdir_builtin ()}) do
147
- local envfile = path .join (envsdir , bind .. " .lua" )
148
- if envfile and os .isfile (envfile ) then
149
- return envfile
159
+ local envfiles = _get_envfiles ()
160
+ for _ , binditem in ipairs (bind :split (' ,' , {plain = true })) do
161
+ binditem = binditem :trim ()
162
+ if envfiles [binditem ] then
163
+ table.insert (files , envfiles [binditem ])
164
+ else
165
+ table.insert (packages , binditem )
150
166
end
151
167
end
168
+ else
169
+ local program = option .get (" program" )
170
+ if program then
171
+ table.insert (packages , program )
172
+ end
152
173
end
153
- return bind
174
+ return packages , files
154
175
end
155
176
156
177
-- add values to environment variable
@@ -244,19 +265,13 @@ end
244
265
-- get package environments
245
266
function _package_getenvs (opt )
246
267
local envs = os .getenvs ()
247
- local boundenv = _get_boundenv (opt )
248
- local has_envfile = false
249
- local packages = nil
250
- if boundenv and os .isfile (boundenv ) then
251
- has_envfile = true
252
- else
253
- packages = boundenv or option .get (" program" )
254
- end
268
+ local packages , envfiles = _get_boundenvs (opt )
269
+ local has_envfile = # envfiles > 0
255
270
local oldir = os .curdir ()
256
- if (os .isfile (os .projectfile ()) and not boundenv ) or has_envfile then
271
+ if (os .isfile (os .projectfile ()) and not option . get ( " bind " ) ) or has_envfile then
257
272
if has_envfile then
258
273
_enter_project ()
259
- table.insert (project .rcfiles (), boundenv )
274
+ table .join2 (project .rcfiles (), envfiles )
260
275
end
261
276
task .run (" config" , {}, {disable_dump = true })
262
277
_toolchain_addenvs (envs )
@@ -267,10 +282,9 @@ function _package_getenvs(opt)
267
282
if not has_envfile then
268
283
_target_addenvs (envs )
269
284
end
270
- elseif packages then
285
+ elseif # packages > 0 then
271
286
_enter_project ()
272
287
local envfile = os .tmpfile () .. " .lua"
273
- packages = packages :split (' ,' , {plain = true })
274
288
local file = io.open (envfile , " w" )
275
289
for _ , requirename in ipairs (packages ) do
276
290
file :print (" add_requires(\" %s\" )" , requirename )
@@ -337,13 +351,13 @@ end
337
351
function _get_prompt (bnd )
338
352
bnd = bnd or option .get (" bind" )
339
353
local prompt
340
- local boundenv = _get_boundenv ({bind = bnd })
341
- if boundenv then
342
- if os . isfile ( boundenv ) then
343
- prompt = path .basename (boundenv )
354
+ local packages , envfiles = _get_boundenvs ({bind = bnd })
355
+ if # packages > 0 or # envfiles > 0 then
356
+ if # packages == 0 and # envfiles == 1 then
357
+ prompt = path .basename (envfiles [ 1 ] )
344
358
else
345
- prompt = boundenv :sub (1 , math.min (# boundenv , 16 ))
346
- if boundenv ~= prompt then
359
+ prompt = bnd :sub (1 , math.min (# bnd , 16 ))
360
+ if bnd ~= prompt then
347
361
prompt = prompt .. " .."
348
362
end
349
363
end
0 commit comments