Skip to content

Commit 1652245

Browse files
Merge pull request #30 from AbigailBuccaneer/AbigailBuccaneer-patch-1
Give targets smarter names
2 parents 5a89401 + 5d0e59b commit 1652245

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

json2cmake/__init__.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import argparse
33
import json
44
import os.path
5+
import re
56
import shlex
67
import subprocess
78
import sys
8-
import uuid
99

1010
try:
1111
basestring
@@ -114,9 +114,22 @@ def write(self, output, directory=None, name='autogenerated'):
114114
output.write('cmake_minimum_required(VERSION 2.8.8)\n')
115115
output.write('project({})\n\n'.format(name))
116116

117+
used_names = {""}
118+
disallowed_characters = re.compile("[^A-Za-z0-9_.+\-]")
119+
117120
for (config, files) in self.targets.items():
118121
config = {k: v for (k, v) in config}
119-
name = uuid.uuid4()
122+
name = os.path.basename(os.path.commonprefix(files).rstrip("/_"))
123+
name = re.sub(disallowed_characters, "", name)
124+
if name in used_names:
125+
index = 2
126+
while True:
127+
candidate = '{}_{}'.format(name, index)
128+
if candidate not in used_names:
129+
name = candidate
130+
break
131+
index = index + 1
132+
used_names.add(name)
120133

121134
output.write('add_library(%s OBJECT\n' % name)
122135
for file in files:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
setup(
1212
name='json2cmake',
13-
version='0.6.2',
13+
version='0.6.3',
1414
description='Generate CMakeLists.txt from a compile_commands.json',
1515
long_description=long_description,
1616
url='https://github.com/AbigailBuccaneer/json2cmake',

0 commit comments

Comments
 (0)