paulgazz / kmax

A collection of analysis tools for Kconfig and Kbuild constraints.
42 stars 21 forks source link

Preserve the escape sequences when outputing Kconfig non-bool values #221

Closed paulgazz closed 1 year ago

paulgazz commented 1 year ago

As reported by @pattersonz:

When a default value has an escape character, such as:

config CONFIG_VISUAL_STUDIO_7_0_BASE
    string "Base"
    depends on CONFIG_VISUAL_STUDIO_7_0
    default "c:\\Program Files\\Microsoft Visual Studio .NET 2003"

The output strips away the escape: def_nonbool CONFIG_CONFIG_VISUAL_STUDIO_7_0_BASE "c:\Program Files\Microsoft Visual Studio .NET 2003"

To fix this, use the sym_escape_string_value function which preserves the escape sequences (and adds quotes) before emitting the string. Test by running all of the current kextract versions on the test case above.

for version in next-20210426 next-20200430 3.19 4.12.8 4.18; do
    echo "VERSION: ${version}";
    kextract --module-version ${version} --extract tests/kclause_tests/escape_codes;
done

The default value for the non-boolean should have escaped back-slashes:

def_nonbool CONFIG_CONFIG_VISUAL_STUDIO_7_0_BASE "c:\\Program Files\\Microsoft Visual Studio .NET 2003"|("CONFIG_VISUAL_STUDIO_7_0")

Fixes #219