Skip to content

Commit

Permalink
All annotations (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
partouf authored Jun 21, 2024
1 parent a8853e2 commit 0cd9ec0
Show file tree
Hide file tree
Showing 6 changed files with 4,741 additions and 554 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ jobs:

strategy:
matrix:
node-version: [12.x, 14.x]
node-version: [16.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm run lint
- run: |
npm i
npm run lint
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
# conanproxy

Nodejs proxy in front of conanserver

## Dependencies

See https://github.com/compiler-explorer/infra/blob/main/setup-conan.sh

* nodejs 16 or higher
* python3
* sqlite3
73 changes: 69 additions & 4 deletions build-annotations.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
const
fs = require('fs').promises,
fsconstants = require('fs').constants;
fsconstants = require('fs').constants,
ini = require('ini');

class BuildAnnotations {
constructor(conanserverroot) {
this.conanserverroot = conanserverroot;
}

getPackageRootPath(library, version) {
return `${this.conanserverroot}/data/${library}/${version}/${library}/${version}/0/package`;
}

getConanInfoFilepath(library, version, buildhash) {
return `${this.conanserverroot}/data/${library}/${version}/${library}/${version}/0/package/${buildhash}/0/conaninfo.txt`;
}

getConanManifestFilepath(library, version, buildhash) {
return `${this.conanserverroot}/data/${library}/${version}/${library}/${version}/0/package/${buildhash}/0/conanmanifest.txt`;
}

getAnnotationsFilepath(library, version, buildhash) {
return `${this.conanserverroot}/data/${library}/${version}/${library}/${version}/0/package/${buildhash}/annotations.json`;
}
Expand All @@ -15,17 +28,69 @@ class BuildAnnotations {
return fs.writeFile(this.getAnnotationsFilepath(library, version, buildhash), JSON.stringify(annotations), 'utf8');
}

async readAnnotations(library, version, buildhash) {
const filepath = this.getAnnotationsFilepath(library, version, buildhash);
async readAnnotationFromFile(filepath) {
try {
await fs.access(filepath, fsconstants.R_OK | fsconstants.W_OK);

const data = await fs.readFile(filepath, 'utf8');
return JSON.parse(data);
} catch(e) {
return {};
return {error: e.message};
}
}

async readAnnotations(library, version, buildhash) {
const filepath = this.getAnnotationsFilepath(library, version, buildhash);
return await this.readAnnotationFromFile(filepath);
}

async readConanInfoFromFile(filepath) {
try {
await fs.access(filepath, fsconstants.R_OK | fsconstants.W_OK);

const data = await fs.readFile(filepath, 'utf8');

const content = ini.parse(data);

return {
arch: content.settings['arch'],
compilerId: content.settings['compiler.version'],
compilerType: content.settings['compiler'],
libcxx: content.settings['compiler.libcxx'],
os: content.settings['os']
};
} catch (e) {
return {
error: e.message,
};
}
}

async readAllAnnotations(library, version) {
const rootpath = this.getPackageRootPath(library, version);

const allAnnotations = [];

const dir = await fs.opendir(rootpath);
for await (const dirent of dir) {
if (dirent.isDirectory()) {
const buildhash = dirent.name;

const annotationFilepath = this.getAnnotationsFilepath(library, version, buildhash);
const infoFilepath = this.getConanInfoFilepath(library, version, buildhash);

const details = {
buildhash: buildhash,
annotation: await this.readAnnotationFromFile(annotationFilepath),
buildinfo: await this.readConanInfoFromFile(infoFilepath),
};

allAnnotations.push(details);
}
}

return allAnnotations;
}
}

module.exports = {
Expand Down
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const
{ BuildAnnotations } = require('./build-annotations'),
{ BuildLogging } = require('./build-logging'),
express = require('express'),
expressjwt = require('express-jwt'),
{ expressjwt } = require('express-jwt'),
jwt = require('jsonwebtoken'),
cors = require('cors'),
httpProxy = require('http-proxy'),
Expand Down Expand Up @@ -236,7 +236,7 @@ async function refreshConanLibraries(forceall) {
if (!ceLib) {
ceLib = _.find(allRustLibrariesAndVersions, (lib) => lib.id === libraryId);
if (ceLib) {
language = 'rust'
language = 'rust';
} else {
ceLib = _.find(allFortranLibrariesAndVersions, (lib) => lib.id === libraryId);
if (ceLib) language = 'fortran';
Expand Down Expand Up @@ -455,6 +455,10 @@ function main() {
const data = await annotations.readAnnotations(req.params.libraryid, req.params.version, req.params.buildhash);
res.send(data);
})
.get('/annotations/:libraryid/:version', expireshourly, async (req, res) => {
const data = await annotations.readAllAnnotations(req.params.libraryid, req.params.version);
res.send(data);
})
.post('/annotations/:libraryid/:version/:buildhash', nocache, async (req, res) => {
const data = req.body;
try {
Expand Down
Loading

0 comments on commit 0cd9ec0

Please sign in to comment.