Skip to content
Merged
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
51 changes: 51 additions & 0 deletions tools/system/dmf-get/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ dmf-get -o /path/to/output mymodule

# Specify tools name for variable substitution
dmf-get -t arch/armv7/cortex-m7 mymodule

# Download module and copy configuration file
dmf-get mymodule@1.0 --config board/config.ini --config-dir ./config

# Example: Download module with specific config (as requested in issue)
dmf-get dmclk@0.4 --config board/stm32f746g-disco.ini --config-dir ./config

# Download with custom config destination name
dmf-get mymodule --config mcu/default.ini --config-dir ./cfg --config-dest my.ini
```

#### Multiple Modules with Dependencies File (.dmd)
Expand Down Expand Up @@ -97,11 +106,50 @@ dmf-man -d /path/to/docs mymodule

For more information about viewing documentation, see the [dmf-man tool documentation](../dmf-man/README.md).

#### Copying Configuration Files from Modules

When downloading a single module from the command line, you can specify a configuration file to copy from the module package using the `--config` option. This feature is similar to the configuration file support in `.dmd` files.

```bash
# Copy a configuration file from the module to a destination directory
dmf-get dmclk@0.4 --config board/stm32f746g-disco.ini --config-dir ./config

# This will:
# 1. Download and install the dmclk@0.4 module
# 2. Look for board/stm32f746g-disco.ini in the module's config directory
# 3. Copy it to ./config/dmclk/stm32f746g-disco.ini

# Specify a custom destination filename (without module subdirectory)
dmf-get mymodule --config mcu/default.ini --config-dir ./cfg --config-dest my.ini
# Copies to: ./cfg/my.ini (instead of ./cfg/mymodule/default.ini)

