Skip to content

Commit b160f91

Browse files
committed
refactor: re-org build_application
1 parent 6bac7e5 commit b160f91

File tree

2 files changed

+108
-114
lines changed

2 files changed

+108
-114
lines changed

src/lib.rs

Lines changed: 107 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -127,120 +127,14 @@ impl<'a> FlatpakManager<'a> {
127127
config_opts,
128128
build_commands,
129129
..
130-
} => {
131-
let buildsystem = buildsystem.as_deref();
132-
match buildsystem {
133-
Some("meson") => {
134-
let build_dir = self.build_dir().join("_build");
135-
let build_dir_str = build_dir.to_str().unwrap();
136-
let mut meson_args = vec!["build", repo_dir_str, "meson", "setup"];
137-
if let Some(config_opts) = config_opts {
138-
meson_args.extend(config_opts.iter().map(|s| s.as_str()));
139-
}
140-
meson_args.extend(&["--prefix=/app", build_dir_str]);
141-
run_command(
142-
"flatpak",
143-
&meson_args,
144-
Some(self.state.base_dir.as_path()),
145-
)?;
146-
run_command(
147-
"flatpak",
148-
&["build", repo_dir_str, "ninja", "-C", build_dir_str],
149-
Some(self.state.base_dir.as_path()),
150-
)?;
151-
run_command(
152-
"flatpak",
153-
&[
154-
"build",
155-
repo_dir_str,
156-
"meson",
157-
"install",
158-
"-C",
159-
build_dir_str,
160-
],
161-
Some(self.state.base_dir.as_path()),
162-
)?;
163-
}
164-
Some("cmake") | Some("cmake-ninja") => {
165-
let build_dir = self.build_dir().join("_build");
166-
let build_dir_str = build_dir.to_str().unwrap();
167-
let b_flag = format!("-B{build_dir_str}");
168-
let mut cmake_args = vec![
169-
"build",
170-
repo_dir_str,
171-
"cmake",
172-
"-G",
173-
"Ninja",
174-
&b_flag,
175-
"-DCMAKE_EXPORT_COMPILE_COMMANDS=1",
176-
"-DCMAKE_BUILD_TYPE=RelWithDebInfo",
177-
"-DCMAKE_INSTALL_PREFIX=/app",
178-
];
179-
if let Some(config_opts) = config_opts {
180-
cmake_args.extend(config_opts.iter().map(|s| s.as_str()));
181-
}
182-
cmake_args.push(".");
183-
run_command(
184-
"flatpak",
185-
&cmake_args,
186-
Some(self.state.base_dir.as_path()),
187-
)?;
188-
run_command(
189-
"flatpak",
190-
&["build", repo_dir_str, "ninja", "-C", build_dir_str],
191-
Some(self.state.base_dir.as_path()),
192-
)?;
193-
run_command(
194-
"flatpak",
195-
&[
196-
"build",
197-
repo_dir_str,
198-
"ninja",
199-
"-C",
200-
build_dir_str,
201-
"install",
202-
],
203-
Some(self.state.base_dir.as_path()),
204-
)?;
205-
}
206-
Some("simple") => {
207-
if let Some(build_commands) = build_commands {
208-
for command in build_commands {
209-
let mut args = vec!["build", repo_dir_str];
210-
args.extend(command.split_whitespace());
211-
run_command(
212-
"flatpak",
213-
&args,
214-
Some(self.state.base_dir.as_path()),
215-
)?;
216-
}
217-
}
218-
}
219-
_ => {
220-
// Default to autotools
221-
let mut autotools_args =
222-
vec!["build", repo_dir_str, "./configure", "--prefix=/app"];
223-
if let Some(config_opts) = config_opts {
224-
autotools_args.extend(config_opts.iter().map(|s| s.as_str()));
225-
}
226-
run_command(
227-
"flatpak",
228-
&autotools_args,
229-
Some(self.state.base_dir.as_path()),
230-
)?;
231-
run_command(
232-
"flatpak",
233-
&["build", repo_dir_str, "make"],
234-
Some(self.state.base_dir.as_path()),
235-
)?;
236-
run_command(
237-
"flatpak",
238-
&["build", repo_dir_str, "make", "install"],
239-
Some(self.state.base_dir.as_path()),
240-
)?;
241-
}
130+
} => match buildsystem.as_deref() {
131+
Some("meson") => self.run_meson(repo_dir_str, config_opts.as_ref())?,
132+
Some("cmake") | Some("cmake-ninja") => {
133+
self.run_cmake(repo_dir_str, config_opts.as_ref())?
242134
}
243-
}
135+
Some("simple") => self.run_simple(repo_dir_str, build_commands.as_ref())?,
136+
_ => self.run_autotools(repo_dir_str, config_opts.as_ref())?,
137+
},
244138
Module::Reference(_) => {
245139
// Skip string references for build_application
246140
}
@@ -261,6 +155,106 @@ impl<'a> FlatpakManager<'a> {
261155
Ok(())
262156
}
263157

