Compare commits

..

No commits in common. "bf87e0c571feac2ab17ec195091ca8e83741e37b" and "9ad9d2140221cc9e81573a261fac45930029d051" have entirely different histories.

4 changed files with 26 additions and 45 deletions

View file

@ -4,7 +4,6 @@ return {
id = "{{ mod.id }}", id = "{{ mod.id }}",
name = "{{ mod.name }}", name = "{{ mod.name }}",
bundled = {{ mod.bundled }}, bundled = {{ mod.bundled }},
version = {{ mod.version }},
packages = { packages = {
{% for pkg in mod.packages %} {% for pkg in mod.packages %}
"{{ pkg }}", "{{ pkg }}",

View file

@ -254,15 +254,8 @@ ModLoader._build_mod_table = function(self)
fassert(table.is_empty(self._mods), "Trying to add mods to non-empty mod table") fassert(table.is_empty(self._mods), "Trying to add mods to non-empty mod table")
for i, mod_data in ipairs(self._mod_data) do for i, mod_data in ipairs(self._mod_data) do
Log.info( Log.info("ModLoader", "mods[%d] = id=%q | name=%q | bundled=%s", i, mod_data.id, mod_data.name,
"ModLoader", tostring(mod_data.bundled))
"mods[%d] = id=%q | name=%q | version=%q | bundled=%s",
i,
mod_data.id,
mod_data.name,
mod_data.version,
tostring(mod_data.bundled)
)
self._mods[i] = { self._mods[i] = {
id = mod_data.id, id = mod_data.id,
@ -296,7 +289,7 @@ ModLoader._load_mod = function(self, index)
mod.state = "loading" mod.state = "loading"
Crashify.print_property(string.format("Mod:%s", mod.name), true) Crashify.print_property(string.format("Mod:%s:%s", mod.id, mod.name), true)
self._mod_load_index = index self._mod_load_index = index

View file

@ -12,7 +12,6 @@ local log = function(category, format, ...)
end end
log("mod_main", "Initializing mods...") log("mod_main", "Initializing mods...")
log("mod_main", "[DTMM] Deployment data:\n{{ deployment_info }}")
local require_store = {} local require_store = {}

View file

@ -261,7 +261,6 @@ fn build_mod_data_lua(state: Arc<ActionState>) -> Result<String> {
id: String, id: String,
name: String, name: String,
bundled: bool, bundled: bool,
version: String,
init: String, init: String,
data: Option<String>, data: Option<String>,
localization: Option<String>, localization: Option<String>,
@ -269,8 +268,6 @@ fn build_mod_data_lua(state: Arc<ActionState>) -> Result<String> {
} }
let mut env = Environment::new(); let mut env = Environment::new();
env.set_trim_blocks(true);
env.set_lstrip_blocks(true);
env.add_template("mod_data.lua", include_str!("../../assets/mod_data.lua.j2")) env.add_template("mod_data.lua", include_str!("../../assets/mod_data.lua.j2"))
.wrap_err("Failed to compile template for `mod_data.lua`")?; .wrap_err("Failed to compile template for `mod_data.lua`")?;
let tmpl = env let tmpl = env
@ -289,7 +286,6 @@ fn build_mod_data_lua(state: Arc<ActionState>) -> Result<String> {
id: m.id.clone(), id: m.id.clone(),
name: m.name.clone(), name: m.name.clone(),
bundled: m.bundled, bundled: m.bundled,
version: m.version.clone(),
init: m.resources.init.to_string_lossy().to_string(), init: m.resources.init.to_string_lossy().to_string(),
data: m data: m
.resources .resources
@ -453,10 +449,7 @@ async fn build_bundles(state: Arc<ActionState>) -> Result<Vec<Bundle>> {
} }
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
async fn patch_boot_bundle( async fn patch_boot_bundle(state: Arc<ActionState>) -> Result<Vec<Bundle>> {
state: Arc<ActionState>,
deployment_info: &String,
) -> Result<Vec<Bundle>> {
let bundle_dir = Arc::new(state.game_dir.join("bundle")); let bundle_dir = Arc::new(state.game_dir.join("bundle"));
let bundle_path = bundle_dir.join(format!("{:x}", Murmur64::hash(BOOT_BUNDLE_NAME.as_bytes()))); let bundle_path = bundle_dir.join(format!("{:x}", Murmur64::hash(BOOT_BUNDLE_NAME.as_bytes())));
@ -502,18 +495,14 @@ async fn patch_boot_bundle(
let _enter = span.enter(); let _enter = span.enter();
let mut env = Environment::new(); let mut env = Environment::new();
env.set_trim_blocks(true);
env.set_lstrip_blocks(true);
env.add_template("mod_main.lua", include_str!("../../assets/mod_main.lua.j2")) env.add_template("mod_main.lua", include_str!("../../assets/mod_main.lua.j2"))
.wrap_err("Failed to compile template for `mod_main.lua`")?; .wrap_err("Failed to compile template for `mod_main.lua`")?;
let tmpl = env let tmpl = env
.get_template("mod_main.lua") .get_template("mod_main.lua")
.wrap_err("Failed to get template `mod_main.lua`")?; .wrap_err("Failed to get template `mod_main.lua`")?;
let is_io_enabled = if state.is_io_enabled { "true" } else { "false" };
let deployment_info = deployment_info.replace("\"", "\\\"").replace("\n", "\\n");
let lua = tmpl let lua = tmpl
.render(minijinja::context!(is_io_enabled => is_io_enabled, deployment_info => deployment_info)) .render(minijinja::context!(is_io_enabled => if state.is_io_enabled { "true" } else {"false"}))
.wrap_err("Failed to render template `mod_main.lua`")?; .wrap_err("Failed to render template `mod_main.lua`")?;
tracing::trace!("Main script rendered:\n===========\n{}\n=============", lua); tracing::trace!("Main script rendered:\n===========\n{}\n=============", lua);
@ -578,10 +567,14 @@ where
} }
#[tracing::instrument(skip_all, fields(bundles = bundles.as_ref().len()))] #[tracing::instrument(skip_all, fields(bundles = bundles.as_ref().len()))]
fn build_deployment_data( async fn write_deployment_data<B>(
bundles: impl AsRef<[Bundle]>, state: Arc<ActionState>,
mod_folders: impl AsRef<[String]>, bundles: B,
) -> Result<String> { mod_folders: Vec<String>,
) -> Result<()>
where
B: AsRef<[Bundle]>,
{
let info = DeploymentData { let info = DeploymentData {
timestamp: OffsetDateTime::now_utc(), timestamp: OffsetDateTime::now_utc(),
bundles: bundles bundles: bundles
@ -590,13 +583,16 @@ fn build_deployment_data(
.map(|bundle| format!("{:x}", bundle.name().to_murmur64())) .map(|bundle| format!("{:x}", bundle.name().to_murmur64()))
.collect(), .collect(),
// TODO: // TODO:
mod_folders: mod_folders mod_folders,
.as_ref()
.iter()
.map(|folder| folder.clone())
.collect(),
}; };
serde_sjson::to_string(&info).wrap_err("Failed to serizalize deployment data") let path = state.game_dir.join(DEPLOYMENT_DATA_PATH);
let data = serde_sjson::to_string(&info).wrap_err("Failed to serizalie deployment data")?;
fs::write(&path, &data)
.await
.wrap_err_with(|| format!("Failed to write deployment data to '{}'", path.display()))?;
Ok(())
} }
#[tracing::instrument(skip_all, fields( #[tracing::instrument(skip_all, fields(
@ -725,11 +721,8 @@ pub(crate) async fn deploy_mods(state: ActionState) -> Result<()> {
.await .await
.wrap_err("Failed to build mod bundles")?; .wrap_err("Failed to build mod bundles")?;
let new_deployment_info = build_deployment_data(&bundles, &mod_folders)
.wrap_err("Failed to build new deployment data")?;
tracing::info!("Patch boot bundle"); tracing::info!("Patch boot bundle");
let mut boot_bundles = patch_boot_bundle(state.clone(), &new_deployment_info) let mut boot_bundles = patch_boot_bundle(state.clone())
.await .await
.wrap_err("Failed to patch boot bundle")?; .wrap_err("Failed to patch boot bundle")?;
bundles.append(&mut boot_bundles); bundles.append(&mut boot_bundles);
@ -804,12 +797,9 @@ pub(crate) async fn deploy_mods(state: ActionState) -> Result<()> {
.wrap_err("Failed to patch bundle database")?; .wrap_err("Failed to patch bundle database")?;
tracing::info!("Writing deployment data"); tracing::info!("Writing deployment data");
{ write_deployment_data(state.clone(), &bundles, mod_folders)
let path = state.game_dir.join(DEPLOYMENT_DATA_PATH);
fs::write(&path, &new_deployment_info)
.await .await
.wrap_err_with(|| format!("Failed to write deployment data to '{}'", path.display()))?; .wrap_err("Failed to write deployment data")?;
}
tracing::info!("Finished deploying mods"); tracing::info!("Finished deploying mods");
Ok(()) Ok(())