Add new globals _PREMAKE_DIR, _MAIN_SCRIPT, and _MAIN_SCRIPT_DIR
This commit is contained in:
parent
287c592733
commit
962ab7935b
@ -22,6 +22,20 @@
|
||||
|
||||
math.randomseed(os.time())
|
||||
|
||||
-- Set some global to describe the runtime environment, building on
|
||||
-- what was already set by the native code host
|
||||
|
||||
_PREMAKE_DIR = path.getdirectory(_PREMAKE_COMMAND)
|
||||
|
||||
local file = _OPTIONS["file"] or "premake5.lua"
|
||||
local script = os.locate(file, file .. ".lua", "premake4.lua")
|
||||
if script then
|
||||
_MAIN_SCRIPT = path.getabsolute(script)
|
||||
_MAIN_SCRIPT_DIR = path.getdirectory(_MAIN_SCRIPT)
|
||||
else
|
||||
_MAIN_SCRIPT_DIR = _WORKING_DIR
|
||||
end
|
||||
|
||||
-- Look for and run the system-wide configuration script; make sure any
|
||||
-- configuration scoping gets cleared before continuing
|
||||
|
||||
@ -43,7 +57,9 @@
|
||||
-- If there is a project script available, run it to get the
|
||||
-- project information, available options and actions, etc.
|
||||
|
||||
local hasScript = dofileopt(_OPTIONS["file"] or { "premake5.lua", "premake4.lua" })
|
||||
if _MAIN_SCRIPT then
|
||||
dofile(_MAIN_SCRIPT)
|
||||
end
|
||||
|
||||
-- Process special options
|
||||
|
||||
@ -81,7 +97,7 @@
|
||||
return 1
|
||||
end
|
||||
|
||||
if not hasScript then
|
||||
if not _MAIN_SCRIPT then
|
||||
print("No Premake script (premake5.lua) found!")
|
||||
return 1
|
||||
end
|
||||
|
@ -5,46 +5,6 @@
|
||||
--
|
||||
|
||||
|
||||
---
|
||||
-- Helper for the dofile() and include() function: locate a script on the
|
||||
-- standard search paths of: the /scripts argument provided on the command
|
||||
-- line, then the PREMAKE_PATH environment variable.
|
||||
--
|
||||
-- @param ...
|
||||
-- A list of file names for which to search. The first one discovered
|
||||
-- is the one that will be returned.
|
||||
-- @return
|
||||
-- The path to file if found, or nil if not.
|
||||
---
|
||||
|
||||
local function locate(...)
|
||||
local function find(fname)
|
||||
-- is this a direct path to a file?
|
||||
if os.isfile(fname) then
|
||||
return fname
|
||||
end
|
||||
|
||||
-- find it on my paths
|
||||
local dir = os.pathsearch(fname, _OPTIONS["scripts"], os.getenv("PREMAKE_PATH"), path.getdirectory(_PREMAKE_COMMAND))
|
||||
if dir then
|
||||
return path.join(dir, fname)
|
||||
end
|
||||
end
|
||||
|
||||
for i = 1, select("#",...) do
|
||||
local fname = select(i, ...)
|
||||
local result = find(fname)
|
||||
if not result then
|
||||
result = find(fname .. ".lua")
|
||||
end
|
||||
if result then
|
||||
return result
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
---
|
||||
-- A replacement for Lua's built-in dofile() function that knows how to
|
||||
-- search for script files. Note that I've also modified luaL_loadfile()
|
||||
@ -55,7 +15,7 @@
|
||||
local builtin_dofile = dofile
|
||||
|
||||
function dofile(fname)
|
||||
fname = locate(fname) or fname
|
||||
fname = os.locate(fname) or fname
|
||||
return builtin_dofile(fname)
|
||||
end
|
||||
|
||||
@ -77,7 +37,10 @@
|
||||
function dofileopt(fname)
|
||||
if type(fname) == "string" then fname = {fname} end
|
||||
for i = 1, #fname do
|
||||
local found = locate(fname[i])
|
||||
local found = os.locate(fname[i])
|
||||
if not found then
|
||||
found = os.locate(fname[i] .. ".lua")
|
||||
end
|
||||
if found then
|
||||
dofile(found)
|
||||
return true
|
||||
@ -101,7 +64,7 @@
|
||||
io._includedFiles = {}
|
||||
|
||||
function include(fname)
|
||||
local found = locate(fname, path.join(fname, "premake5.lua"), path.join(fname, "premake4.lua"))
|
||||
local found = os.locate(fname, fname .. ".lua", path.join(fname, "premake5.lua"), path.join(fname, "premake4.lua"))
|
||||
|
||||
-- only include each file once
|
||||
fname = path.getabsolute(found or fname)
|
||||
|
@ -207,6 +207,43 @@
|
||||
|
||||
|
||||
|
||||
---
|
||||
-- Locate a file on one of Premake's search paths: 1) the --script command
|
||||
-- line argument, 2) the PREMAKE_PATH environment variable, 3) relative to
|
||||
-- the Premake executable.
|
||||
--
|
||||
-- @param ...
|
||||
-- A list of file names for which to search. The first one discovered
|
||||
-- is the one that will be returned.
|
||||
-- @return
|
||||
-- The path to file if found, or nil if not.
|
||||
---
|
||||
|
||||
function os.locate(...)
|
||||
local function find(fname)
|
||||
-- is this a direct path to a file?
|
||||
if os.isfile(fname) then
|
||||
return fname
|
||||
end
|
||||
|
||||
-- find it on my paths
|
||||
local dir = os.pathsearch(fname, _OPTIONS["scripts"], os.getenv("PREMAKE_PATH"), path.getdirectory(_PREMAKE_COMMAND))
|
||||
if dir then
|
||||
return path.join(dir, fname)
|
||||
end
|
||||
end
|
||||
|
||||
for i = 1, select("#",...) do
|
||||
local fname = select(i, ...)
|
||||
local result = find(fname)
|
||||
if result then
|
||||
return result
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
---
|
||||
-- Perform a wildcard search for files or directories.
|
||||
--
|
||||
|
Reference in New Issue
Block a user