|
| 1 | +# Selective cleaning with fpm |
| 2 | + |
| 3 | +:::{note} |
| 4 | +Available since fpm v0.14.0 |
| 5 | +::: |
| 6 | + |
| 7 | +The `fpm clean` command allows you to remove build artifacts to free up disk space or ensure a fresh build. By default, `fpm clean` removes all build artifacts, but you can use selective cleaning to remove only specific types of executables, which speeds up recompilation by preserving other build outputs. |
| 8 | + |
| 9 | +## Command overview |
| 10 | + |
| 11 | +The selective cleaning feature provides three flags to target specific executable types: |
| 12 | + |
| 13 | +- `--test`: Clean only test executables |
| 14 | +- `--apps`: Clean only application executables |
| 15 | +- `--examples`: Clean only example executables |
| 16 | + |
| 17 | +## Basic usage |
| 18 | + |
| 19 | +### Clean test executables only |
| 20 | + |
| 21 | +```bash |
| 22 | +fpm clean --test |
| 23 | +``` |
| 24 | + |
| 25 | +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. |
| 26 | + |
| 27 | +### Clean application executables only |
| 28 | + |
| 29 | +```bash |
| 30 | +fpm clean --apps |
| 31 | +``` |
| 32 | + |
| 33 | +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. |
| 34 | + |
| 35 | +### Clean example executables only |
| 36 | + |
| 37 | +```bash |
| 38 | +fpm clean --examples |
| 39 | +``` |
| 40 | + |
| 41 | +This removes only the compiled example executables while preserving application and test executables, and object files. Useful when working on documentation examples. |
| 42 | + |
| 43 | +## Combining flags |
| 44 | + |
| 45 | +You can combine multiple flags to clean several types of executables simultaneously: |
| 46 | + |
| 47 | +```bash |
| 48 | +# Clean both test and application executables |
| 49 | +fpm clean --test --apps |
| 50 | + |
| 51 | +# Clean all executable types (equivalent to targeting all executables) |
| 52 | +fpm clean --test --apps --examples |
| 53 | +``` |
| 54 | + |
| 55 | +## Practical use cases |
| 56 | + |
| 57 | +### Debugging failing tests |
| 58 | + |
| 59 | +When tests are failing and you suspect cached executables might be the issue: |
| 60 | + |
| 61 | +```bash |
| 62 | +fpm clean --test |
| 63 | +fpm test |
| 64 | +``` |
| 65 | + |
| 66 | +This ensures test executables are rebuilt from scratch while preserving your application builds. |
| 67 | + |
| 68 | +### Preparing for release |
| 69 | + |
| 70 | +Before building release versions of your applications: |
| 71 | + |
| 72 | +```bash |
| 73 | +fpm clean --apps |
| 74 | +fpm build --release |
| 75 | +``` |
| 76 | + |
| 77 | +This ensures your applications are built fresh while preserving test and example builds for ongoing development. |
| 78 | + |
| 79 | +### Working on examples |
| 80 | + |
| 81 | +When updating documentation examples: |
| 82 | + |
| 83 | +```bash |
| 84 | +fpm clean --examples |
| 85 | +fpm run --example my_example |
| 86 | +``` |
| 87 | + |
| 88 | +This rebuilds only the example you're working on without affecting your main application or tests. |
| 89 | + |
| 90 | +### Managing disk space efficiently |
| 91 | + |
| 92 | +For large projects where full rebuilds are time-consuming: |
| 93 | + |
| 94 | +```bash |
| 95 | +# Clean only what you're currently working on |
| 96 | +fpm clean --test # If working on tests |
| 97 | +fpm clean --apps # If working on applications |
| 98 | +fpm clean --examples # If working on examples |
| 99 | +``` |
| 100 | + |
| 101 | +## Comparison with full cleaning |
| 102 | + |
| 103 | +| Command | What gets removed | Use when | |
| 104 | +|---------|------------------|----------| |
| 105 | +| `fpm clean` | All build artifacts | Starting completely fresh, major build system changes | |
| 106 | +| `fpm clean --test` | Test executables only | Test-specific issues, modified test code | |
| 107 | +| `fpm clean --apps` | Application executables only | Application-specific changes | |
| 108 | +| `fpm clean --examples` | Example executables only | Documentation updates, example modifications | |
| 109 | + |
| 110 | +## Performance benefits |
| 111 | + |
| 112 | +Selective cleaning provides several advantages: |
| 113 | + |
| 114 | +- **Faster rebuilds**: Preserves object files and unmodified executables |
| 115 | +- **Targeted workflow**: Clean only what you're working on |
| 116 | +- **Disk space management**: Remove executables while keeping compiled objects |
| 117 | +- **Parallel development**: Different team members can clean different components |
| 118 | + |
| 119 | +## Best practices |
| 120 | + |
| 121 | +1. **Use selective cleaning during development**: Avoid full `fpm clean` unless necessary |
| 122 | +2. **Clean specific targets when troubleshooting**: If tests fail, try `fpm clean --test` first |
| 123 | +3. **Combine with build flags**: `fpm clean --apps && fpm build --release` for release builds |
| 124 | +4. **Clean examples regularly**: Examples often have different build requirements than main code |
| 125 | + |
| 126 | +:::{tip} |
| 127 | +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. |
| 128 | +::: |
0 commit comments