<commit_before>--
-- _premake_main.lua
-- Script-side entry point for the main program logic.
-- Copyright (c) 2002-2015 <NAME> and the Premake project
--

	local shorthelp     = "Type 'premake5 --help' for help"
	local versionhelp   = "premake5 (Premake Build Script Generator) %s"


-- Load the collection of core scripts, required for everything else to work

	local manifest = dofile("_manifest.lua")
	for i = 1, #manifest do
		dofile(manifest[i])
	end


-- Create namespaces for myself

	local p = premake
	p.main = {}

	local m = p.main


--
-- Script-side program entry point.
--

	m.elements = function()
		return {
			m.installModuleLoader,
			m.prepareEnvironment,
			m.runSystemScript,
			m.locateUserScript,
			m.prepareAction,
			m.runUserScript,
			m.checkInteractive,
			m.processCommandLine,
			m.preBake,
			m.bake,
			m.postBake,
			m.validate,
			m.preAction,
			m.callAction,
			m.postAction,
		}
	end

	function _premake_main()
		p.callArray(p.main.elements)
		return 0
	end


---
-- Add a new module loader that knows how to use the Premake paths like
-- PREMAKE_PATH and the --scripts option, and follows the module/module.lua
-- naming convention.
---

	function m.installModuleLoader()
		table.insert(package.loaders, 2, m.moduleLoader)

		-- TEMPORARY: I'm working on a different solution for this
		require("xcode")
	end

	function m.moduleLoader(name)
		local dir = path.getdirectory(name)
		local base = path.getname(name)

		if dir ~= "." then
			dir = dir .. "/" .. base
		else
			dir = base
		end

		-- Premake standard is moduleName/moduleName.lua
		local relPath = dir .. "/" .. base .. ".lua"

		local chunk = loadfile("modules/" .. relPath)
		if not chunk then
			chunk = loadfile(relPath)
		end
		if not chunk then
			chunk = loadfile(name .. ".lua")
		end

		if not chunk then
			return "\n\tno file " .. name .. " on module paths"
		end

		return chunk
	end


---
-- Prepare the script environment; anything that should be done
-- before the system script gets a chance to run.
---

	function m.prepareEnvironment()
		math.randomseed(os.time())
		_PREMAKE_DIR = path.getdirectory(_PREMAKE_COMMAND)
		premake.path = premake.path .. ";" .. _PREMAKE_DIR
	end


---
-- Look for and run the system-wide configuration script; make sure any
-- configuration scoping gets cleared before continuing.
---

	function m.runSystemScript()
		dofileopt(_OPTIONS["systemscript"] or { "premake5-system.lua", "premake-system.lua" })
		filter {}<commit_msg>Report script errors from the custom module loader<commit_after>--
-- _premake_main.lua
-- Script-side entry point for the main program logic.
-- Copyright (c) 2002-2015 <NAME> and the Premake project
--

	local shorthelp     = "Type 'premake5 --help' for help"
	local versionhelp   = "premake5 (Premake Build Script Generator) %s"


-- Load the collection of core scripts, required for everything else to work

	local manifest = dofile("_manifest.lua")
	for i = 1, #manifest do
		dofile(manifest[i])
	end


-- Create namespaces for myself

	local p = premake
	p.main = {}

	local m = p.main


--
-- Script-side program entry point.
--

	m.elements = function()
		return {
			m.installModuleLoader,
			m.prepareEnvironment,
			m.runSystemScript,
			m.locateUserScript,
			m.prepareAction,
			m.runUserScript,
			m.checkInteractive,
			m.processCommandLine,
			m.preBake,
			m.bake,
			m.postBake,
			m.validate,
			m.preAction,
			m.callAction,
			m.postAction,
		}
	end

	function _premake_main()
		p.callArray(p.main.elements)
		return 0
	end


---
-- Add a new module loader that knows how to use the Premake paths like
-- PREMAKE_PATH and the --scripts option, and follows the module/module.lua
-- naming convention.
---

	function m.installModuleLoader()
		table.insert(package.loaders, 2, m.moduleLoader)

		-- TEMPORARY: I'm working on a different solution for this
		require("xcode")
	end

	function m.moduleLoader(name)
		local dir = path.getdirectory(name)
		local base = path.getname(name)

		if dir ~= "." then
			dir = dir .. "/" .. base
		else
			dir = base
		end

		local function tryLoad(filename)
			local chunk, err = loadfile(filename)
			if not chunk and not err:startswith("No such file") then
				error(err, 0)
			end
			return chunk
		end

		-- Premake standard is moduleName/moduleName.lua
		local relPath = dir .. "/" .. base .. ".lua"
		local chunk = tryLoad("modules/" .. relPath)
		if not chunk then
			chunk = tryLoad(relPath)
		end
		if not chunk then
			chunk = tryLoad(name .. ".lua")
		end

		if not chunk then
			return "\n\tno file " .. name .. " on module paths"
		end

		return chunk
	end


---
-- Prepare the script environment; anything that should be done
-- before the system script gets a chance to run.
---

	function m.prepareEnvironment()
		math.randomseed(os.time())
		_PREMAKE_DIR = path.getdirectory(_PREMAKE_COMMAND)
		premake.path = premake.path .. ";" .. _PREMAKE_DIR
	end


---
-- Look for and run the system-wide configuration script; make sure any
-- configuration scoping gets cleared before continuing.
---

	function m.runSystemScript()
		dofileopt(_OPTIONS["systemscript"] or { "premake5-system.lua", "premake-system.lua" })
		filter {}
{'fraction_non_alphanumeric': 0.11371108102881454, 'fraction_numerical': 0.005608199574550377, 'mean_word_length': 2.9693016116653874, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2092373', 'n_tokens_mistral': 1907, 'n_tokens_neox': 1656, 'n_words': 525}