Skip to content

Bug: Generated CMakeLists.txt uses non-canonical relative paths (dir/.. instead of ../dir) #315

@sfourdrinier

Description

@sfourdrinier

Bug Report

Description

The generated android/CMakeLists.txt uses non-canonical relative paths like cpp/../file.cpp instead of the canonical form ../cpp/file.cpp. While both are technically valid, the non-canonical form can cause issues with some CMake versions and build tools.

Problem

When relative_to() calculates paths from android/CMakeLists.txt to files in cpp/, the pathdiff crate generates paths like:

cpp/../generated/file.cpp
cpp/../module.cpp

Impact

  • Some CMake configurations may fail to find source files with non-canonical paths
  • Build errors in certain environments
  • Less readable generated CMakeLists.txt files

Expected Behavior

Paths should be in canonical form:

../cpp/generated/file.cpp
../cpp/module.cpp

Root Cause

The relative_to() function in crates/ubrn_cli/src/codegen/mod.rs uses pathdiff::diff_utf8_paths() directly without normalizing the result. The pathdiff crate can produce non-canonical paths when calculating relative paths.

Reproduction

  1. Generate Android bindings for any project
  2. Check android/CMakeLists.txt
  3. Observe cpp/../ patterns in source file paths

References

Fix

PR #313 now includes a fix that lexically normalizes paths by processing components and eliminating dir/.. patterns.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions