Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 30 additions & 24 deletions cmake/scripts/BclCmakeFile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@

from __future__ import print_function

import string
import os
import sys
import os.path
import cStringIO
try:
from io import StringIO
except:
from StringIO import StringIO

# class represents a single SET(...) command from a CMakeLists file, optionally lower case
class CmakeListSetCommand:
Expand All @@ -27,7 +33,7 @@ def FromFile(self, lines, line_number_start):
start_scope_pos = lines[line_number_start].find('(')
self.line_number_end, end_scope_paren_pos = self.EndOfScope(lines, line_number_start, start_scope_pos)
if end_scope_paren_pos < 0 or self.line_number_end < 0:
print "Unclosed parenthesis!"
print("Unclosed parenthesis!")
return (-1)
if self.line_number_end >= len(lines):
self.line_number_end = len(lines) - 1
Expand All @@ -43,48 +49,48 @@ def FromFile(self, lines, line_number_start):
if set_command_clean.find('.cpp') < 0 and (set_command_clean.find("SOURCES") < 0 or set_command_clean.find('${') > 0):
# set command with no sources, not interesting
return (-1)

if end_scope_paren_pos != len(set_command_lines_clean[-1].rstrip()) - 1:
print str(line_number_start) + " " + str(start_scope_pos) \
print(str(line_number_start) + " " + str(start_scope_pos) \
+ " " + str(self.line_number_end) + " " + str(end_scope_paren_pos) \
+ " " + str(len(lines)) + " " + str(len(set_command_lines_clean[-1].rstrip()) - 1)
print "multiple commands on a single line not allowed, line: " + set_command_clean
+ " " + str(len(lines)) + " " + str(len(set_command_lines_clean[-1].rstrip()) - 1))
print("multiple commands on a single line not allowed, line: " + set_command_clean)
return (-1)

if set_command_clean != set_command:
print "could not parse set command: " + ''.join(set_command_lines_clean) + "\nbecause it contained comments or quotes"
print("could not parse set command: " + ''.join(set_command_lines_clean) + "\nbecause it contained comments or quotes")
return (-1)

# now we can finally parse the lines
set_command_internal = set_command.strip()[start_scope_pos + 1:-1].replace('\n', ' ').replace('\t', ' ')

#print "set command, internal component: " + set_command_internal
#print("set command, internal component: " + set_command_internal)

# make sure there were no comments or quotes in the set command
if set_command.find('#') > 0 or set_command.find('"') > 0 or set_command.find("'") > 0:
print "Could not parse cmake set command with internal comments or quotes"
print("Could not parse cmake set command with internal comments or quotes")
return (-1)

set_command_tokens = set_command_internal.split(' ')
set_command_tokens = [ token for token in set_command_tokens if len(token) > 0]

self.variable = set_command_tokens[ 0]
for token_index in xrange(1, len(set_command_tokens)):
for token_index in range(1, len(set_command_tokens)):
if set_command_tokens[token_index].endswith('.cpp'):
#print "adding source: " + set_command_tokens[token_index]
#print("adding source: " + set_command_tokens[token_index])
self.sources.add(set_command_tokens[token_index].replace('${CMAKE_CURRENT_SOURCE_DIR}/', ''))
elif len(self.sources) == 0:
#print "other variables: " + set_command_tokens[token_index] + " in " + set_command_internal
#print("other variables: " + set_command_tokens[token_index] + " in " + set_command_internal)
self.other_variables.append(set_command_tokens[token_index])
else:
#print "flag: " + set_command_tokens[token_index] + " in " + set_command_internal
#print("flag: " + set_command_tokens[token_index] + " in " + set_command_internal)
self.flag_lines.append(set_command_tokens[token_index])

if len(self.sources) == 0 and (len(self.other_variables) or len(self.flag_lines)):
print "no sources in " + set_command_internal
print("no sources in " + set_command_internal)
return (-1)

#print "sources: " + ','.join(self.sources)
#print("sources: " + ','.join(self.sources))
return self.line_number_end

def Write(self, x):
Expand Down Expand Up @@ -246,19 +252,19 @@ def CheckCmakeLists(directory, sources_dict, can_update):

# warn the user and return if the sources could not be added
if largest_set_command_index == -1:
print "Error: " + filename + ": Could not add sources because this file lacks a parseable set command that includes sources"
print ("Error: " + filename + ": Could not add sources because this file lacks a parseable set command that includes sources")
return

# warn the user if there is an ambiguous assignment of sources to a set command
if len(all_set_command_blocks) > 1 and len(added_sources) > 0:
print "Warning: ambiguous assignment of new sources in " + filename + " to largest block of sources"
print("Warning: ambiguous assignment of new sources in " + filename + " to largest block of sources")

