Skip to content

Commit fe250ef

Browse files
committed
part of the build logic
1 parent fc63290 commit fe250ef

File tree

8 files changed

+289
-100
lines changed

8 files changed

+289
-100
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/target
2+
/test

Cargo.lock

+111-96
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
clippy = "0.0.302"
9+
clap = { version = "4.5.23", features = ["cargo"] }

diplomarbeit/latex_template_htlinn/template/settings-tex.nix

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ submission = if lib.strings.hasInfix "-" config.submissionDate then rec {
77
split = lib.strings.splitString "-" config.submissionDate;
88
year = builtins.elemAt split 0;
99
monthNum = builtins.elemAt split 1;
10-
month = builtins.elemAt monthMap monthNum;
10+
month = builtins.elemAt monthMap (lib.strings.toInt monthNum);
1111
day = builtins.elemAt split 2;
1212
} else rec {
1313
split = lib.strings.splitString "." config.submissionDate;
1414
day = builtins.elemAt split 0;
1515
monthNum = builtins.elemAt split 1;
16-
month = builtins.elemAt monthMap monthNum;
16+
month = builtins.elemAt monthMap (lib.strings.toInt monthNum);
1717
year = builtins.elemAt split 2;
1818
};
1919

src/build.rs

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
use std::process::Command;
2+
use std::path::PathBuf;
3+
4+
use clap::ArgMatches;
5+
6+
7+
pub fn run(sub_matches: &ArgMatches) -> Result<(), String> {
8+
let mut src_path = std::env::current_dir().map_err(|e| format!("{}", e))?;
9+
let build_path = src_path.as_path().join("build");
10+
let htldoc_version = crate::utils::htldoc_version();
11+
12+
// create the build dir
13+
std::fs::create_dir_all(build_path.as_path());
14+
15+
16+
// copy template files to there
17+
let template_path_output = Command::new("nix")
18+
.arg("eval")
19+
.arg(format!("{}#self.outPath", htldoc_version))
20+
.output().expect("failed to get #self.outPath of the htldocVersion in the htldoc.nix")
21+
;
22+
let mut template_path_string = String::from_utf8(template_path_output.stdout).expect("not utf8");
23+
if !template_path_output.status.success() {
24+
println!("{}", String::from_utf8(template_path_output.stderr).unwrap());
25+
return Err("failed to get the template_path_output".to_owned());
26+
}
27+
template_path_string.pop(); // remove \n
28+
template_path_string.pop(); // remove the " at the end
29+
template_path_string.remove(0); // remove the " at the begining
30+
let template_path = PathBuf::from(template_path_string);
31+
println!("src_path: {}", src_path.display());
32+
println!("template_path: {}", template_path.display());
33+
println!("build_path: {}", build_path.display());
34+
35+
36+
// generate settings.tex from config.nix
37+
let settings_tex_output = Command::new("nix")
38+
.arg("eval")
39+
.arg("--impure")
40+
.arg("--expr")
41+
.arg(format!(r#"
42+
let
43+
htldocFlake = builtins.getFlake {htldoc_version};
44+
pkgs = import htldocFlake.inputs.nixpkgs {{}};
45+
lib = pkgs.lib;
46+
defaultConfig = import {}/diplomarbeit/default-config.nix {{ }};
47+
userConfig = import {}/htldoc.nix {{ }};
48+
config = defaultConfig // userConfig;
49+
in import {}/diplomarbeit/latex_template_htlinn/template/settings-tex.nix {{ inherit config lib; }}
50+
"#, template_path.display(), src_path.display(), template_path.display()))
51+
.output().expect("failed to eval the $template/diplomarbeit/latex_template_htlinn/template/settings-tex.nix")
52+
;
53+
if !settings_tex_output.status.success() {
54+
println!("{}", String::from_utf8(settings_tex_output.stderr).unwrap());
55+
return Err("failed to eval the $template/diplomarbeit/latex_template_htlinn/template/settings-tex.nix".to_owned());
56+
}
57+
let settings_tex = String::from_utf8(settings_tex_output.stdout).expect("not utf8");
58+
println!("settings_tex: {}", settings_tex);
59+
println!("template_path: {}", template_path.display());
60+
println!("htldocVersion: {}", htldoc_version);
61+
println!(r#"
62+
let
63+
defaultConfig = import {}/diplomarbeit/default-config.nix {{ }};
64+
userConfig = import {}/htldoc.nix {{ }};
65+
config = defaultConfig // userConfig;
66+
in import {}/diplomarbeit/latex_template_htlinn/template/settings-tex.nix config
67+
"#, template_path.display(), src_path.display(), template_path.display());
68+
std::fs::write(build_path.as_path().join("template").join("settings.tex"), settings_tex).map_err(|e| format!("from IO err: {}", e))?;
69+
70+
71+
// run latex build commands
72+
/*
73+
let settings_tex = Command::new("nix")
74+
.arg("eval")
75+
.arg("--impure")
76+
.arg("--expr")
77+
.arg(format!(r#"
78+
let
79+
defaultConfig = import {template_path}/diplomarbeit/default-config.nix {};
80+
userConfig = import {src_path}/htldoc.nix {};
81+
config = defaultConfig // userConfig;
82+
in import {template_path}/diplomarbeit/latex_template_htlinn/template/settings-tex.nix config
83+
"#,))
84+
.output().expect("failed to eval the $template/diplomarbeit/latex_template_htlinn/template/settings-tex.nix")
85+
*/
86+
87+
88+
89+
Ok(())
90+
}
91+
92+
93+

0 commit comments

Comments
 (0)