Skip to content

Commit

Permalink
gng-build-agent: Move startup code into lua module "startup"
Browse files Browse the repository at this point in the history
  • Loading branch information
hunger committed Feb 24, 2021
1 parent 8b04f39 commit f3a89ef
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 29 deletions.
33 changes: 33 additions & 0 deletions gng-build-agent/lua/startup.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
local startup = {}

function startup.init(pkg_definition)
print("Init called with \"" .. pkg_definition .. "\"...")
pkg_defaults = {
bootstrap = false,

build_dependencies = {},
check_dependencies = {},

prepare = function() end,
build = function() end,
check = function() end,
install = function() end,
polish = function() end,
}

PKG_func, err = loadfile(pkg_definition)

if PKG_func == nil then
error("Failed to load \"" .. pkg_definition .. "\" in gng-build-agent: "..err)
end

_G.PKG = PKG_func()

for k, v in pairs(pkg_defaults) do
if PKG[k] == nil then
PKG[k] = v
end
end
end

return startup
30 changes: 1 addition & 29 deletions gng-build-agent/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,35 +168,7 @@ impl EngineBuilder {
engine.load_functions()?;

let script = format!(
r#"
package.path = "/gng/lua/?.lua"
pkg_defaults = {{
bootstrap = false,
build_dependencies = {{}},
check_dependencies = {{}},
prepare = function() end,
build = function() end,
check = function() end,
install = function() end,
polish = function() end,
}}
PKG_func, err = loadfile("{}")
if PKG_func == nil then
error("Failed to load /gng/build.lua in gng-build-agent: "..err)
end
PKG = PKG_func()
for k, v in pairs(pkg_defaults) do
if PKG[k] == nil then
PKG[k] = v
end
end"#,
"package.path = \"/gng/lua/?.lua\"\nrequire(\"startup\").init(\"{}\")",
build_file.to_string_lossy().as_ref()
);

Expand Down

0 comments on commit f3a89ef

Please sign in to comment.