if can_update:
# write the modified file to a cstringio object, then write that to a file
# write the modified file to a stringio object, then write that to a file
# this is several times faster than writing directly to the file
out_file = cStringIO.StringIO()
out_file = StringIO()
prev_line_start = 0
for cmake_set_number in xrange(len(all_set_command_blocks)):
for cmake_set_number in range(len(all_set_command_blocks)):
if(prev_line_start != all_set_command_blocks[cmake_set_number].line_number_start):
out_file.write(''.join(lines[prev_line_start:all_set_command_blocks[cmake_set_number].line_number_start]))
all_set_command_blocks[cmake_set_number].Write(out_file)
Expand All @@ -274,12 +280,12 @@ def CheckCmakeLists(directory, sources_dict, can_update):

# let the user know what was done
if len(removed_sources):
print "Removing " + ','.join(removed_sources) + " from " + filename
print("Removing " + ','.join(removed_sources) + " from " + filename)
if len(added_sources):
print "Adding " + ','.join(added_sources) + " to " + filename
print("Adding " + ','.join(added_sources) + " to " + filename)
else:
# will not update; just inform the user as to what would be added/removed
if len(removed_sources):
print "Running in fix mode would remove " + ','.join(removed_sources) + " from " + filename
print("Running in fix mode would remove " + ','.join(removed_sources) + " from " + filename)
if len(added_sources):
print "Running in fix mode would add " + ','.join(added_sources) + " to " + filename
print("Running in fix mode would add " + ','.join(added_sources) + " to " + filename)
Binary file removed cmake/scripts/BclCmakeFile.pyc
Binary file not shown.
12 changes: 7 additions & 5 deletions cmake/scripts/CheckCmakeLists.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
Created on Feb 19, 2011

This script checks CmakeLists for the bcl project, optionally updating CMakeLists.txt with new source files and removing
non-existent files.
non-existent files.

@author: mendenjl
'''
from __future__ import print_function


import os
import sys
import os.path
from BclCmakeFile import *

# print usage info
# print usage info
def usage():
print "\nusage: CheckCmakeLists.py bcl-path [-o]\n"
print "-o if given, update the CMakeLists"
print("\nusage: CheckCmakeLists.py bcl-path [-o]\n")
print("-o if given, update the CMakeLists")

def main():

Expand Down Expand Up @@ -57,7 +59,7 @@ def main():
# does the cmake list file even exist yet?
if source_directory not in cmake_list_paths.keys():
if len(directory_sources) > 0:
print source_directory + " needs a CMakeLists.txt file containing:\n" + '\n'.join(directory_sources) + '\n'
print(source_directory + " needs a CMakeLists.txt file containing:\n" + '\n'.join(directory_sources) + '\n')
else:
# open the cmake lists file
CheckCmakeLists(source_directory, source_files_and_directories, should_update)
Expand Down
4 changes: 2 additions & 2 deletions scripts/build/build_cmdline.apple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ BCL_DIRECTORY=`pwd`
export TOOLCHAIN_ALIAS TOOLCHAIN BUILD_TYPE_ALIAS BCL_DIRECTORY
mkdir -p build/${TOOLCHAIN_ALIAS}_${BUILD_TYPE_ALIAS}

python2 ./cmake/scripts/CheckCmakeLists.py ./ -o
python ./cmake/scripts/CheckCmakeLists.py ./ -o

python2 ./scripts/code/CreateNamespaceForwardHeaders.py ./ -o
python ./scripts/code/CreateNamespaceForwardHeaders.py ./ -o

if [ -z "${SHARED+x}" ] ; then
tcsh ./scripts/build/check_pump_make.csh -k static
Expand Down
4 changes: 2 additions & 2 deletions scripts/build/build_cmdline.linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ BCL_DIRECTORY=`pwd`
export TOOLCHAIN_ALIAS TOOLCHAIN BUILD_TYPE_ALIAS BCL_DIRECTORY
mkdir -p build/${TOOLCHAIN_ALIAS}_${BUILD_TYPE_ALIAS}

python2 ./cmake/scripts/CheckCmakeLists.py ./ -o
python ./cmake/scripts/CheckCmakeLists.py ./ -o

python2 ./scripts/code/CreateNamespaceForwardHeaders.py ./ -o
python ./scripts/code/CreateNamespaceForwardHeaders.py ./ -o

if [ -z "${SHARED+x}" ] ; then
tcsh ./scripts/build/check_pump_make.csh -k static
Expand Down
4 changes: 2 additions & 2 deletions scripts/build/build_cmdline.win.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ BCL_DIRECTORY=`pwd`
export TOOLCHAIN_ALIAS TOOLCHAIN BUILD_TYPE_ALIAS BCL_DIRECTORY
mkdir -p build/${TOOLCHAIN_ALIAS}_${BUILD_TYPE_ALIAS}

python2 ./cmake/scripts/CheckCmakeLists.py ./ -o
python ./cmake/scripts/CheckCmakeLists.py ./ -o

python2 ./scripts/code/CreateNamespaceForwardHeaders.py ./ -o
python ./scripts/code/CreateNamespaceForwardHeaders.py ./ -o

if [ -z "${SHARED+x}" ] ; then
tcsh ./scripts/build/check_pump_make.csh -k static
Expand Down
55 changes: 29 additions & 26 deletions scripts/code/CodeFileUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
@brief Functions used in parsing code-files, some of which are bcl-specific
@author: mendenjl
'''
from __future__ import print_function

