Skip to content

Add cross-platform support for determining the executable directory and output directory configuration#13

Open
eharquin wants to merge 2 commits intovincentnozick:masterfrom
eharquin:fix-executable-path
Open

Add cross-platform support for determining the executable directory and output directory configuration#13
eharquin wants to merge 2 commits intovincentnozick:masterfrom
eharquin:fix-executable-path

Conversation

@eharquin
Copy link

Title: Add Cross-Platform Support for Determining the Executable Directory and Configurable Paths


Description

This PR introduces the following enhancements and fixes:

  1. Cross-Platform Executable Directory Detection:

    • Replaced hardcoded paths with a dynamic method to retrieve the directory of the executable.
    • Added platform-specific logic:
      • Windows: Used GetModuleFileNameA to retrieve the executable's directory.
      • Linux/macOS: Used dirname() from <libgen.h>.
  2. New -d Option for Configurable Data Directory:

    • Introduced a -d <data_dir> option to specify the data directory path at runtime.
    • If no -d option is provided, the program defaults to a data directory relative to the executable's directory.
  3. Output Directory Configuration:

    • Introduced a -o <output_dir> option to specify the output directory for generated files.
    • If no -o option is provided, the default output directory (output/) is used.
  4. Improved Flexibility:

    • Removed the dependency on hardcoded paths like ../data. The data directory is now dynamically resolved based on the -d option or the executable's directory.

How to Test

  1. Build and Run:

    • Compile the project on both Linux/macOS and Windows platforms.
    • Run the executable with the -d and -o options:
      ./garamon_generator -d /custom/data/path -o /custom/output/path conf/example.conf
    • Verify that the data files are accessed from /custom/data/path and the output files are generated in /custom/output/path.
  2. Default Behavior:

    • Run the executable without the -d or -o options:
      ./garamon_generator conf/example.conf
    • Verify that the data directory defaults to ../data (relative to the executable) and the output files are generated in output/.
  3. Cross-Platform:

    • Ensure that the logic for detecting the executable directory and resolving the data directory works correctly on both Windows and Linux/macOS.

Additional Context

  • This PR resolves issues related to portability by removing dependencies on hardcoded paths.
  • The new -d option enhances usability by allowing the user to specify the data directory path dynamically.

Checklist

  • Verified functionality on Linux/macOS.
  • [] Verified functionality on Windows.
  • Added cross-platform support for the executable directory.
  • Added -d option for configurable data directory.
  • Tested with different data and output directory configurations.
  • [] Ensured backward compatibility with existing behavior.

@sbreuils sbreuils self-assigned this Nov 19, 2024
@sbreuils sbreuils added the enhancement New feature or request label Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants