Skip to content

Windows: _enter_file's filename argument has a mix of \ and / in the filename path #15

@gudnimg

Description

@gudnimg

This is just something I spotted when looking into something else. Consider this an idea for improvement.


We have this code in kconfiglib.py, def _enter_file(self, filename)

if filename.startswith(self._srctree_prefix):

# Path relative to $srctree, stored in e.g. self.filename (which makes
# it indirectly show up in MenuNode.filename). Equals 'filename' for
# absolute paths passed to 'source'.
if filename.startswith(self._srctree_prefix):
    # Relative path (or a redundant absolute path to within $srctree,
    # but it's probably fine to reduce those too)
    rel_filename = filename[len(self._srctree_prefix):]
else:
    # Absolute path
    rel_filename = filename

self.kconfig_filenames.append(rel_filename)

On Windows I see that:

self._srctree_prefix = C:\folder1\folder2\zephyr\

While at the same time
filename = C:/folder1/folder2/nrf\samples/Kconfig

In this case what we want is for this if statement to be True: filename.startswith(self._srctree_prefix), but due to the path separators not being consistent it doesn't. And the full absolute path is loaded into memory in variables like self.kconfig_filenames.append(rel_filename)

Source of inconsistency

I investigated this a bit and found that the source of the inconsistency is from pattern = self._expect_str_and_eol()

pattern = self._expect_str_and_eol()
. Here / is always used even though \ would be expected for a filepath in Windows.

I do not understand the Tokenizer code enough to find where the / was coming from. At least at the time of writing this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions