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

"external xtasks" pattern; wire up cargo xtask releng #5783

Merged
merged 5 commits into from
May 20, 2024
Merged

Conversation

iliana
Copy link
Contributor

@iliana iliana commented May 16, 2024

I finally found the set of Clap options to do what I wanted!

$ cargo xtask releng --help
    Finished dev [unoptimized + debuginfo] target(s) in 0.58s
     Running `target/debug/xtask releng --help`
    Finished release [optimized] target(s) in 1.02s
     Running `target/release/omicron-releng --help`
Run the Oxide release engineering process and produce a TUF repo that can be used to update a rack.

For more information, see `docs/releng.adoc` in the Omicron repository.

Note that `--host-dataset` and `--recovery-dataset` must be set to different values to build the two OS images in parallel. This is strongly recommended.

Usage: omicron-releng [OPTIONS]

Options:
      --host-dataset <HOST_DATASET>
          ZFS dataset to use for `helios-build` when building the host image

[... and so on]

@iliana iliana requested review from sunshowers and smklein May 16, 2024 04:41
@jclulow
Copy link
Collaborator

jclulow commented May 16, 2024

Note that --host-dataset and --recovery-dataset must be set to different values to build the two OS images in parallel. This is strongly recommended.

Could you just have the tool create child datasets for each of these under a single parent?

@iliana
Copy link
Contributor Author

iliana commented May 16, 2024

I wanted to avoid writing anything in this tool that would pfexec directly. Also the default values for each is rpool/images/$LOGNAME/host and rpool/images/$LOGNAME/recovery respectively, so by default the behavior is as-recommended.

/// Run the Oxide release engineering process and produce a TUF repo that can be
/// used to update a rack.
///
/// For more information, see `docs/releng.adoc` in the Omicron repository.
///
/// Note that `--host-dataset` and `--recovery-dataset` must be set to different
/// values to build the two OS images in parallel. This is strongly recommended.
#[derive(Parser)]
#[command(name = "cargo xtask releng")]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this here to give better error messages when this command is invoked via xtask?

It's possible that the command is still cargo run explicitly, instead of being invoked by xtask, right?

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 thought this adjusted the usage string because this is the same thing that's in xtask, but it actually doesn't -- this appears to just be the name of the tool, which defaults to the crate name. So I'm going to try and find the correct thing and adjust that here and in xtask.

Comment on lines 37 to 38
#[clap(skip)]
command: Option<Command>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

If these args are being skipped, does it make sense to just omit this from the parsed struct?

mut self,
args: impl IntoIterator<Item = impl AsRef<OsStr>>,
) -> External {
self.command.get_or_insert_with(default_command).args(args);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Related to my comment above, this is calling .get_or_insert_with, but it's always using default_command, right?

self.command.get_or_insert_with(default_command).args(args);
self
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Rather than calling cargo_args and exec, we could just call:

pub struct External {
  args: Vec<OsString>,
}

impl External {
  pub fn exec(self, binary: impl AsRef<OsStr>) -> Result<()> {
    default_command()  // I might rename this to "cargo_run_command()"
      .arg("--bin")
      .arg(binary)
      .arg("--")
      .args(self.args)
      .exec();
    ...
  }
}

I think this has the same functionality, but makes it a little clear that the "default" command is not actually modifiable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, this is what I was wondering too -- any particular reason to have command be part of the struct rather than creating it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What this is missing is the ability to add --release to the command, which is particularly useful for the releng tooling. (I don't expect that all external xtasks should be built and run in release mode.)

Copy link
Contributor Author

@iliana iliana May 16, 2024

Choose a reason for hiding this comment

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

Specifically I imagine the usual flow in main.rs would be:

Cmds::Whatever(external) => external.exec("omicron-whatever"),

What the Option<Command>, defualt_command, etc chicanery gets us is the ability to optionally add additional arguments to cargo itself, which we use for Cmds::Releng:

Cmds::Releng(external) => external.cargo_args(["--release"]).exec("omicron-releng"),

self.command.get_or_insert_with(default_command).args(args);
self
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, this is what I was wondering too -- any particular reason to have command be part of the struct rather than creating it here?

@iliana
Copy link
Contributor Author

iliana commented May 16, 2024

I'll add some comments to the cargo_args machinery to make it clearer what's going on.

@iliana iliana merged commit a5213df into main May 20, 2024
18 checks passed
@iliana iliana deleted the iliana/xtask-releng branch May 20, 2024 19:27
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

4 participants