Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve y.sh script (to potentially allow dependencies) and improve build_system help message #344

Merged
merged 2 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion build_system/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ mod utils;
macro_rules! arg_error {
($($err:tt)*) => {{
eprintln!($($err)*);
eprintln!();
usage();
std::process::exit(1);
}};
}

fn usage() {
// println!("{}", include_str!("usage.txt"));
println!("\
Available commands for build_system:

prepare : Run prepare command
build : Run build command
--help : Show this message");
}

pub enum Command {
Expand All @@ -31,6 +37,10 @@ fn main() {
let command = match env::args().nth(1).as_deref() {
Some("prepare") => Command::Prepare,
Some("build") => Command::Build,
Some("--help") => {
usage();
process::exit(0);
}
Some(flag) if flag.starts_with('-') => arg_error!("Expected command found flag {}", flag),
Some(command) => arg_error!("Unknown command {}", command),
None => {
Expand Down
7 changes: 4 additions & 3 deletions y.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

set -e
echo "[BUILD] build system" 1>&2
mkdir -p build_system/target
rustc build_system/src/main.rs -o build_system/target/y -Cdebuginfo=1 --edition 2021
exec ./build_system/target/y "$@"
cd build_system
cargo build --release
cd ..
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using pushd and popd would also be an option. Mostly a matter of preference for simple cases like this, but when you have a lot of nested directories or there is a symlink, pushd+popd less error prone.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case I used cd because I didn't want extra things to be displayed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe 2>/dev/null works for that, which makes it less nice than cd .. in this case though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see 2>/dev/null in this script and I don't really want to make the script any more complex than it already is (at a minimum, which is very good as is ^^').

./build_system/target/release/y $@
Loading