3030
3131import os
3232
33- from typing import Any , Dict , List
33+ from typing import Any , Dict , List , Optional
3434
3535localconfig = False
3636
4343class Config ():
4444
4545 def __init__ (self ) -> None :
46+ self .codehawkdir : Optional [str ] = None
47+
48+ # initial personalization, in particular for self.codehawkdir
49+ if localconfig :
50+ ConfigLocal .getLocals (self )
51+
4652 # platform settings
4753 if os .uname ()[0 ] == 'Linux' :
4854 self .platform = 'linux'
@@ -55,21 +61,35 @@ def __init__(self) -> None:
5561 self .rootdir = os .path .dirname (self .chbdir )
5662 self .testsdir = os .path .join (self .rootdir , "tests" )
5763 self .projects = os .path .join (self .testsdir , "projects.json" )
58- self .bindir = os .path .join (self .chbdir , "bin" )
59- self .binariesdir = os .path .join (self .bindir , "binaries" )
6064 self .summariesdir = os .path .join (self .chbdir , "summaries" )
6165 self .summaries = os .path .join (self .summariesdir , "bchsummaries.jar" )
6266 self .stdchheader = os .path .join (self .summariesdir , "bch_header.c" )
6367
64- # analyzer location
65- if self .platform == 'linux' :
66- self .linuxdir = os .path .join (self .binariesdir , "linux" )
67- self .chx86_analyze = os .path .join (self .linuxdir , "chx86_analyze" )
68- self .cparser = os .path .join (self .linuxdir , "parseFile" )
69-
70- elif self .platform == "macOS" :
71- self .macOSdir = os .path .join (self .binariesdir , "macOS" )
72- self .chx86_analyze = os .path .join (self .macOSdir , "chx86_analyze" )
68+ if self .codehawkdir is None :
69+ # CodeHawk directory -- assumption is it will be either the
70+ # parent directory of the rootdir, or a sibling in the parent.
71+ def looks_like_codehawk (path : str ) -> bool :
72+ chb = os .path .join (path , "CodeHawk" , "CHB" )
73+ chc = os .path .join (path , "CodeHawk" , "CHC" )
74+ return os .path .isdir (chb ) and os .path .isdir (chc )
75+ topparent = os .path .dirname (self .rootdir )
76+ alts = [topparent ,
77+ os .path .join (topparent , "codehawk" ),
78+ os .path .join (topparent , "CodeHawk" )]
79+ viable_alts = [alt for alt in alts if looks_like_codehawk (alt )]
80+ if viable_alts :
81+ self .codehawkdir = viable_alts [0 ]
82+
83+ ## analyzer executables
84+ if self .codehawkdir is not None :
85+ # Look for non-installed binaries by default
86+ self .cparser = os .path .join (self .codehawkdir , "CodeHawk" ,
87+ "_build" , "default" , "CHC" , "cchcil" , "cCHXParseFile.exe" )
88+ self .chx86_analyze = os .path .join (self .codehawkdir , "CodeHawk" ,
89+ "_build" , "default" , "CHB" , "bchcmdline" , "bCHXBinaryAnalyzer.exe" )
90+ else :
91+ self .cparser = "<no codehawkdir!>"
92+ self .chx86_analyze = "<no codehawkdir!>"
7393
7494 # instruction support
7595 self .armdir = os .path .join (self .chbdir , "arm" )
0 commit comments