json2cmake
json2cmake copied to clipboard
TypeError: 'set' object does not support indexing
Using 13e0a6ba0111b6b with Python 3.7.1 on a following (redacted, simplified, but roughly the same) compile_commands.json
, I get following error:
$ json2cmake
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
Traceback (most recent call last):
File "/home/janisozaur/.local/bin/json2cmake", line 10, in <module>
sys.exit(main())
File "/home/janisozaur/.local/lib/python3.7/site-packages/json2cmake/__init__.py", line 223, in main
database.write(args.outfile, name=args.name)
File "/home/janisozaur/.local/lib/python3.7/site-packages/json2cmake/__init__.py", line 122, in write
name = os.path.basename(os.path.commonprefix(files).rstrip("/_"))
File "/usr/lib/python3.7/genericpath.py", line 76, in commonprefix
if not isinstance(m[0], (list, tuple)):
TypeError: 'set' object does not support indexing
[
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-m64",
"-fPIC",
"-pipe",
"-fno-strict-aliasing",
"-Og",
"-g",
"-fno-omit-frame-pointer",
"-I.",
"-I../../include",
"-o",
"ccc.o",
"../../../foo/bar_43/ccc.c"
],
"directory": "/home/janisozaur/workspace/foo-build/bar_43",
"file": "../../../foo/bar_43/ccc.c"
},
{
"arguments": [
"gcc",
"-c",
"-m64",
"-I.",
"-I../../include",
"-fPIC",
"-pipe",
"-fno-strict-aliasing",
"-Og",
"-g",
"-fno-omit-frame-pointer",
"-o",
"aaa.o",
"../../../foo/bar_43/aaa.c"
],
"directory": "/home/janisozaur/workspace/foo-build/bar_43",
"file": "../../../foo/bar_43/aaa.c"
},
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-m64",
"-fPIC",
"-pipe",
"-fno-strict-aliasing",
"-Og",
"-g",
"-fno-omit-frame-pointer",
"-I.",
"-I../../include",
"-o",
"bbb.o",
"../../../foo/bar_43/bbb.c"
],
"directory": "/home/janisozaur/workspace/foo-build/bar_43",
"file": "../../../foo/bar_43/bbb.c"
}
]
It looks like json2cmake
is also looking for some git information, but in this case I built the project outside of the git clone.
Encountered this as well.
Seems like the commonprefix (used at init.py:122) does not like the files that are submitted which is a set. Changing the line to:
name = os.path.basename(os.path.commonprefix(list(files)).rstrip("/_"))
Avoids the error.
Closed by #32, but it has not been released to PyPI yet.