remix-project mirror
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
remix-project/ci/makeMockCompiler.js

73 lines
2.1 KiB

'use strict'
var fs = require('fs')
var compiler = require('solc')
8 years ago
var compilerInput = require('remix-solidty').CompilerInput
7 years ago
var compilationResult = {}
gatherCompilationResults('./test-browser/tests/', compilationResult)
gatherCompilationResults('./test-browser/tests/units/', compilationResult)
replaceSolCompiler(compilationResult)
7 years ago
7 years ago
function gatherCompilationResults (dir, compilationResult, callback) {
var filenames = fs.readdirSync(dir, 'utf8')
filenames.map(function (item, i) {
if (item.endsWith('.js')) {
var testDef = require('.' + dir + item)
if ('@sources' in testDef) {
var sources = testDef['@sources']()
for (var files in sources) {
compile(sources[files], true, function (result) {
compilationResult[result.key] = result
})
compile(sources[files], false, function (result) {
compilationResult[result.key] = result
})
}
7 years ago
}
}
})
7 years ago
return compilationResult
8 years ago
}
function compile (source, optimization, addCompilationResult) {
var missingInputs = []
try {
7 years ago
var input = compilerInput(source, {optimize: optimization})
var result = compiler.compileStandardWrapper(input, function (path) {
missingInputs.push(path)
})
7 years ago
input = input.replace(/(\t)|(\n)|(\\n)|( )/g, '')
} catch (e) {
console.log(e)
}
var ret = {
7 years ago
key: input,
8 years ago
source: source,
optimization: optimization,
missingInputs: missingInputs,
result: result
}
addCompilationResult(ret)
8 years ago
}
function replaceSolCompiler (results) {
fs.readFile('./test-browser/mockcompiler/compiler.js', 'utf8', function (error, data) {
if (error) {
console.log(error)
process.exit(1)
return
8 years ago
}
console.log(compiler.version())
8 years ago
data = data + '\n\nvar mockCompilerVersion = \'' + compiler.version() + '\''
data = data + '\n\nvar mockData = ' + JSON.stringify(results) + ';\n'
8 years ago
fs.writeFile('./soljson.js', data, 'utf8', function (error) {
if (error) {
console.log(error)
process.exit(1)
return
8 years ago
}
})
})
8 years ago
}