Skip to content

Commit

Permalink
fix act code-block parsing and report under a build_hash
Browse files Browse the repository at this point in the history
  • Loading branch information
mhhf committed May 4, 2019
1 parent 7ac2dc6 commit f131e00
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 29 deletions.
2 changes: 1 addition & 1 deletion lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const getActs = str => {
const raw_config = marked.lexer(str)

const acts_str = raw_config
.filter(e => e.type === "code")
.filter(e => e.type === "code" && e.lang == "act")
.map(e => e.text)
.join("\n\n")

Expand Down
38 changes: 37 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const fs = require("fs");
const path = require("path");
const locale = require("./locale.js");
const keccak = require("keccak");
const { execSync } = require('child_process');
const sha3 = function (str) {
return keccak('keccak256')
.update(str)
Expand Down Expand Up @@ -65,6 +66,38 @@ const toK = str => str
.replace(/uint\(/g, "#unsigned(")
.replace(/bool\(/g, "bool2Word(")

const getKlabHEAD = () => {
return execSync(`git rev-parse HEAD`, {
cwd: path.join(__dirname, '..'),
encoding: 'utf8'
});
}

const getProjectHEAD = () => {
var project_HEAD = "";

if(testPath('.git')) {
project_HEAD = execSync(`git rev-parse HEAD`, {
encoding: 'utf8'
}).trim();
}

return project_HEAD;
}

const getBuildId = () => {

const klab_HEAD = getKlabHEAD();
const project_HEAD = getProjectHEAD();

const build_hash = sha3(JSON.stringify({
project_HEAD, // e.g. current k-dss git HEAD
klab_HEAD, // e.g. klab master HEAD
})).slice(0, 20);

return build_hash;
}


module.exports = {
ensureDirs,
Expand All @@ -76,5 +109,8 @@ module.exports = {
sha3,
warn,
mapInterface,
toK
toK,
getBuildId,
getKlabHEAD,
getProjectHEAD
};
5 changes: 3 additions & 2 deletions libexec/klab-prove-all
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ if [ "$PNAME" == "null" ]; then PNAME=""; fi
export PNAME

if [ -d ".git" ]; then
export commit_hash=$(git rev-parse HEAD)
export build_hash=$(klab get-build-id)
if [ -n "$KLAB_REPORT_DIR" ]; then
export KLAB_REPORT_NAME_DIR=$KLAB_REPORT_DIR/$PNAME
export KLAB_REPORT_PROJECT_DIR=$KLAB_REPORT_DIR/$PNAME/$commit_hash
export KLAB_REPORT_PROJECT_DIR=$KLAB_REPORT_DIR/$PNAME/$build_hash
mkdir -p "$KLAB_REPORT_PROJECT_DIR"
if [ -n "$PNAME" ]; then
klab setup-ci-project "$PNAME"
Expand Down Expand Up @@ -127,6 +127,7 @@ do_proof () {
cp "$KLAB_OUT/log/boot_${hash}.json" "$KLAB_WEBPROOF_DIR"
fi;
fi;

# cleanup dumped data
rm -fdr "$KLAB_OUT/data/${hash}_blobs"
rm -fdr "$KLAB_OUT/data/${hash}.log"
Expand Down
49 changes: 24 additions & 25 deletions libexec/klab-report
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ const {
render,
warn,
ensureDir,
sha3
sha3,
getBuildId,
getKlabHEAD,
getProjectHEAD
} = require("../lib/util.js")
const fs = require("fs");
const KLAB_OUT = process.env.KLAB_OUT || "out";
Expand All @@ -28,11 +31,8 @@ const EVM_SEMANTICS_VERSION = execSync(`git rev-parse HEAD`, {
cwd: KLAB_EVMS_PATH,
encoding: 'utf8'
});
const klab_HEAD = execSync(`git rev-parse HEAD`, {
cwd: path.join(__dirname, '..'),
encoding: 'utf8'
});
// const out = JSON.parse(read(path.join(KLAB_OUT, "out.json")));
const klab_HEAD = getKlabHEAD()
const project_HEAD = getProjectHEAD();
const config_json = JSON.parse(read("./config.json"));

const h = n => s => `<${Array.isArray(n) ? n.join(' ') : n}>${Array.isArray(s) && s.join('') || s}</${Array.isArray(n) ? n[0] : n}>`
Expand All @@ -46,12 +46,8 @@ const codespan = h(["span", 'class="codespan"'])
// const textinput = h(["input", 'type="text"'])


var project_HEAD = '';
if(testPath('.git')) {
project_HEAD = execSync(`git rev-parse HEAD`, {
encoding: 'utf8'
}).trim();
}
const build_hash = getBuildId();



const config = Config(config_json);
Expand All @@ -63,11 +59,6 @@ const raw_md_config = read(config_path)
const title = path.basename(config_path, ".md");
const raw_rules = rule_paths.map(p => read(p))
const rule_hashes = raw_rules.map(str => sha3(str).slice(0, 40))
const rules = marked
.lexer(raw_rules.join("\n\n"))
.filter(block => block.type === "code")
.map(block => block.text)
.join("\n\n")
const tokens = marked.lexer(raw_md_config)
// const act2specs = Object.keys(out)
// .reduce((a, key) => ({...a, [out[key].act]: [...(a[out[key].act] || []), key]}), {})
Expand Down Expand Up @@ -247,7 +238,7 @@ const cleanupCode = act_obj => {
.join("\n\n")

const behaviour_title = `behaviour ${act_obj.name} of ${act_obj.subject}`
const iface_args = act_obj.interface.map(i => i[0] + " " + i[1]).join(", ");
const iface_args = (act_obj.interface || []).map(i => i[0] + " " + i[1]).join(", ");
const interface = `interface ${act_obj.fname}(${iface_args})`;
var iff = "";
if(act_obj.iff_orig) {
Expand Down Expand Up @@ -301,10 +292,18 @@ const cleanupCode = act_obj => {


const parsed_tokens = tokens
.map(t => t.type == 'code'
? {type: 'code', obj: parseAct({})(t.text, true), text: t.text}
: t
);
.map(t => {
if(t.type == 'code' && t.lang === "act") {
return {
type: 'code',
lang: "act",
obj: parseAct({})(t.text, true),
text: t.text
};
} else {
return t;
}
});

const genCoverageReport = (proofs) => {

Expand Down Expand Up @@ -377,7 +376,7 @@ const stats = table(
)

const proofs = parsed_tokens
.filter(o => o.type == 'code')
.filter(o => o.type == 'code' && o.lang === "act")
.map(o => {
const cases = getCases(o.obj);
const contract_name = config.implementations[o.obj.subject];
Expand All @@ -400,7 +399,7 @@ const enriched_tokens = [{
text: `<div id="stats">${stats}</div><div id="coverage">${genCoverageReport(proofs)}</div>`
}].concat(parsed_tokens
.reduce((a, t) => {
return a.concat(t.type == "code" ? [{...t, type: "html", text: cleanupCode(t.obj)}, getBadges(t.obj)] : t)
return a.concat(t.type == "code" && t.lang === "act" ? [{...t, type: "html", text: cleanupCode(t.obj)}, getBadges(t.obj)] : t)
}, []))
enriched_tokens.links = tokens.links;

Expand All @@ -416,7 +415,7 @@ ensureDir(path.join(KLAB_OUT, 'report'))
fs.writeFileSync(path.join(KLAB_OUT, 'report', 'index.html'), htmlString);

const json_report = {
[project_HEAD]: {
[build_hash]: {
date: new Date(),
proofs
},
Expand Down

0 comments on commit f131e00

Please sign in to comment.