UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

80 lines 4.4 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getStatsForSingleFile = getStatsForSingleFile; const features_1 = require("../common/features"); const fs_1 = __importDefault(require("fs")); const shell_1 = require("../../r-bridge/shell"); const statistics_file_1 = require("../../statistics/output/statistics-file"); const statistics_1 = require("../../statistics/statistics"); const cfg_1 = require("../../util/cfg/cfg"); const print_1 = require("../../core/print/print"); const _00_parse_1 = require("../../core/steps/all/core/00-parse"); const _10_normalize_1 = require("../../core/steps/all/core/10-normalize"); const _20_dataflow_1 = require("../../core/steps/all/core/20-dataflow"); const json_1 = require("../../util/json"); const log_1 = require("../../util/log"); const assert_1 = require("../../util/assert"); const time_1 = require("../../util/time"); const tar_1 = require("tar"); const ansi_1 = require("../../util/ansi"); function compressFolder(folder, target) { return (0, tar_1.create)({ gzip: true, file: target, portable: true, preservePaths: false }, [folder]).then(() => { // now, remove the folder fs_1.default.rmSync(folder, { recursive: true, force: true }); }, () => { console.log(`failed to compress ${folder}`); }).catch((e) => { console.error('Error during compression:', e); }); } async function getStatsForSingleFile(options) { if (options['no-ansi']) { log_1.log.info('disabling ansi colors'); (0, ansi_1.setFormatter)(ansi_1.voidFormatter); } let target = undefined; if (options.compress) { target = (0, features_1.retrieveArchiveName)(options['output-dir']); if (fs_1.default.existsSync(target)) { console.log(`Archive ${target} exists. Skip.`); process.exit(0); } } // assume correct const processedFeatures = new Set(options.features); const shell = new shell_1.RShell(); (0, statistics_file_1.initFileProvider)(options['output-dir']); await shell.obtainTmpDir(); const stats = await (0, statistics_1.extractUsageStatistics)(shell, () => { }, processedFeatures, (0, statistics_1.staticRequests)({ request: 'file', content: options.input }), options['root-dir']); // console.warn(`skipped ${stats.meta.failedRequests.length} requests due to errors (run with logs to get more info)`) if (stats.outputs.size === 1) { if (options['dump-json']) { const [, output] = [...stats.outputs.entries()][0]; const cfg = (0, cfg_1.extractCFG)(output.normalize, output.dataflow.graph); statistics_file_1.statisticsFileProvider.append('output-json', 'parse', await (0, print_1.printStepResult)(_00_parse_1.PARSE_WITH_R_SHELL_STEP, output.parse, 2 /* StepOutputFormat.Json */)); statistics_file_1.statisticsFileProvider.append('output-json', 'normalize', await (0, print_1.printStepResult)(_10_normalize_1.NORMALIZE, output.normalize, 2 /* StepOutputFormat.Json */)); statistics_file_1.statisticsFileProvider.append('output-json', 'dataflow', await (0, print_1.printStepResult)(_20_dataflow_1.STATIC_DATAFLOW, output.dataflow, 2 /* StepOutputFormat.Json */)); statistics_file_1.statisticsFileProvider.append('output-json', 'cfg', JSON.stringify(cfg, json_1.jsonReplacer)); } statistics_file_1.statisticsFileProvider.append('meta', 'stats', JSON.stringify({ ...stats.meta, file: options.input }, json_1.jsonReplacer)); statistics_file_1.statisticsFileProvider.append('meta', 'features', JSON.stringify(stats.features, json_1.jsonReplacer)); } else { log_1.log.error(`expected exactly one output vs. ${stats.outputs.size}, got: ${JSON.stringify([...stats.outputs.keys()], json_1.jsonReplacer, 2)}`); } if (options.compress) { (0, assert_1.guard)(target !== undefined, 'target must be defined given the compress option'); console.log(`[${(0, time_1.date2string)(new Date())}] Compressing ${options['output-dir']} to ${target}`); await compressFolder(options['output-dir'], target); } shell.close(); } //# sourceMappingURL=statistics-helper-core.js.map