15 lines
625 B
Python
15 lines
625 B
Python
"""Execute actual Enforce policy bodies as C++, without claiming engine coverage."""
|
|
from pathlib import Path
|
|
import subprocess,tempfile,re
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
def body(path,signature):
|
|
s=path.read_text();a=s.index(signature);b=s.index('{',a);i=b+1;depth=1
|
|
while depth:
|
|
depth+=(s[i]=='{')-(s[i]=='}');i+=1
|
|
return s[a:i]
|
|
def run(code):
|
|
with tempfile.TemporaryDirectory(prefix='err-policy-') as tmp:
|
|
p=Path(tmp);(p/'check.cpp').write_text(code)
|
|
subprocess.run(['g++','-std=c++17','-Wall','-Werror',str(p/'check.cpp'),'-o',str(p/'check')],check=True)
|
|
subprocess.run([str(p/'check')],check=True)
|