import sys
import os
import cStringIO
from curses.ascii import isspace, isalpha, isdigit
from string import lower
try:
from io import StringIO
except:
from StringIO import StringIO

# write a string with a certain precision
def strWithPrecision(number, precision):
Expand All @@ -26,13 +29,13 @@ def Contains(listy, stringy):
return i

def findIndexStringStartingWith(listy, stringy, startPos = 0):
for i in xrange(max(startPos, 0), len(listy) , 1):
for i in range(max(startPos, 0), len(listy) , 1):
if listy[i].startswith(stringy):
return i
return (-1)

def rfindIndexStringStartingWith(listy, stringy, startPos = sys.maxint):
for i in xrange(min(len(listy), startPos), 0, -1):
def rfindIndexStringStartingWith(listy, stringy, startPos = sys.maxsize):
for i in range(min(len(listy), startPos), 0, -1):
if listy[i].startswith(stringy):
return i
return (-1)
Expand Down Expand Up @@ -400,7 +403,7 @@ def findAllNonArrayVariablesAndIndices(line):
i += 1
return tokens, listOIndices

# find all things that look like variables
# find all things that look like variables
def findAllNonArrayVariables(line):
return findAllNonArrayVariablesAndIndices(line)

Expand All @@ -426,7 +429,7 @@ def findEndOfUncommentedCPPFunction(ourLines, startLine):
break
startLine += 1
if startLine == len(ourLines):
print "Unbalanced brackets in " + '\n'.join(ourLines) + "terminating "
print("Unbalanced brackets in " + '\n'.join(ourLines) + "terminating ")
sys.exit(1)
return startLine

Expand Down Expand Up @@ -474,13 +477,13 @@ def walkToEndOfNumber(strn, startPos):
i = last
return i

ishex = [ isdigit(chr(x)) or (chr(x) >= 'a' and chr(x) <= 'f') or (chr(x) >= 'A' and chr(x) <= 'F') for x in xrange(256)]
ishex = [ isdigit(chr(x)) or (chr(x) >= 'a' and chr(x) <= 'f') or (chr(x) >= 'A' and chr(x) <= 'F') for x in range(256)]

def walkToEndOfCPPNumber(strn, startPos):
en = walkToEndOfNumber(strn, startPos)
if en == startPos or en == len(strn) or not isalpha(strn[en]):
return en
low = lower(strn[en])
low = strn[en].lower()

# handle floating point suffices
if low == 'f' or low == 'd':
Expand All @@ -493,17 +496,17 @@ def walkToEndOfCPPNumber(strn, startPos):
en += 1
if en == len(strn) or not isalpha(strn[en]):
return en
low = lower(strn[en])
low = strn[en].lower()

# handle integral suffices
if low == 'u':
en += 1
if en == len(strn):
return en
low = lower(strn[en])
low = strn[en].lower()
if low == 'l':
en += 1
if en < len(strn) and lower(strn[en]) == 'l':
if en < len(strn) and strn[en].lower() == 'l':
return en + 1
return en

Expand Down Expand Up @@ -595,7 +598,7 @@ def walkToEndOfNextScope(strn, startPos):# assumes no comments or spaces
parenDepth -= 1
endPos += 1
else:
print "no valid scope!: " + strn
print("no valid scope!: " + strn)
sys.exit(1)
return endPos

