3 /**************************************************************************
4 * Copyright 2017-2018 IoT.bzh
6 * author: Sebastien Douheret <sebastien@iot.bzh>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 **************************************************************************/
21 const fs = require('fs');
22 const process = require('process');
23 const execSync = require('child_process').execSync;
24 const path = require('path');
27 // Only used for debug purpose
28 const DEBUG = false || (process.argv.length > 2 && process.argv[2] == '-debug');
29 dbgPrint = function () {
30 if (DEBUG) console.log.apply(console, arguments);
34 envData = execSync(path.join(__dirname, '_env-init.sh -print'));
35 envData.toString().split('\n').forEach(e => envMap[e.split('=')[0]] = e.split('=')[1]);
41 // Get list of available SDKs
42 sdksDBFile = path.join(envMap["SDK_ROOT_DIR"], "sdks_latest.json")
44 // Fetch SDK Json database file when not existing
45 if (!fs.existsSync(sdksDBFile)) {
46 var data = execSync(path.join(__dirname, 'db-update ' + sdksDBFile), opts);
48 // Read SDK Json database file
49 var data = fs.readFileSync(sdksDBFile);
50 var sdks = JSON.parse(data);
52 // Force some default fields value
54 sdk.status = 'Not Installed';
57 dbgPrint('ERROR: ', err);
61 // Get list of installed SDKs
63 const cmd = 'find "${SDK_ROOT_DIR}" -maxdepth 4 -name "${SDK_ENV_SETUP_FILENAME}"';
64 var data = execSync(cmd, opts);
65 data.toString().split('\n').forEach(envFile => {
66 if (envFile == '') return;
68 dbgPrint('Processing ', envFile);
69 const profile = envFile.split('/')[3];
70 const version = envFile.split('/')[4];
71 const arch = envFile.split('/')[5];
72 const dir = path.dirname(envFile);
73 if (profile == '' || version == '' || arch == '' || dir == '') {
78 versionFile = path.join(path.dirname(envFile), 'version-*')
80 cmdVer = "[ -f " + versionFile + " ] && grep Timestamp " + versionFile + " |cut -d' ' -f2"
81 var data = execSync(cmdVer);
83 dbgPrint('IGNORING SDK ', dir);
84 dbgPrint(err.toString());
93 sdkDate = d.substring(0, 4) + "-" + d.substring(4, 6) + "-" + d.substring(6, 8)
94 sdkDate += " " + d.substring(8, 10) + ":" + d.substring(10, 12)
99 // Update sdk with local info when found
100 if (profile == sdk.profile && version == sdk.version && arch == sdk.arch) {
102 dbgPrint(" OK found, updating...");
104 sdk.status = 'Installed';
106 sdk.setupFile = envFile;
110 if (found == false) {
111 dbgPrint(" NOT found in database, adding it...");
113 name: profile + '-' + arch + '-' + version,
114 description: 'AGL SDK ' + arch + ' (version ' + version + ')',
130 dbgPrint('ERROR: ', err);
135 console.log(JSON.stringify(sdks));