Skip to content

Bug: Generated header contains empty include when source and build directories are on different drives (Windows) #16

Description

@fnMrRice

Description

On Windows, when the source directory and the build directory are located on different drives (for example, source on C: and build on D:), the generated header file contains an empty include/file content instead of the expected relative path.

This issue occurs because relative path generation fails across different drive letters on Windows.

Steps to Reproduce

  1. Place the project source directory on drive C:.
  2. Configure the build directory on drive D:.
  3. Generate the project.
  4. Inspect the generated header file.

Expected Behavior

The generated header should correctly reference the intended file regardless of whether the source and build directories are on different drives.

Actual Behavior

The generated header contains an empty file/include when the source and build directories are on different drives.

Fix

Subject: [PATCH] fix
---
Index: src/corecmd/main.cpp
<+>UTF-8
===================================================================
diff --git a/src/corecmd/main.cpp b/src/corecmd/main.cpp
--- a/src/corecmd/main.cpp	(revision 4a3ff82d89d3101a77ba8dda52868a930cff5a3d)
+++ b/src/corecmd/main.cpp	(date 1783647373833)
@@ -787,7 +787,8 @@
                 fs::copy(path, targetPath, fs::copy_options::overwrite_existing);
             } else {
                 // Make relative reference
-                std::string rel = tstr2str(fs::relative(path, targetDir));
+                auto relPath = fs::relative(path, targetDir);
+                std::string rel = tstr2str(relPath.empty() ? path : relPath);
 
 #ifdef _WIN32
                 // Replace separator

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions