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

Introduce new command, xtask print #905

Merged
merged 2 commits into from Nov 21, 2022
Merged

Introduce new command, xtask print #905

merged 2 commits into from Nov 21, 2022

Conversation

steveklabnik
Copy link
Contributor

This command can print out information about the build. Currently, it only supports one option, --archive, which prints out the final build archive. This is useful in scripting.

Example:

〉cargo xtask print .\app\demo-stm32f4-discovery\app.toml --archive
    Finished dev [optimized + debuginfo] target(s) in 1.68s
     Running `target\debug\xtask.exe print .\app\demo-stm32f4-discovery\app.toml --archive`
target\demo-stm32f4-discovery\dist\default\build-demo-stm32f4-discovery.zip

Additonally, I wanted to make the errors nice for this, and so I ended up adding some contexts inside of the other commands, which will also make them slightly better. Example:

〉cargo xtask print .\app\demo-stm32f4-discovery\app.tom --archive
    Finished dev [optimized + debuginfo] target(s) in 1.52s
     Running `target\debug\xtask.exe print .\app\demo-stm32f4-discovery\app.tom --archive`
Error: could not print information about the build

Caused by:
    0: could not create build configuration
    1: could not read .\app\demo-stm32f4-discovery\app.tom
    2: The system cannot find the file specified. (os error 2)

This feature was requested by @rmustacc and @jclulow , so I'd love to make sure that this satisfies their needs.

I could make the command just print-archive (suggested by @mkeeter) and remove some of the machinery here, but I feel like we've wanted to print other stuff in the past? IIRC @cbiffle was talking about something with environment variables? maybe that was just setting them, not examining them.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

license-eye has totally checked 391 files.

Valid Invalid Ignored Fixed
390 1 0 0
Click to see the invalid file list
  • build/xtask/src/print.rs

build/xtask/src/print.rs Show resolved Hide resolved

println!("{}", final_path.display());
} else {
bail!("I'm not sure what to print. Currently supported: --archive");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd prefer to use an ArgGroup here, but it seems like it's not fully baked in the derive API yet clap-rs/clap#2621

No big deal.

.ok_or(Error::msg(format!("cannot find image {}", image_name)))?;

let final_path = config
.img_file(format!("build-{}.zip", config.toml.name), image_name);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am a little not happy about this one, as it's duplicating the logic that's already been duplicated twice:

Not 100% sure what the best way to solve this would be, though...

steveklabnik and others added 2 commits November 21, 2022 16:28
This command can print out information about the build. Currently, it
only supports one option, --archive, which prints out the final build
archive. This is useful in scripting.

Example:

```
〉cargo xtask print .\app\demo-stm32f4-discovery\app.toml --archive
    Finished dev [optimized + debuginfo] target(s) in 1.68s
     Running `target\debug\xtask.exe print .\app\demo-stm32f4-discovery\app.toml --archive`
target\demo-stm32f4-discovery\dist\default\build-demo-stm32f4-discovery.zip
```

Additonally, I wanted to make the errors nice for this, and so I ended
up adding some contexts inside of the other commands, which will also
make them slightly better. Example:

```
〉cargo xtask print .\app\demo-stm32f4-discovery\app.tom --archive
    Finished dev [optimized + debuginfo] target(s) in 1.52s
     Running `target\debug\xtask.exe print .\app\demo-stm32f4-discovery\app.tom --archive`
Error: could not print information about the build

Caused by:
    0: could not create build configuration
    1: could not read .\app\demo-stm32f4-discovery\app.tom
    2: The system cannot find the file specified. (os error 2)
```
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@steveklabnik steveklabnik merged commit 367c14e into master Nov 21, 2022
@steveklabnik steveklabnik deleted the print-archive-path branch November 21, 2022 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants