Skip to content

Commit 7d07ad9

Browse files
authored
doc: Selective clean functionality (#169)
1 parent dba6413 commit 7d07ad9

File tree

2 files changed

+201
-0
lines changed

2 files changed

+201
-0
lines changed

pages/how-to/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ This section contains practical guides and recipes for solving specific problems
66

77
:::{toctree}
88
compute-pi-openmp
9+
selective-cleaning
910
:::

pages/how-to/selective-cleaning.md

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
# Cleaning build artifacts with fpm
2+
3+
The `fpm clean` command allows you to remove build artifacts to free up disk space or ensure a fresh build. This guide covers both general cleaning and selective cleaning options.
4+
5+
## Overview
6+
7+
By default, `fpm clean` prompts for confirmation before deleting directories in the `build/` folder while preserving dependencies. The command supports several modes of operation:
8+
9+
- **Interactive cleaning** (default): Prompts for confirmation
10+
- **Automatic cleaning**: Skip prompts with `--skip` or `--all`
11+
- **Selective cleaning** *(fpm v0.14.0+)*: Target specific executable types
12+
- **Registry cache cleaning**: Remove cached registry data
13+
14+
## General cleaning options
15+
16+
### Default behavior
17+
18+
```bash
19+
fpm clean
20+
```
21+
22+
Prompts for confirmation before deleting build artifacts, excluding dependencies. This is the safest option for regular use.
23+
24+
### Skip confirmation, preserve dependencies
25+
26+
```bash
27+
fpm clean --skip
28+
```
29+
30+
Deletes build directories without prompting but preserves dependency builds. Useful in automated scripts where you want to clean your project but keep external dependencies intact.
31+
32+
### Clean everything including dependencies
33+
34+
```bash
35+
fpm clean --all
36+
```
37+
38+
Deletes all build directories without prompting, including dependencies. Use this when you need a completely fresh build environment or when dependency issues require rebuilding everything from scratch.
39+
40+
### Clean registry cache
41+
42+
```bash
43+
fpm clean --registry-cache
44+
```
45+
46+
Removes cached registry data. Useful when registry metadata becomes stale or when troubleshooting package resolution issues.
47+
48+
### Custom configuration file
49+
50+
```bash
51+
fpm clean --config-file /path/to/config.toml
52+
```
53+
54+
Use a custom global configuration file location for the clean operation.
55+
56+
## Selective cleaning options
57+
58+
:::{note}
59+
Available since fpm v0.14.0
60+
:::
61+
62+
Selective cleaning allows you to remove only specific types of executables, which speeds up recompilation by preserving other build outputs.
63+
64+
### Available selective cleaning flags
65+
66+
- `--test`: Clean only test executables
67+
- `--apps`: Clean only application executables
68+
- `--examples`: Clean only example executables
69+
70+
### Selective cleaning examples
71+
72+
#### Clean test executables only
73+
74+
```bash
75+
fpm clean --test
76+
```
77+
78+
This removes only the compiled test executables while preserving application executables, example executables, and all object files. Useful when you've modified test code and want to ensure tests are rebuilt from scratch.
79+
80+
#### Clean application executables only
81+
82+
```bash
83+
fpm clean --apps
84+
```
85+
86+
This removes only the compiled application executables while preserving test executables, example executables, and object files. Useful when you've made changes that affect only your main applications.
87+
88+
#### Clean example executables only
89+
90+
```bash
91+
fpm clean --examples
92+
```
93+
94+
This removes only the compiled example executables while preserving application and test executables, and object files. Useful when working on documentation examples.
95+
96+
### Combining selective flags
97+
98+
You can combine multiple flags to clean several types of executables simultaneously:
99+
100+
```bash
101+
# Clean both test and application executables
102+
fpm clean --test --apps
103+
104+
# Clean all executable types (equivalent to targeting all executables)
105+
fpm clean --test --apps --examples
106+
```
107+
108+
## Use cases and workflows
109+
110+
### Common scenarios
111+
112+
#### Debugging failing tests
113+
114+
When tests are failing and you suspect cached executables might be the issue:
115+
116+
```bash
117+
fpm clean --test
118+
fpm test
119+
```
120+
121+
This ensures test executables are rebuilt from scratch while preserving your application builds.
122+
123+
#### Preparing for release
124+
125+
Before building release versions of your applications:
126+
127+
```bash
128+
fpm clean --apps
129+
fpm build --release
130+
```
131+
132+
This ensures your applications are built fresh while preserving test and example builds for ongoing development.
133+
134+
### Working on examples
135+
136+
When updating documentation examples:
137+
138+
```bash
139+
fpm clean --examples
140+
fpm run --example my_example
141+
```
142+
143+
This rebuilds only the example you're working on without affecting your main application or tests.
144+
145+
### Managing disk space efficiently
146+
147+
For large projects where full rebuilds are time-consuming:
148+
149+
```bash
150+
# Clean only what you're currently working on
151+
fpm clean --test # If working on tests
152+
fpm clean --apps # If working on applications
153+
fpm clean --examples # If working on examples
154+
```
155+
156+
## Command reference
157+
158+
### Complete option summary
159+
160+
| Command | What gets removed | Dependencies | Prompts | Use when |
161+
|---------|------------------|--------------|---------|----------|
162+
| `fpm clean` | All build artifacts | Preserved | Yes | Safe interactive cleaning |
163+
| `fpm clean --skip` | All build artifacts | Preserved | No | Automated scripts, preserve deps |
164+
| `fpm clean --all` | All build artifacts | Removed | No | Fresh start, dependency issues |
165+
| `fpm clean --registry-cache` | Registry cache only | N/A | No | Registry troubleshooting |
166+
| `fpm clean --test` | Test executables only | Preserved | Variable | Test-specific issues |
167+
| `fpm clean --apps` | Application executables only | Preserved | Variable | Application changes |
168+
| `fpm clean --examples` | Example executables only | Preserved | Variable | Documentation updates |
169+
170+
### Combining options
171+
172+
You can combine general and selective cleaning options:
173+
174+
```bash
175+
# Clean test and apps without prompting, preserve dependencies
176+
fpm clean --skip --test --apps
177+
178+
# Clean everything including dependencies and registry cache
179+
fpm clean --all --registry-cache
180+
```
181+
182+
## Performance benefits
183+
184+
Selective cleaning provides several advantages:
185+
186+
- **Faster rebuilds**: Preserves object files and unmodified executables
187+
- **Targeted workflow**: Clean only what you're working on
188+
- **Disk space management**: Remove executables while keeping compiled objects
189+
- **Parallel development**: Different team members can clean different components
190+
191+
## Best practices
192+
193+
1. **Use selective cleaning during development**: Avoid full `fpm clean` unless necessary
194+
2. **Clean specific targets when troubleshooting**: If tests fail, try `fpm clean --test` first
195+
3. **Combine with build flags**: `fpm clean --apps && fpm build --release` for release builds
196+
4. **Clean examples regularly**: Examples often have different build requirements than main code
197+
198+
:::{tip}
199+
If you're unsure which executables to clean, start with the most specific flag (e.g., `--test` if working on tests) and escalate to broader cleaning only if needed.
200+
:::

0 commit comments

Comments
 (0)