File src/backend/build.rs changed (mode: 100644) (index 41102be..0181652) |
... |
... |
use std::result::Result; |
4 |
4 |
use std::path::PathBuf; |
use std::path::PathBuf; |
5 |
5 |
|
|
6 |
6 |
pub fn build(dep_name: String) -> Result<String, String> { |
pub fn build(dep_name: String) -> Result<String, String> { |
7 |
|
let dep_path = match super::filesystem::search_current_module_root(dep_name.clone()) { |
|
8 |
|
Ok(path) => path, |
|
9 |
|
Err(e) => return Err(e.to_string()) |
|
10 |
|
}; |
|
11 |
|
|
|
12 |
|
let config_path = match super::dep_config::scan(dep_name) { |
|
|
7 |
|
let config_path = match super::dep_config::scan(dep_name.clone()) { |
13 |
8 |
Ok(path) => path, |
Ok(path) => path, |
14 |
9 |
Err(e) => return Err(e) |
Err(e) => return Err(e) |
15 |
10 |
}; |
}; |
|
... |
... |
pub fn build(dep_name: String) -> Result<String, String> { |
24 |
19 |
Err(e) => return Err(e) |
Err(e) => return Err(e) |
25 |
20 |
} |
} |
26 |
21 |
|
|
27 |
|
match build_module(dep_path, config) { |
|
|
22 |
|
match build_module(dep_name, config) { |
28 |
23 |
Ok(result) => println!("{}", result), |
Ok(result) => println!("{}", result), |
29 |
24 |
Err(e) => return Err(e) |
Err(e) => return Err(e) |
30 |
25 |
} |
} |
|
... |
... |
pub fn build_rec(config_file: PathBuf) -> Result<String, String> { |
61 |
56 |
} |
} |
62 |
57 |
|
|
63 |
58 |
#[cfg(target_os="linux")] |
#[cfg(target_os="linux")] |
64 |
|
fn build_module(config_path: PathBuf, config_value: serde_json::Value) -> Result<String, String> { |
|
|
59 |
|
fn build_module(dep_name: String, config_value: serde_json::Value) -> Result<String, String> { |
65 |
60 |
println!("Building module.."); |
println!("Building module.."); |
66 |
61 |
|
|
67 |
62 |
let build_cmd = &config_value["build"]["linux"]; |
let build_cmd = &config_value["build"]["linux"]; |
|
... |
... |
fn build_module(config_path: PathBuf, config_value: serde_json::Value) -> Result |
70 |
65 |
return Err(String::from("ambassade.json: 'build->linux' should be a string.")); |
return Err(String::from("ambassade.json: 'build->linux' should be a string.")); |
71 |
66 |
} |
} |
72 |
67 |
|
|
73 |
|
super::fetch::build(config_path, String::from(build_cmd.as_str().unwrap())) |
|
|
68 |
|
super::fetch::build(dep_name, String::from(build_cmd.as_str().unwrap())) |
74 |
69 |
} |
} |
75 |
70 |
|
|
76 |
71 |
#[cfg(target_os="macos")] |
#[cfg(target_os="macos")] |
77 |
|
fn build_module(config_path: PathBuf, config_value: serde_json::Value) -> Result<String, String> { |
|
|
72 |
|
fn build_module(dep_name: String, config_value: serde_json::Value) -> Result<String, String> { |
78 |
73 |
println!("Building module.."); |
println!("Building module.."); |
79 |
74 |
|
|
80 |
75 |
let build_cmd = &config_value["build"]["os-x"]; |
let build_cmd = &config_value["build"]["os-x"]; |
|
... |
... |
fn build_module(config_path: PathBuf, config_value: serde_json::Value) -> Result |
83 |
78 |
return Err(String::from("ambassade.json: 'build->os-x' should be a string.")); |
return Err(String::from("ambassade.json: 'build->os-x' should be a string.")); |
84 |
79 |
} |
} |
85 |
80 |
|
|
86 |
|
super::fetch::build(config_path, String::from(build_cmd.as_str().unwrap())) |
|
|
81 |
|
super::fetch::build(dep_name, String::from(build_cmd.as_str().unwrap())) |
87 |
82 |
} |
} |
88 |
83 |
|
|
89 |
84 |
#[cfg(target_os="windows")] |
#[cfg(target_os="windows")] |
90 |
|
fn build_module(config_path: PathBuf, config_value: serde_json::Value) -> Result<String, String> { |
|
|
85 |
|
fn build_module(dep_name: String, config_value: serde_json::Value) -> Result<String, String> { |
91 |
86 |
println!("Building module.."); |
println!("Building module.."); |
92 |
87 |
|
|
93 |
88 |
let build_cmd = &config_value["build"]["windows"]; |
let build_cmd = &config_value["build"]["windows"]; |
|
... |
... |
fn build_module(config_path: PathBuf, config_value: serde_json::Value) -> Result |
96 |
91 |
return Err(String::from("ambassade.json: 'build->windows' should be a string.")); |
return Err(String::from("ambassade.json: 'build->windows' should be a string.")); |
97 |
92 |
} |
} |
98 |
93 |
|
|
99 |
|
super::fetch::build(config_path, String::from(build_cmd.as_str().unwrap())) |
|
|
94 |
|
super::fetch::build(dep_name, String::from(build_cmd.as_str().unwrap())) |
100 |
95 |
} |
} |
File src/backend/dep_config.rs changed (mode: 100644) (index 23b9f70..c8ea53b) |
... |
... |
pub fn scan(dep_name: String) -> Result<PathBuf, String> { |
31 |
31 |
return Ok(config_path); |
return Ok(config_path); |
32 |
32 |
} |
} |
33 |
33 |
|
|
34 |
|
match super::filesystem::get_current_project_root() { |
|
|
34 |
|
let project_path = match super::filesystem::get_current_project_root() { |
35 |
35 |
Some(mut path) => { |
Some(mut path) => { |
36 |
36 |
if String::from(path.file_name().unwrap().to_str().unwrap()) == dep_name { |
if String::from(path.file_name().unwrap().to_str().unwrap()) == dep_name { |
37 |
37 |
println!("Project name equals dep name. Taking project's configfile..."); |
println!("Project name equals dep name. Taking project's configfile..."); |
38 |
38 |
path.push("ambassade.json"); |
path.push("ambassade.json"); |
39 |
39 |
return Ok(path); |
return Ok(path); |
|
40 |
|
} else { |
|
41 |
|
path |
40 |
42 |
} |
} |
41 |
43 |
}, |
}, |
42 |
|
None => println!("Couldn't find current project root. Skipped in scan.") |
|
43 |
|
} |
|
|
44 |
|
None => return Err(String::from("Not in a project (sub)directory.")) |
|
45 |
|
}; |
44 |
46 |
|
|
45 |
47 |
match super::filesystem::get_current_dep_root() { |
match super::filesystem::get_current_dep_root() { |
46 |
48 |
Ok(mut path) => { |
Ok(mut path) => { |
47 |
|
path.push(dep_name); |
|
48 |
|
match super::config::get_json_from_dir(path.clone()) { // Inconventient, should be changed later |
|
|
49 |
|
path.push(dep_name.clone()); |
|
50 |
|
path.push("ambassade.json"); |
|
51 |
|
match super::config::get_json(&path) { // Inconventient, should be changed later |
49 |
52 |
Ok(_) => Ok(path), |
Ok(_) => Ok(path), |
50 |
|
Err(e) => Err(e) |
|
|
53 |
|
_ => { |
|
54 |
|
match super::config::get_json_from_dir(project_path) { |
|
55 |
|
Ok(json) => match super::dep::check(json) { |
|
56 |
|
Ok(result) => { |
|
57 |
|
println!("{}", result); |
|
58 |
|
return scan(dep_name); |
|
59 |
|
}, |
|
60 |
|
Err(e) => return Err(e) |
|
61 |
|
}, |
|
62 |
|
Err(e) => return Err(e) |
|
63 |
|
} |
|
64 |
|
} |
51 |
65 |
} |
} |
52 |
66 |
}, |
}, |
53 |
67 |
Err(e) => Err(e.to_string()) |
Err(e) => Err(e.to_string()) |
File src/backend/fetch.rs changed (mode: 100644) (index eb413a0..fc1b9c6) |
... |
... |
use std::process::{Command, Stdio}; |
5 |
5 |
use std::path::PathBuf; |
use std::path::PathBuf; |
6 |
6 |
use std::result::Result; |
use std::result::Result; |
7 |
7 |
|
|
8 |
|
pub fn build(dep: PathBuf, mut command: String) -> Result<String, String> { |
|
9 |
|
let dep_name = String::from(dep.file_name().unwrap().to_str().unwrap()); |
|
10 |
|
|
|
|
8 |
|
pub fn build_from_path(dep_name: String, mut command: String, path: PathBuf) -> Result<String, String> { |
11 |
9 |
if command == String::new() { |
if command == String::new() { |
12 |
10 |
match set_command(&dep_name, true) { |
match set_command(&dep_name, true) { |
13 |
11 |
Some(cmd) => command = cmd, |
Some(cmd) => command = cmd, |
14 |
12 |
None => return Err(String::from("Fetching failed: no appropriate command set.")) |
None => return Err(String::from("Fetching failed: no appropriate command set.")) |
15 |
13 |
} |
} |
16 |
14 |
} |
} |
17 |
|
fetch(dep_name, dep, command) |
|
|
15 |
|
|
|
16 |
|
fetch(dep_name, path, command) |
|
17 |
|
} |
|
18 |
|
|
|
19 |
|
pub fn build(dep_name: String, command: String) -> Result<String, String> { |
|
20 |
|
match super::filesystem::get_current_project_root() { |
|
21 |
|
Some(dir) => build_from_path(dep_name, command, dir), |
|
22 |
|
None => return Err(String::from("Not in a project (sub)directory.")) |
|
23 |
|
} |
18 |
24 |
} |
} |
19 |
25 |
|
|
20 |
26 |
pub fn run(dep: PathBuf, mut command: String) -> Result<String, String> { |
pub fn run(dep: PathBuf, mut command: String) -> Result<String, String> { |
|
... |
... |
fn fetch(dep_name: String, mut path: PathBuf, command: String) -> Result<String, |
41 |
47 |
} |
} |
42 |
48 |
} |
} |
43 |
49 |
|
|
|
50 |
|
println!("Running from {} ..", path.to_str().unwrap()); |
|
51 |
|
|
44 |
52 |
let out = Command::new(command) |
let out = Command::new(command) |
45 |
53 |
.current_dir(&path) |
.current_dir(&path) |
46 |
54 |
.args(args) |
.args(args) |
File src/backend/filesystem.rs changed (mode: 100644) (index e3e8889..5190c5f) |
1 |
|
use std::{path, env, fs, result}; |
|
|
1 |
|
use std::{path, env, fs}; |
2 |
2 |
use std::io::{Result, Error, ErrorKind}; |
use std::io::{Result, Error, ErrorKind}; |
3 |
3 |
|
|
4 |
4 |
fn get_root(mut path: path::PathBuf) -> Option<path::PathBuf> { |
fn get_root(mut path: path::PathBuf) -> Option<path::PathBuf> { |
|
... |
... |
pub fn get_dep_root(from_dir: path::PathBuf) -> Result<path::PathBuf> { |
67 |
67 |
} |
} |
68 |
68 |
} |
} |
69 |
69 |
|
|
70 |
|
pub fn search_current_module_root(dep_name: String) -> result::Result<path::PathBuf, String> { |
|
71 |
|
search_module_root(dep_name, env::current_dir().unwrap()) |
|
72 |
|
} |
|
73 |
|
|
|
74 |
|
pub fn search_module_root(dep_name: String, from_dir: path::PathBuf) -> result::Result<path::PathBuf, String> { |
|
75 |
|
let project_path = match get_project_root(from_dir.clone()) { |
|
76 |
|
Some(path) => path, |
|
77 |
|
None => return Err(String::from("No project folder found!")) |
|
78 |
|
}; |
|
79 |
|
|
|
80 |
|
if dep_name == String::from(project_path.file_name().unwrap().to_str().unwrap()) { |
|
81 |
|
return Ok(project_path); |
|
82 |
|
} |
|
83 |
|
|
|
84 |
|
match get_dep_root(from_dir) { |
|
85 |
|
Ok(mut dir) => { |
|
86 |
|
dir.push(dep_name); |
|
87 |
|
Ok(dir) |
|
88 |
|
}, |
|
89 |
|
Err(e) => Err(e.to_string()) |
|
90 |
|
} |
|
91 |
|
} |
|
92 |
|
|
|
93 |
70 |
pub fn get_dep_config_root() -> Result<path::PathBuf> { |
pub fn get_dep_config_root() -> Result<path::PathBuf> { |
94 |
71 |
match get_current_project_root() { |
match get_current_project_root() { |
95 |
72 |
Some(mut path) => { |
Some(mut path) => { |