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

Lazily load the default workspace as needed #1188

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
43 changes: 35 additions & 8 deletions crates/spk-cli/common/src/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,18 @@ impl Requests {
repos: &[Arc<storage::RepositoryHandle>],
) -> Result<Vec<AnyIdent>> {
let mut idents = Vec::new();
let mut workspace = self.workspace.load_or_default()?;
let mut workspace = None;
for package in packages {
if package.contains('@') {
if workspace.is_none() {
workspace = Some(self.workspace.load_or_default()?);
}
let Some(ws) = workspace.as_mut() else {
unreachable!();
};

let (recipe, _, stage, _) =
parse_stage_specifier(package, options, &mut workspace, repos).await?;
parse_stage_specifier(package, options, ws, repos).await?;

match stage {
TestStage::Sources => {
Expand All @@ -394,8 +401,14 @@ impl Requests {

let path = std::path::Path::new(package);
if path.is_file() {
let mut workspace = self.workspace.load_or_default()?;
let configured = workspace
if workspace.is_none() {
workspace = Some(self.workspace.load_or_default()?);
}
let Some(ws) = workspace.as_mut() else {
unreachable!();
};

let configured = ws
.find_or_load_package_template(package)
.wrap_err("did not find recipe template")?;
let rendered_data = configured.template.render(options)?;
Expand Down Expand Up @@ -450,18 +463,25 @@ impl Requests {
let override_options = options.get_options()?;
let mut templating_options = override_options.clone();
let mut extra_options = OptionMap::default();
let mut workspace = self.workspace.load_or_default()?;
let mut workspace = None;

// From the positional REQUESTS arg
for r in requests.into_iter() {
let r: &str = r.as_ref();

// Is it a filepath to a package requests yaml file?
if r.ends_with(".spk.yaml") {
if workspace.is_none() {
workspace = Some(self.workspace.load_or_default()?);
}
let Some(ws) = workspace.as_mut() else {
unreachable!();
};

let (spec, filename) = find_package_recipe_from_workspace_or_repo(
Some(&r),
&templating_options,
&mut workspace,
ws,
repos,
)
.await
Expand Down Expand Up @@ -510,16 +530,23 @@ impl Requests {
&self,
request: &str,
options: &OptionMap,
workspace: &mut spk_workspace::Workspace,
workspace: &mut Option<spk_workspace::Workspace>,
repos: &[Arc<storage::RepositoryHandle>],
) -> Result<Vec<Request>> {
// Parses a command line request into one or more requests.
// 'file@stage' strings can expand into more than one request.
let mut out = Vec::<Request>::new();

if request.contains('@') {
if workspace.is_none() {
*workspace = Some(self.workspace.load_or_default()?);
}
let Some(ws) = workspace.as_mut() else {
unreachable!();
};

let (recipe, _, stage, build_variant) =
parse_stage_specifier(request, options, workspace, repos)
parse_stage_specifier(request, options, ws, repos)
.await
.wrap_err_with(|| {
format!("parsing {request} as a filename with stage specifier")
Expand Down
1 change: 1 addition & 0 deletions crates/spk-schema/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ impl TemplateExt for SpecTemplate {

if api.is_none() {
tracing::warn!(
spec_file = %file_path.to_string_lossy(),
"Spec file is missing the 'api' field, this may be an error in the future"
);
tracing::warn!(
Expand Down
Loading