-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild-annotations.js
126 lines (101 loc) · 3.95 KB
/
build-annotations.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
const
fs = require('fs').promises,
fsconstants = require('fs').constants,
ini = require('ini');
class RemoteAnnotations {
constructor(conanserverurl) {
this.conanserverurl = conanserverurl;
}
async readAnnotations(library, version, buildhash) {
try {
// eslint-disable-next-line no-undef
const response = await fetch(this.conanserverurl + `/annotations/${library}/${version}/${buildhash}`);
if (response.status !== 200) {
return {};
}
return await response.json();
} catch(err) {
return {
error: "error"
};
}
}
}
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`;
}
async writeAnnotations(library, version, buildhash, annotations) {
return fs.writeFile(this.getAnnotationsFilepath(library, version, buildhash), JSON.stringify(annotations), 'utf8');
}
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 {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 = [];
try {
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);
}
}
} catch (e) {
console.error(e);
}
return allAnnotations;
}
}
module.exports = {
BuildAnnotations,
RemoteAnnotations
};