-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
77 lines (72 loc) · 2.61 KB
/
Copy pathbuild.rs
File metadata and controls
77 lines (72 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use std::env;
use std::fs;
use std::io::ErrorKind;
use std::process::exit;
/// sets the configuration directory. Currently set to comply with XDG standards.
/// (will create the directory inside of $HOME/.config if it doesn't exist.)
const CONFIG_DIRECTORY: &str = ".config/shellrandomgreeter";
#[cfg(target_family = "windows")]
fn main() {
let home = match env::home_dir() {
Some(v) => v,
None => {
exit(1);
}
}
.into_os_string()
.into_string()
.expect("Failed to get the canonical path to the user's home directory.");
// mkdir shellrandomgreeter if it doesn't exist.
let windows_conf = CONFIG_DIRECTORY.replace("/", "\\");
let absolute_config_path = format!("{home}\\{windows_conf}");
match fs::create_dir_all(&absolute_config_path) {
Ok(()) => (),
Err(e) => match e.kind() {
ErrorKind::PermissionDenied => {
panic!(
"Lacked permissions to create the directory:\n{}",
absolute_config_path
);
}
ErrorKind::AlreadyExists => {
eprintln!("The following path already exists:\n{absolute_config_path}");
eprintln!("Skipping config directory creation:\n{absolute_config_path}");
}
_ => panic!("No other error should have been encountered:\n{e}"),
},
}
// sets the compiler env.
println!("cargo::rustc-env=CONFIG_DIRECTORY={}", windows_conf);
}
#[cfg(target_family = "unix")]
fn main() {
let home = match env::home_dir() {
Some(v) => v,
None => {
exit(1);
}
}
.into_os_string()
.into_string()
.expect("Failed to get the canonical path to the user's home directory.");
// mkdir shellrandomgreeter if it doesn't exist.
let absolute_config_path = format!("{home}/{CONFIG_DIRECTORY}");
match fs::create_dir_all(&absolute_config_path) {
Ok(()) => (),
Err(e) => match e.kind() {
ErrorKind::PermissionDenied => {
panic!(
"Lacked permissions to create the directory:\n{}",
absolute_config_path
);
}
ErrorKind::AlreadyExists => {
eprintln!("The following path already exists:\n{absolute_config_path}");
eprintln!("Skipping config directory creation:\n{absolute_config_path}");
}
_ => panic!("No other error should have been encountered:\n{e}"),
},
}
// sets the compiler env.
println!("cargo::rustc-env=CONFIG_DIRECTORY={}", CONFIG_DIRECTORY);
}