4242
4343class Config (object ):
4444 def __init__ (self ) -> None :
45+ self .codehawkdir : Optional [str ] = None
46+
47+ # initial personalization, in particular for self.codehawkdir
48+ if localconfig :
49+ ConfigLocal .getLocals (self )
50+
4551 # platform settings
4652 if os .uname ()[0 ] == "Linux" :
4753 self .platform = "linux"
@@ -51,20 +57,33 @@ def __init__(self) -> None:
5157 # general settings
5258 self .utildir = os .path .dirname (os .path .abspath (__file__ ))
5359 self .rootdir = os .path .dirname (self .utildir )
54- self .bindir = os .path .join (self .rootdir , "bin" )
5560 self .topdir = os .path .dirname (self .rootdir )
5661 self .testdir = os .path .join (self .topdir , "tests" )
5762
58- # parser and analyzer executables
59- if self .platform == "linux" :
60- self .linuxdir = os .path .join (self .bindir , "linux" )
61- self .cparser = os .path .join (self .linuxdir , "parseFile" )
62- self .canalyzer = os .path .join (self .linuxdir , "canalyzer" )
63-
64- if self .platform == "macOS" :
65- self .macOSdir = os .path .join (self .bindir , "macOS" )
66- self .cparser = os .path .join (self .macOSdir , "parseFile" )
67- self .canalyzer = os .path .join (self .macOSdir , "canalyzer" )
63+ if self .codehawkdir is None :
64+ # CodeHawk directory -- assumption is it will be either the
65+ # parent directory of the rootdir, or a sibling in the parent.
66+ def looks_like_codehawk (path : str ) -> bool :
67+ chb = os .path .join (path , "CodeHawk" , "CHB" )
68+ chc = os .path .join (path , "CodeHawk" , "CHC" )
69+ return os .path .isdir (chb ) and os .path .isdir (chc )
70+ topparent = os .path .dirname (self .topdir )
71+ alts = [topparent ,
72+ os .path .join (topparent , "codehawk" ),
73+ os .path .join (topparent , "CodeHawk" )]
74+ viable_alts = [alt for alt in alts if looks_like_codehawk (alt )]
75+ self .codehawkdir = (viable_alts + [None ])[0 ]
76+
77+ ## parser and analyzer executables
78+ if self .codehawkdir is not None :
79+ # Look for non-installed binaries by default
80+ self .cparser = os .path .join (self .codehawkdir , "CodeHawk" ,
81+ "_build" , "default" , "CHC" , "cchcil" , "cCHXParseFile.exe" )
82+ self .canalyzer = os .path .join (self .codehawkdir , "CodeHawk" ,
83+ "_build" , "default" , "CHC" , "cchcmdline" , "cCHXCAnalyzer.exe" )
84+ else :
85+ self .cparser = "<no codehawkdir!>"
86+ self .canalyzer = "<no codehawkdir!>"
6887
6988 self .chc_gui : Optional [str ] = None
7089
@@ -80,7 +99,7 @@ def __init__(self) -> None:
8099 self .name_separator = ":"
81100 self .targets : Dict [str , str ] = {}
82101
83- # personalization
102+ # personalization: ConfigLocal takes precedence over options above
84103 if localconfig :
85104 ConfigLocal .getLocals (self )
86105
0 commit comments