# Use with variable substitution
dmf-get mymodule --config boards/${BOARD}/config.ini --config-dir ./config -D BOARD=stm32f7
# Substitutes ${BOARD} with stm32f7 in the config path
```

**Configuration File Lookup:**
1. The configuration file is searched in the module's config directory as specified in the `.dmr` file
2. If not found in `.dmr`, the default location `<output-dir>/<module-name>/config/<config-path>` is used

**Destination Naming:**
- **Default behavior**: Configuration file is copied to `<config-dir>/<module-name>/<filename>`
- **With --config-dest**: Configuration file is copied to `<config-dir>/<custom-name>`

**Requirements:**
- Both `--config` and `--config-dir` must be specified together
- The module must be successfully installed before the configuration file is copied
- If configuration file copying fails, the module installation still succeeds (with a warning)

### Command-Line Options

- `-d, --dependencies <path>` - Path or URL to dependencies (.dmd) file
- `-m, --manifest <path>` - Path or URL to manifest file
- `-o, --output-dir <path>` - Output directory for downloaded modules
- `--config <path>` - Configuration file to copy from module (for single module only)
- `--config-dir <path>` - Directory where configuration files should be copied
- `--config-dest <name>` - Custom destination filename for configuration file
- `-D, --define <VAR=value>` - Define variable for configuration path substitution
- `-t, --tools-name <name>` - Tools name for variable substitution
- `-a, --arch-name <name>` - Architecture name for variable substitution
- `--type <dmf|dmfc>` - Prefer dmf or dmfc file type
Expand Down Expand Up @@ -166,6 +214,9 @@ dmf-get -t arch/armv7/cortex-m7 mymodule@1.0
# Download to specific directory
dmf-get -o ./my_modules mymodule

# Download module with configuration file (as requested in issue)
dmf-get dmclk@0.4 --config board/stm32f746g-disco.ini --config-dir ./config

# Non-interactive mode (automatically accept licenses)
dmf-get -y mymodule
```
Expand Down
52 changes: 52 additions & 0 deletions tools/system/dmf-get/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1927,6 +1927,8 @@ static void PrintUsage(const char* app_name) {
Dmod_Printf(" -m, --manifest <path> Path or URL to manifest file\n");
Dmod_Printf(" -o, --output-dir <path> Output directory for downloaded modules\n");
Dmod_Printf(" --config-dir <path> Directory where configuration files should be copied\n");
Dmod_Printf(" --config <path> Configuration file to copy (for single module only)\n");
Dmod_Printf(" --config-dest <name> Custom destination filename for config file\n");
Dmod_Printf(" -D, --define <VAR=value> Define variable for config path substitution\n");
Dmod_Printf(" -t, --tools-name <name> Tools name for variable substitution\n");
Dmod_Printf(" -a, --arch-name <name> Architecture name for variable substitution\n");
Expand Down Expand Up @@ -1963,6 +1965,8 @@ static void PrintUsage(const char* app_name) {
Dmod_Printf(" %s -d deps.dmd # Download all modules from deps.dmd\n", app_name);
Dmod_Printf(" %s -d deps.dmd --config-dir ./config # Download modules and copy configs to ./config\n", app_name);
Dmod_Printf(" %s -d deps.dmd --config-dir ./config -D BOARD=stm32f7 # Use variable substitution in config paths\n", app_name);
Dmod_Printf(" %s dmclk@0.4 --config board/stm32f746g-disco.ini --config-dir ./config # Download module with config\n", app_name);
Dmod_Printf(" %s mymodule --config mcu/config.ini --config-dir ./cfg --config-dest my.ini # Custom config destination\n", app_name);
Dmod_Printf(" %s -m http://... module # Use custom manifest\n", app_name);
Dmod_Printf(" %s --type dmfc module # Prefer dmfc files\n", app_name);
Dmod_Printf(" %s -a armv7-cortex-m7 module # Use arch name directly\n", app_name);
Expand Down Expand Up @@ -2332,6 +2336,8 @@ int main(int argc, char* argv[]) {
const char* manifest_path = NULL;
const char* output_dir = NULL;
const char* config_dir = NULL;
const char* config_file = NULL; // Configuration file to copy for single module
const char* config_dest_name = NULL; // Custom destination name for config file
const char* tools_name = NULL;
const char* arch_name = NULL;
const char* cpu_name = NULL;
Expand Down Expand Up @@ -2385,6 +2391,20 @@ int main(int argc, char* argv[]) {
}
config_dir = argv[i];
}
else if (strcmp(argv[i], "--config") == 0) {
if (++i >= argc) {
DMOD_LOG_ERROR("Error: %s requires an argument\n", argv[i-1]);
return 1;
}
config_file = argv[i];
}
else if (strcmp(argv[i], "--config-dest") == 0) {
if (++i >= argc) {
DMOD_LOG_ERROR("Error: %s requires an argument\n", argv[i-1]);
return 1;
}
config_dest_name = argv[i];
}
else if (strcmp(argv[i], "-D") == 0 || strcmp(argv[i], "--define") == 0) {
if (++i >= argc) {
DMOD_LOG_ERROR("Error: %s requires an argument\n", argv[i-1]);
Expand Down Expand Up @@ -2532,6 +2552,32 @@ int main(int argc, char* argv[]) {
return 1;
}

// Validate --config option usage
if (config_file) {
if (!config_dir) {
DMOD_LOG_ERROR("Error: --config requires --config-dir to be specified\n");
PrintUsage(argv[0]);
return 1;
}
if (dependencies_path) {
DMOD_LOG_ERROR("Error: --config cannot be used with -d/--dependencies\n");
DMOD_LOG_ERROR(" Use configuration syntax in .dmd file instead\n");
PrintUsage(argv[0]);
return 1;
}
if (command && (strcmp(command, "headers") == 0 || strcmp(command, "docs") == 0)) {
DMOD_LOG_ERROR("Error: --config cannot be used with %s command\n", command);
PrintUsage(argv[0]);
return 1;
}
}

if (config_dest_name && !config_file) {
DMOD_LOG_ERROR("Error: --config-dest requires --config to be specified\n");
PrintUsage(argv[0]);
return 1;
}

// Initialize curl
curl_global_init(CURL_GLOBAL_DEFAULT);

Expand Down Expand Up @@ -2930,6 +2976,12 @@ int main(int argc, char* argv[]) {

if (result != 0) {
counts.failed_count++;
} else if (config_file && config_dir) {
// If configuration file is specified via command line, copy it
DMOD_LOG_INFO("Configuration file specified: %s\n", config_file);
if (!CopyConfigurationFile(module_name, config_file, output_dir, config_dir, config_dest_name)) {
DMOD_LOG_WARN("Failed to copy configuration file (module was installed successfully)\n");
}
}

// Print installation summary
Expand Down
Loading