Skip to content

Commit 6165f10

Browse files
committed
Update README and Config.py for dune-built CodeHawk
1 parent 2cb7996 commit 6165f10

5 files changed

Lines changed: 44 additions & 53 deletions

File tree

README.md

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,22 @@ Sound Static Analysis of C for Memory Safety (Undefined Behavior)
44
### Quick start
55

66
The CodeHawk-C Analyzer consists of two parts:
7-
- A python front end (this repository) through which all user interaction
7+
- A Python front end (this repository) through which all user interaction
88
is performed, and
9-
- An ocaml abstract-interpretation engine that powers the analysis.
9+
- An OCaml abstract-interpretation engine that powers the analysis.
1010

11-
To use the CodeHawk-C Analyzer first clone or download the ocaml application
11+
To use the CodeHawk-C Analyzer first clone or download the OCaml application
1212
from
1313
```
1414
https://github.com/static-analysis-engineering/codehawk
1515
```
16-
and build according to the accompanying instructions given there.
17-
Then copy the following files from that build:
18-
```
19-
codehawk/CodeHawk/CHC/cchcil/parseFile
20-
codehawk/CodeHawk/CHC/cchcmdline/canalyzer
21-
```
22-
to the following location in this repository:
23-
```
24-
CodeHawk-C/chc/bin/linux/
25-
```
26-
or
27-
```
28-
CodeHawk-C/chc/bin/macOS
29-
```
30-
depending on the platform where the executables were built.
31-
Alternatively, you can edit the path to these two executables directly
32-
in chc/util/Config.py or chc/util/ConfigLocal.py, so there is no need
33-
to copy them or update them with each new version of the ocaml analyzer.
16+
and build according to the accompanying instructions given there (using `dune`).
17+
18+
If this repository is placed within, or next to, that directory,
19+
you should be ready to proceed. Otherwise, copy
20+
`chc/util/ConfigLocal.template` to `chc/util/ConfigLocal.py` in this
21+
repository, and edit the latter file to set `config.codehawkdir` to
22+
the location of the `codehawk` checkout.
3423

3524
Set the python path and path:
3625
```
@@ -47,8 +36,8 @@ which should show something like:
4736
Analyzer configuration:
4837
-----------------------
4938
platform : linux
50-
parser : /home/user/codehawk/CodeHawk/CHC/cchcil/parseFile (found)
51-
analyzer : /home/user/codehawk/CodeHawk/CHC/cchcmdline/canalyzer (found)
39+
parser : /home/user/codehawk/CodeHawk/_build/default/CHC/cchcil/cCHXParseFile.exe (found)
40+
analyzer : /home/user/codehawk/CodeHawk/_build/default/CHC/cchcmdline/cCHXCAnalyzer.exe (found)
5241
5342
summaries: /home/user/CodeHawk-C/chc/summaries/cchsummaries.jar (found)
5443
```

chc/bin/linux/README.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

chc/bin/macOS/README.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

chc/util/Config.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242

4343
class 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

chc/util/ConfigLocal.template

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ def getLocals(config: chc.util.Config.Config) -> None:
4343
'''Set local configuration variables here if they differ from the defaults in Config.py
4444

4545
Example :
46-
config.canalyzer = '/home/username/my-analyzer/canalyzer'
47-
config.cparser = '/home/username/my-parser/parseFile'
46+
config.codehawkdir = '/home/username/codehawk/'
4847
config.summaries = '/home/username/my-summaries/cchsummaries.jar'
49-
config.bear = '/home/username/bear-home/bear'
50-
config.libear = '/home/username/bear-home/libear.so'
5148
'''

0 commit comments

Comments
 (0)