2010/8/11 Alexander Neundorf <neund...@kde.org>:
> On Tuesday 10 August 2010, Brad King wrote:
>> On 08/10/2010 05:14 PM, Alexander Neundorf wrote:
>> > I think it is still true for most find-modules, I think there are only a
>> > few exceptions, mostly Boost and Subversion.
>> > Checking... ok, also PostgreSQL, LibArchive (they are both new, right ?),
>> > ImageMagick and Java set the exact-case _FOUND variables.
>> > All others (more then 100 ?) use the UPPERCASE_FOUND.
>> >
>> > No matter which version I personally like better, I really do think that
>> > the big majority uses UPPERCASE_CASE found, and now declaring that
>> > ExactCase_FOUND is the standard would be wrong.
>>
>> I think the subversion patch in question is a step backwards.
>> Somehow we need to move toward the Right Thing.  At least the
>> documented FOO_FOUND variable should match the case of the
>> rest of the Foo_XXX variables in the same module.  This is why
>> I think the fphsa should just set both,
>
> Well, I still think the UPPERCASE_ prefix also has it advantages, I don't have
> to remember the exact case of the module (was it FindLibXml2 or FindLibXML2
> or Findlibxml2 or FindLibxml2, the variables are all just LIBXML_SOMETHING).
> It also makes them look more "consistent".

The simplicity argument is a good one.
I was in favor of ExactCase because I found it more "coherent"
but I admit UPPERCASE is "easier to remember".

I think the strongest argument is the one from Alan:

" I don't care what standard you follow so long as it is not ambiguous like the
  present standard in readme.txt AND enforced (with appropriate test
  scripts) in all the Find modules distributed with CMake."

> But if the majority here thinks ExactCase is better then ok.

So in the end I would say "I don't care" but let's do it for good:

 1) Chose between UPPERCASE and ExactCase

 2) Update FPHSA **and** Module/readme.txt accordingly

 3) Review existing Modules and set-up "compatibility" missing vars
     in them if needed.

You'll find attached a python script which does a "raw" check
on any file given as argument which would help for 3).

currently
checkModules.py <prefix>/share/cmake-2.8/Modules/*

gives:
Checked <130> files, exact=63, allUp=55, mismatch=12

* exact       means ExactCase is used (including those whose name is
all upper case)
* allUp        means UPPERCASE is used
* mismatch means neither those two.

there may be false positives because I do a raw regular expression match.

-- 
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
#!/usr/bin/env python

import os
import getopt, sys
import re

def usage():
    print "Usage:\n %s [--verbose] [--help] <files>" % os.path.basename(sys.argv[0])

try:
    opts, args = getopt.getopt(sys.argv[1:], "vh", ["verbose","help"])
except getopt.GetoptError, err:
    print >> sys.stderr, "opt = %s, msg = %s" % (err.opt,err.msg)
    usage()
    sys.exit(2)

def getModuleNameFromFile(f):
    (d,fn)=os.path.split(f)
    (fn,ext) = fn.split(".")
    fn = fn.replace("Find","",1)
    return fn

def buildRegularExpressionsFromModuleName(m):
    restring = ""
    for c in m:
        restring = restring + "["+c.lower()+c.upper()+"]"
    restring = ".*"+restring + "_.*"
    exactRe  = re.compile(m)
    approxRe = re.compile(restring)
    allUpRe  = re.compile(m.upper())
    return (exactRe,approxRe,allUpRe)
        
class CheckedFile(object):
    def __init__(self,exact,exactLine,allUp,allUpLine):
        self.exact     = exact
        self.exactLine = exactLine
        self.allUp     = allUp
        self.allUpLine = allUpLine

def checkOneFile(f):
    fn = getModuleNameFromFile(f)
    (exactRe,approxRe,allUpRe) = buildRegularExpressionsFromModuleName(fn)
    of = open(f,"r")    
    linenum=0
    retvalExact=True
    exactnumline=0
    retvalAllUp=True
    allupnumline=0
    for line in of:        
        linenum = linenum + 1
        line = line.strip()
        if line.startswith("#"):
            continue
        if approxRe.search(line) and not exactRe.search(line):
            exactnumline=linenum
            retvalExact = False
        if approxRe.search(line) and not allUpRe.search(line):
            allupnumline=linenum
            retvalAllUp = False
        if (not retvalAllUp) or (not retvalExact):
            break
    of.close()
    checkedFile = CheckedFile(retvalExact,exactnumline,retvalAllUp,allupnumline)
    return checkedFile

# default value
verbose=False

for o, a in opts:
    if o in ("-v", "--verbose"):
        verbose=True
    if o in ("-h", "--help"):
        usage()
        sys.exit(0)

# takes only files argument (no dir)
# whose name is "Find<whatever>.cmake"
onlyFindFiles = list()
for f in args:
    if not os.path.isdir(f):
        (d,fn)=os.path.split(f)
        if (fn.endswith(".cmake") and fn.startswith("Find")):
            onlyFindFiles.append(f)

nbFile=0
nbExact=0
nbAllUp=0
nbMismatch=0
for f in onlyFindFiles:   
    cf=checkOneFile(f) 
    nbFile = nbFile + 1
    if cf.exact:
        print f, "checked OK : exact match"
        nbExact = nbExact + 1
    elif cf.allUp:
        print f, "checked OK  but ALLUP match"
        nbAllUp = nbAllUp + 1
    else:        
        print f, "checked : has module name case mismatch see lines (%d,%d)" % (cf.exactLine,cf.allUpLine)
        nbMismatch = nbMismatch + 1

print "Checked <%d> files, exact=%d, allUp=%d, mismatch=%d" % (nbFile,nbExact,nbAllUp,nbMismatch)

_______________________________________________
cmake-developers mailing list
cmake-developers@cmake.org
http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers

Reply via email to