158+
fn run_meson(&self, repo_dir_str: &str, config_opts: Option<&Vec<String>>) -> Result<()> {
159+
let build_dir = self.build_dir().join("_build");
160+
let build_dir_str = build_dir.to_str().unwrap();
161+
let mut meson_args = vec!["build", repo_dir_str, "meson", "setup"];
162+
if let Some(opts) = config_opts {
163+
meson_args.extend(opts.iter().map(|s| s.as_str()));
164+
}
165+
meson_args.extend(&["--prefix=/app", build_dir_str]);
166+
run_command("flatpak", &meson_args, Some(self.state.base_dir.as_path()))?;
167+
run_command(
168+
"flatpak",
169+
&["build", repo_dir_str, "ninja", "-C", build_dir_str],
170+
Some(self.state.base_dir.as_path()),
171+
)?;
172+
run_command(
173+
"flatpak",
174+
&[
175+
"build",
176+
repo_dir_str,
177+
"meson",
178+
"install",
179+
"-C",
180+
build_dir_str,
181+
],
182+
Some(self.state.base_dir.as_path()),
183+
)
184+
}
185+
186+
fn run_cmake(&self, repo_dir_str: &str, config_opts: Option<&Vec<String>>) -> Result<()> {
187+
let build_dir = self.build_dir().join("_build");
188+
let build_dir_str = build_dir.to_str().unwrap();
189+
let b_flag = format!("-B{build_dir_str}");
190+
let mut cmake_args = vec![
191+
"build",
192+
repo_dir_str,
193+
"cmake",
194+
"-G",
195+
"Ninja",
196+
&b_flag,
197+
"-DCMAKE_EXPORT_COMPILE_COMMANDS=1",
198+
"-DCMAKE_BUILD_TYPE=RelWithDebInfo",
199+
"-DCMAKE_INSTALL_PREFIX=/app",
200+
];
201+
if let Some(opts) = config_opts {
202+
cmake_args.extend(opts.iter().map(|s| s.as_str()));
203+
}
204+
cmake_args.push(".");
205+
run_command("flatpak", &cmake_args, Some(self.state.base_dir.as_path()))?;
206+
run_command(
207+
"flatpak",
208+
&["build", repo_dir_str, "ninja", "-C", build_dir_str],
209+
Some(self.state.base_dir.as_path()),
210+
)?;
211+
run_command(
212+
"flatpak",
213+
&[
214+
"build",
215+
repo_dir_str,
216+
"ninja",
217+
"-C",
218+
build_dir_str,
219+
"install",
220+
],
221+
Some(self.state.base_dir.as_path()),
222+
)
223+
}
224+
225+
fn run_simple(&self, repo_dir_str: &str, build_commands: Option<&Vec<String>>) -> Result<()> {
226+
if let Some(commands) = build_commands {
227+
for command in commands {
228+
let mut args = vec!["build", repo_dir_str];
229+
args.extend(command.split_whitespace());
230+
run_command("flatpak", &args, Some(self.state.base_dir.as_path()))?;
231+
}
232+
}
233+
Ok(())
234+
}
235+
236+
fn run_autotools(&self, repo_dir_str: &str, config_opts: Option<&Vec<String>>) -> Result<()> {
237+
let mut autotools_args = vec!["build", repo_dir_str, "./configure", "--prefix=/app"];
238+
if let Some(opts) = config_opts {
239+
autotools_args.extend(opts.iter().map(|s| s.as_str()));
240+
}
241+
run_command(
242+
"flatpak",
243+
&autotools_args,
244+
Some(self.state.base_dir.as_path()),
245+
)?;
246+
run_command(
247+
"flatpak",
248+
&["build", repo_dir_str, "make"],
249+
Some(self.state.base_dir.as_path()),
250+
)?;
251+
run_command(
252+
"flatpak",
253+
&["build", repo_dir_str, "make", "install"],
254+
Some(self.state.base_dir.as_path()),
255+
)
256+
}
257+
264258
fn build_dependencies(&mut self) -> Result<()> {
265259
println!("{}", "Building dependencies...".bold());
266260
let manifest = self.manifest.as_ref().unwrap();

src/process.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::Result;
22
use colored::*;
33
use nix::errno::Errno;
4-
use nix::sys::signal::{kill, Signal};
4+
use nix::sys::signal::{Signal, kill};
55
use nix::unistd::Pid;
66

77
use crate::state::State;

0 commit comments

Comments
 (0)