pavelliavonau/cmakeconverter

index error replacement index 1 out of range for positional args tuple

ShivamMahajan10 opened this issue ยท 6 comments

I am running the command as cmake-converter - "path.sln"

Very informative.
Thank you.

Same error here. It's a Qt project

PS D:\> cmake-converter -s "R:\Tools\CryptoTester2\CryptoTester.sln"
0.000000 processes count = 8
0.001024 warnings level = 2
0.190542 1> Conversion started: Project CryptoTester
multiprocessing.pool.RemoteTraceback:
"""
Traceback (most recent call last):
  File "c:\users\mark\appdata\local\programs\python\python38\lib\multiprocessing\pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "c:\users\mark\appdata\local\programs\python\python38\lib\multiprocessing\pool.py", line 48, in mapstar
    return list(map(*args))
  File "c:\users\mark\appdata\local\programs\python\python38\lib\site-packages\cmake_converter\data_converter.py", line 285, in run_conversion
    converted = self.convert_project(
  File "c:\users\mark\appdata\local\programs\python\python38\lib\site-packages\cmake_converter\data_converter.py", line 252, in convert_project
    self.collect_data(context)
  File "c:\users\mark\appdata\local\programs\python\python38\lib\site-packages\cmake_converter\data_converter.py", line 53, in collect_data
    context.parser.parse(context)
  File "c:\users\mark\appdata\local\programs\python\python38\lib\site-packages\cmake_converter\visual_studio\vcxproj\parser.py", line 145, in parse
    self._parse_nodes(context, root)
  File "c:\users\mark\appdata\local\programs\python\python38\lib\site-packages\cmake_converter\parser.py", line 101, in _parse_nodes
    node_handlers[child_node_tag](context, child_node)
  File "c:\users\mark\appdata\local\programs\python\python38\lib\site-packages\cmake_converter\visual_studio\vcxproj\parser.py", line 190, in __parse_property_group
    self._parse_nodes(context, node)
  File "c:\users\mark\appdata\local\programs\python\python38\lib\site-packages\cmake_converter\parser.py", line 92, in _parse_nodes
    self._parse_attributes(context, child_node)
  File "c:\users\mark\appdata\local\programs\python\python38\lib\site-packages\cmake_converter\parser.py", line 119, in _parse_attributes
    attributes_handlers[attr](context, attr, node.get(attr), node)
  File "c:\users\mark\appdata\local\programs\python\python38\lib\site-packages\cmake_converter\visual_studio\vcxproj\parser.py", line 291, in __parse_condition
    cmake_setting = make_cmake_configuration(context, found.group(1))
  File "c:\users\mark\appdata\local\programs\python\python38\lib\site-packages\cmake_converter\utils.py", line 508, in make_cmake_configuration
    return "{}|{}".format(*sln_conf_arch)
IndexError: Replacement index 1 out of range for positional args tuple
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "c:\users\mark\appdata\local\programs\python\python38\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\mark\appdata\local\programs\python\python38\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\mark\AppData\Local\Programs\Python\Python38\Scripts\cmake-converter.exe\__main__.py", line 7, in <module>
  File "c:\users\mark\appdata\local\programs\python\python38\lib\site-packages\cmake_converter\main.py", line 144, in main
    converter.convert_solution(project_context, os.path.abspath(args.solution))
  File "c:\users\mark\appdata\local\programs\python\python38\lib\site-packages\cmake_converter\visual_studio\solution.py", line 330, in convert_solution
    results = self.do_conversion(project_context, input_data_for_converter)
  File "c:\users\mark\appdata\local\programs\python\python38\lib\site-packages\cmake_converter\data_converter.py", line 317, in do_conversion
    results = pool.map(self.run_conversion, input_converter_data_list)
  File "c:\users\mark\appdata\local\programs\python\python38\lib\multiprocessing\pool.py", line 364, in map
    return self._map_async(func, iterable, mapstar, chunksize).get()
  File "c:\users\mark\appdata\local\programs\python\python38\lib\multiprocessing\pool.py", line 771, in get
    raise self._value
IndexError: Replacement index 1 out of range for positional args tuple

@marc6h , have you checked all the issues before posting this??

In fact it's the same as in #128 , which was closed about a year ago.
Still the question is - is there any workaround?
I had the same problem and the reason was the setup project: in *.sln-file all the projects in the postProject section had configs like:
{guid}.Debug|x64.ActiveCfg = Debug|x64
{guid}.Release|x64.ActiveCfg = Release|x64
the setup project was:
{guid}.Debug|x64.ActiveCfg = Debug
{guid}.Release|x64.ActiveCfg = Release
So no '|', and IndexError.
Removing such kinds of projects from *.sln solved the IndexError issue in my case.

It seem that the text below in the *.vcproj file will cause this error:
<QtMsBuild Condition="'$(QtMsBuild)'=='' OR !Exists('$(QtMsBuild)\qt.targets')">$(MSBuildProjectDirectory)\QtMsBuild</QtMsBuild>

same here

git clone --depth=1 https://github.com/nu774/qaac
cd qaac
cmake-converter -s ./vcproject/qaac.sln

input

<PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration">

cmake_converter/utils.py

def make_cmake_configuration(context, sln_configuration):
    """ Tries to make cmake configuration name from sln_configuration """
    sln_conf_arch = sln_configuration.split('|')
    genex_invalid_regex = r'[^A-Za-z0-9_]'
    sln_conf_arch[0] = escape_string(context, genex_invalid_regex, sln_conf_arch[0])

    # sln_conf_arch = ['Debug']
    if len(sln_conf_arch) != 2:
        raise ValueError(f"sln_conf_arch = {repr(sln_conf_arch)}")

    # IndexError: Replacement index 1 out of range for positional args tuple
    return "{}|{}".format(*sln_conf_arch)

cmake_converter/visual_studio/vcxproj/parser.py

    def __parse_condition(self, context, attr_name, condition_value, node):
        del attr_name

        # condition_value = "'$(Configuration)'=='Debug'"
        print(f"condition_value = {repr(condition_value)}")

        # WTF? regex != parser
        found = re.search(r".*=='(.*)'", condition_value)
        if not found:
            return

        cmake_setting = make_cmake_configuration(context, found.group(1))

#128 (comment)

Cmake converter does not and won't support handmade msbuild files. It's not parser of msbuild language.

how hard can it be to parse these expressions? these are
boolean expressions, strings, string interpolations, variables, function calls

https://github.com/pyparsing/pyparsing/blob/master/examples/simpleBool.py
https://github.com/pyparsing/pyparsing/blob/master/examples/eval_arith.py
https://github.com/pyparsing/pyparsing/blob/master/examples/lucene_grammar.py
https://github.com/pyparsing/pyparsing/blob/master/examples/fourFn.py
https://docs.galaxyproject.org/en/release_22.05/_modules/galaxy/util/bool_expressions.html
https://lmfit.github.io/asteval/motivation.html
https://github.com/pyparsing/plusminus
https://stackoverflow.com/questions/23879784/parse-mathematical-expressions-with-pyparsing
...

i looked at 10 different vcxproj converters
and none of them handle the Condition="..." attributes