Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions scripts/chwd
Original file line number Diff line number Diff line change
Expand Up @@ -232,25 +232,25 @@ local function parse_profiles(path)
}
else
if profile then
if not profiles[profile].packages then
profiles[profile].packages = line:match(packages_pattern)
else
local hooks = profiles[profile]["hooks"]
if captured_hook == nil then
for hook in pairs(hooks) do
local hook_pattern = '^' .. escape_pattern(hook) .. '%s*=%s*"""'
if line:match(hook_pattern) then
captured_hook = hook
end
local hooks = profiles[profile]["hooks"]
if captured_hook == nil then
if not profiles[profile].packages then
profiles[profile].packages = line:match(packages_pattern)
end
for hook in pairs(hooks) do
local hook_pattern = '^' .. escape_pattern(hook) .. '%s*=%s*"""'
if line:match(hook_pattern) then
captured_hook = hook
break
end
end
else
local hook_end = line:match('(.*)"""')
if hook_end then
hooks[captured_hook] = hooks[captured_hook] .. hook_end
captured_hook = nil
else
local hook_end = line:match('(.*)"""')
if hook_end then
hooks[captured_hook] = hooks[captured_hook] .. hook_end
captured_hook = nil
else
hooks[captured_hook] = hooks[captured_hook] .. line .. "\n"
end
hooks[captured_hook] = hooks[captured_hook] .. line .. "\n"
end
end
end
Expand Down
14 changes: 14 additions & 0 deletions src/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,4 +796,18 @@ mod tests {
// Should fail because cpu_models is set without cpu_family
assert!(parsed_profiles.is_err() || parsed_profiles.unwrap().is_empty());
}

#[test]
fn handheld_profile_parse_test() {
let prof_path = "profiles/pci/handhelds/profiles.toml";
let parsed_profiles = parse_profiles(prof_path).expect("failed to parse handheld profiles");
let rog_ally = parsed_profiles
.iter()
.find(|p| p.name == "handheld.rog-ally")
.expect("handheld.rog-ally profile not found");
assert_eq!(rog_ally.packages, "steamos-manager inputplumber steamos-powerbuttond");
assert!(rog_ally.post_install.contains("Ally chwd installing..."));
assert!(rog_ally.post_install.contains("/etc/wireplumber/wireplumber.conf.d"));
assert!(rog_ally.post_remove.contains("Ally chwd removing..."));
}
}
42 changes: 42 additions & 0 deletions tests/chwd_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,48 @@ EOF
mkinitcpio -P
]])
end)
it("Child post install hook", function()
assert.are.equals(hooks['post_install'], [[
cat <<EOF >/etc/mkinitcpio.conf.d/10-chwd.conf
# This file is automatically generated by chwd. PLEASE DO NOT EDIT IT.
MODULES+=(nvidia nvidia_modeset nvidia_uvm nvidia_drm)
EOF
mkinitcpio -P
]])
end)
end)

describe("Handheld profiles without explicit packages", function()
local handheld_profiles = chwd.parse_profiles("profiles/pci/handhelds/profiles.toml")

it("Parent handheld profile parsed", function()
assert.truthy(handheld_profiles["handheld"])
assert.are.equals(handheld_profiles["handheld"].packages, "steamos-manager inputplumber steamos-powerbuttond")
end)

it("ROG Ally profile inherits packages and parses its own hooks", function()
assert.truthy(handheld_profiles["handheld.rog-ally"])
local packages, hooks = chwd.get_profile(handheld_profiles, "handheld.rog-ally")
assert.are.equals(packages, "steamos-manager inputplumber steamos-powerbuttond")
assert.truthy(hooks["post_install"])
assert.truthy(hooks["post_install"]:find("Ally chwd installing%.%.%."))
assert.truthy(hooks["post_install"]:find("/etc/wireplumber/wireplumber%.conf%.d"))
assert.truthy(hooks["post_remove"])
assert.truthy(hooks["post_remove"]:find("Ally chwd removing%.%.%."))
assert.truthy(hooks["conditional_packages"])
assert.truthy(hooks["conditional_packages"]:find("LENOVO"))
end)

it("MSI Claw profile inherits packages and parses its own hooks", function()
assert.truthy(handheld_profiles["handheld.msi-claw"])
local packages, hooks = chwd.get_profile(handheld_profiles, "handheld.msi-claw")
assert.are.equals(packages, "steamos-manager inputplumber steamos-powerbuttond")
assert.truthy(hooks["post_install"])
assert.truthy(hooks["post_install"]:find("Claw chwd installing%.%.%."))
assert.truthy(hooks["post_install"]:find("chwd%-msi%-claw%.conf"))
assert.truthy(hooks["post_remove"])
assert.truthy(hooks["post_remove"]:find("Claw chwd removing%.%.%."))
end)
end)

describe("Packages inspection", function()
Expand Down