-
Notifications
You must be signed in to change notification settings - Fork 178
Expand file tree
/
Copy pathclean.rs
More file actions
96 lines (82 loc) · 3.38 KB
/
clean.rs
File metadata and controls
96 lines (82 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
use crate::app::context::BuildContext;
use crate::fs;
use crate::log::{log_action, LogIndent};
use crate::model::app::CleanMode;
use golem_common::model::component::ComponentName;
use std::collections::BTreeSet;
use std::path::PathBuf;
// Copyright 2024-2025 Golem Cloud
//
// Licensed under the Golem Source License v1.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://license.golem.cloud/LICENSE
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
pub fn clean_app(ctx: &BuildContext<'_>, mode: CleanMode) -> anyhow::Result<()> {
{
log_action("Cleaning", "components");
let _indent = LogIndent::new();
let paths = {
let mut paths = BTreeSet::<(&'static str, PathBuf)>::new();
let component_names: Vec<ComponentName> = match mode {
CleanMode::All => ctx.application().component_names().cloned().collect(),
CleanMode::SelectedComponentsOnly => ctx
.application_context()
.selected_component_names()
.iter()
.cloned()
.collect(),
};
for component_name in &component_names {
let component = ctx.application().component(component_name);
let component_source_dir = component.source_dir();
paths.insert(("generated wit", component.generated_wit()));
paths.insert(("component wasm", component.wasm()));
paths.insert(("output wasm", component.final_wasm()));
for build_step in component.build_commands() {
let build_dir = build_step
.dir()
.map(|dir| component_source_dir.join(dir))
.unwrap_or_else(|| component_source_dir.to_path_buf());
paths.extend(
fs::compile_and_collect_globs(&build_dir, &build_step.targets())?
.into_iter()
.map(|path| ("build output", path)),
);
}
paths.extend(
component
.clean()
.iter()
.map(|path| ("clean target", component_source_dir.join(path))),
);
}
paths
};
for (context, path) in paths {
fs::delete_logged(context, &path)?;
}
}
match mode {
CleanMode::All => {
log_action("Cleaning", "common clean targets");
let _indent = LogIndent::new();
for clean in ctx.application().common_clean() {
fs::delete_logged("common clean target", &clean.source.join(&clean.value))?;
}
log_action("Cleaning", "application build dir");
let _indent = LogIndent::new();
fs::delete_logged("temp dir", ctx.application().temp_dir())?;
}
CleanMode::SelectedComponentsOnly => {
// NOP
}
}
Ok(())
}