Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Barnard-PL-Labs/tsl-api int…
Browse files Browse the repository at this point in the history
…o main
  • Loading branch information
santolucito committed Nov 16, 2022
2 parents 60392d3 + 633131e commit 17d5bc3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ ENV DEBIAN_FRONTEND noninteractive
# [START cloudrun_system_package_alpine]
# [START run_system_package_alpine]
#RUN apk --no-cache add graphviz ttf-ubuntu-font-family
RUN apt-get update -y && apt-get install -y \
RUN apt-get update -y && apt-get install -y\
nodejs npm \
wget git \
&& apt-get clean
# [END run_system_package_alpine]
# [END cloudrun_system_package_alpine]

RUN apt-get install libpcre3 libpcre3-dev -y
RUN wget -qO- https://get.haskellstack.org/ | sh
RUN git clone https://github.com/Barnard-PL-Labs/tsltools
RUN cd tsltools && make
Expand All @@ -40,7 +40,6 @@ RUN echo 'deb http://www.lrde.epita.fr/repo/debian/ stable/' >> /etc/apt/sources
RUN apt-get update
RUN apt-get install -y spot


# Copy application dependency manifests to the container image.
# A wildcard is used to ensure both package.json AND package-lock.json are copied.
# Copying this separately prevents re-running npm install on every code change.
Expand Down
39 changes: 39 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,23 @@ app.get('/tslsynth', (req, res) => {
}
}
});

app.get('/tslminrealizable', (req, res) => {
try {
const synthResult = createMinDiagram(req.query.tsl);
res.setHeader('Content-Type', 'text/plain');
res.setHeader('Cache-Control', 'public, max-age=86400');
res.send(synthResult);
} catch (err) {
console.error(`error: ${err.message}`);
const errDetails = (err.stderr || err.message).toString();
if (errDetails.includes('syntax')) {
res.status(400).send(`Bad Request: ${err.message}`);
} else {
res.status(500).send('Internal Server Error');
}
}
});
// [END run_system_package_handler]
// [END cloudrun_system_package_handler]

Expand All @@ -70,10 +87,32 @@ const createDiagram = (tsl, target) => {
cwd: "./tsltools",
input: tsl,
});

console.log("synthResult");
console.log(String(synthResult));

return synthResult;
};

const createMinDiagram = (tsl) => {
if (!tsl) {
throw new Error('syntax: no tsl spec provided');
}
try {
fs.writeFileSync('tsltools/tmp.tsl', tsl)
} catch (err) {
console.error(err)
}

const synthResult = execSync(`./tslminrealizable tmp.tsl -r /usr/src/app/tsltools/tlsfSynth_stdin.sh`, {
cwd: "./tsltools",
input: tsl,
});
console.log("synthResult");
console.log(String(synthResult));
return synthResult;
};

// [END run_system_package_exec]
// [END cloudrun_system_package_exec]

Expand Down

0 comments on commit 17d5bc3

Please sign in to comment.