Expand Down Expand Up @@ -678,7 +681,7 @@ def stripComments(ourLines):
if(len(strings)):
buffer += strings + '\n'
walker = 0
placer = cStringIO.StringIO()
placer = StringIO()
inEscape = 0
if len(buffer):
while walker + 1 < len(buffer):
Expand Down Expand Up @@ -750,8 +753,8 @@ def stripComments(ourLines):
placer.write(buffer[walker])
buffer = placer.getvalue()
ourLines = buffer.split('\n')
ourLines = [ourLines[i].strip() for i in xrange(len(ourLines)) if ourLines[i] != None]
ourLines = [ourLines[i] for i in xrange(len(ourLines)) if len(ourLines[i]) > 0]
ourLines = [ourLines[i].strip() for i in range(len(ourLines)) if ourLines[i] != None]
ourLines = [ourLines[i] for i in range(len(ourLines)) if len(ourLines[i]) > 0]
return(ourLines)

def stripCommentsAndQuotes(ourLines):
Expand All @@ -762,7 +765,7 @@ def stripCommentsAndQuotes(ourLines):
if(len(strings)):
buffer += strings + '\n'
walker = 0
placer = cStringIO.StringIO()
placer = StringIO()
inEscape = 0
if len(buffer):
while walker + 1 < len(buffer):
Expand Down Expand Up @@ -830,8 +833,8 @@ def stripCommentsAndQuotes(ourLines):
placer.write(buffer[walker])
buffer = placer.getvalue()
ourLines = buffer.split('\n')
ourLines = [ourLines[i].strip() for i in xrange(len(ourLines)) if ourLines[i] != None]
ourLines = [ourLines[i] for i in xrange(len(ourLines)) if len(ourLines[i]) > 0]
ourLines = [ourLines[i].strip() for i in range(len(ourLines)) if ourLines[i] != None]
ourLines = [ourLines[i] for i in range(len(ourLines)) if len(ourLines[i]) > 0]
return(ourLines)


Expand All @@ -843,7 +846,7 @@ def stripMultilineComments(ourLines):
if(len(strings)):
buffer += strings + '\n'
walker = 0
placer = cStringIO.StringIO()
placer = StringIO()
inEscape = 0
if len(buffer):
while walker + 1 < len(buffer):
Expand Down Expand Up @@ -917,8 +920,8 @@ def stripMultilineComments(ourLines):
placer.write(buffer[walker])
buffer = placer.getvalue()
ourLines = buffer.split('\n')
ourLines = [ourLines[i].strip() for i in xrange(len(ourLines)) if ourLines[i] != None]
ourLines = [ourLines[i] for i in xrange(len(ourLines)) if len(ourLines[i]) > 0]
ourLines = [ourLines[i].strip() for i in range(len(ourLines)) if ourLines[i] != None]
ourLines = [ourLines[i] for i in range(len(ourLines)) if len(ourLines[i]) > 0]
return(ourLines)

def isCommentBlockDelimitingLine(line):
Expand Down Expand Up @@ -1007,7 +1010,7 @@ def getDoxyBlocksContainingTag(ourLines, tag):
def getClassesAndStructs(ourLines):
lines = stripComments(ourLines)
lines = [ line.strip() for line in lines if (line.strip().startswith('struct ') or line.strip().startswith('class ')) and not line.strip().endswith(';')]
for i in xrange(len(lines)):
for i in range(len(lines)):
if lines[i].startswith('class '):
lines[i] = lines[i][6:]
else:
Expand All @@ -1024,7 +1027,7 @@ def getClassesAndStructs(ourLines):

def extractStrings(ourLines, prep):
ourStrings = []
for i in xrange(len(ourLines)):
for i in range(len(ourLines)):
if '\'' in ourLines[i] or '"' in ourLines[i]:
walker = 0
lastStrEnd = 0
Expand Down Expand Up @@ -1099,12 +1102,12 @@ def getFilesFromDirectory(directory, suffix):
def writeTwoLists(afile, prefix, vars, joiner, RHSs, suffix):
if len(vars):
endStr = suffix + prefix
afile.write(prefix + endStr.join([(str(vars[i]) + joiner + str(RHSs[i])) for i in xrange(len(vars))]) + suffix)
afile.write(prefix + endStr.join([(str(vars[i]) + joiner + str(RHSs[i])) for i in range(len(vars))]) + suffix)

def writeOneList(afile, prefix, vars, suffix):
if len(vars):
endStr = suffix + prefix
afile.write(prefix + endStr.join([str(vars[i]) for i in xrange(len(vars))]) + suffix)
afile.write(prefix + endStr.join([str(vars[i]) for i in range(len(vars))]) + suffix)

def writeOneSet(afile, prefix, vars, suffix):
if len(vars):
Expand Down
Binary file removed scripts/code/CodeFileUtils.pyc
Binary file not shown.
Loading