|
1 | 1 | const VERBOSE: bool = false;
|
| 2 | +use enable_ansi_support::enable_ansi_support; |
| 3 | +use std::fs; |
2 | 4 | use rand::random;
|
3 | 5 | use std::{
|
4 | 6 | env::args,
|
@@ -76,16 +78,8 @@ fn preprocess(file: &str, out: &str) {
|
76 | 78 | write("build_artifacts/final", last_step).unwrap();
|
77 | 79 | }
|
78 | 80 | }
|
79 |
| -fn main() { |
80 |
| - if args().len() != 3 { |
81 |
| - err(format!("Usage: {} <run/deploy> <file>", args().nth(0).unwrap()).as_str()) |
82 |
| - } else if args().nth(1).unwrap() != "run" && args().nth(1).unwrap() != "deploy" { |
83 |
| - err(format!("Usage: {} <run/deploy> <file>", args().nth(0).unwrap()).as_str()) |
84 |
| - } else if !std::path::Path::new(&args().nth(2).unwrap()).exists() { |
85 |
| - err(format!("File {} does not exist.", args().nth(2).unwrap()).as_str()) |
86 |
| - } else if std::path::Path::new(&args().nth(2).unwrap()).is_dir() { |
87 |
| - err(format!("{} is a directory.", args().nth(2).unwrap()).as_str()) |
88 |
| - } |
| 81 | +#[cfg(not(windows))] |
| 82 | +fn build(){ |
89 | 83 | match Command::new("rm")
|
90 | 84 | .args(["-rf", "build_artifacts"])
|
91 | 85 | .spawn()
|
@@ -126,3 +120,51 @@ fn main() {
|
126 | 120 | ok("Deployed");
|
127 | 121 | }
|
128 | 122 | }
|
| 123 | +#[cfg(windows)] |
| 124 | +fn build(){ |
| 125 | + if let Ok(_) = fs::remove_dir_all("build_artifacts") { |
| 126 | + } else {}; |
| 127 | + create_dir("build_artifacts").unwrap(); |
| 128 | + if args().nth(1).unwrap() == "run" { |
| 129 | + info("Preprocessing."); |
| 130 | + preprocess(args().nth(2).unwrap().as_str(), "main"); |
| 131 | + info("Running"); |
| 132 | + Command::new("pdn_exec") |
| 133 | + .args(["build_artifacts/final"]) |
| 134 | + .spawn() |
| 135 | + .unwrap() |
| 136 | + .wait() |
| 137 | + .unwrap(); |
| 138 | + } else if args().nth(1).unwrap() == "deploy" { |
| 139 | + info("Preprocessing."); |
| 140 | + preprocess(args().nth(2).unwrap().as_str(), "main"); |
| 141 | + ok("Preprocessed"); |
| 142 | + info("Deploying"); |
| 143 | + Command::new("pdn_deploy") |
| 144 | + .args([ |
| 145 | + "build_artifacts/final", |
| 146 | + args() |
| 147 | + .nth(2) |
| 148 | + .unwrap() |
| 149 | + .as_str() |
| 150 | + .replace(".pnet", ".out") |
| 151 | + .as_str(), |
| 152 | + ]) |
| 153 | + .output() |
| 154 | + .unwrap(); |
| 155 | + ok("Deployed"); |
| 156 | + } |
| 157 | +} |
| 158 | +fn main() { |
| 159 | + enable_ansi_support().unwrap(); |
| 160 | + if args().len() != 3 { |
| 161 | + err(format!("Usage: {} <run/deploy> <file>", args().nth(0).unwrap()).as_str()) |
| 162 | + } else if args().nth(1).unwrap() != "run" && args().nth(1).unwrap() != "deploy" { |
| 163 | + err(format!("Usage: {} <run/deploy> <file>", args().nth(0).unwrap()).as_str()) |
| 164 | + } else if !std::path::Path::new(&args().nth(2).unwrap()).exists() { |
| 165 | + err(format!("File {} does not exist.", args().nth(2).unwrap()).as_str()) |
| 166 | + } else if std::path::Path::new(&args().nth(2).unwrap()).is_dir() { |
| 167 | + err(format!("{} is a directory.", args().nth(2).unwrap()).as_str()) |
| 168 | + } |
| 169 | + build(); |
| 170 | +} |
0 commit comments