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

76 lines
1.8 KiB

'use strict'
var fs = require('fs')
var solc = require('solc/wrapper')
var soljson = require('../soljson')
var compiler = solc(soljson)
8 years ago
gatherCompilationResults(function (error, data) {
if (error) {
console.log(error)
process.exit(1)
} else {
replaceSolCompiler(data)
8 years ago
}
})
function gatherCompilationResults (callback) {
var compilationResult = {}
fs.readdir('./test-browser/tests', 'utf8', function (error, filenames) {
if (error) {
console.log(error)
process.exit(1)
} else {
filenames.map(function (item, i) {
var testDef = require('../test-browser/tests/' + item)
if ('@sources' in testDef) {
var source = testDef['@sources']()
var result = compile(source, 1)
compilationResult[result.key] = result
result = compile(source, 0)
compilationResult[result.key] = result
}
})
callback(null, compilationResult)
}
})
8 years ago
}
function compile (source, optimization) {
var missingInputs = []
8 years ago
var result = compiler.compile(source, optimization, function (path) {
missingInputs.push(path)
})
var key = optimization.toString()
8 years ago
for (var k in source.sources) {
key += k + source.sources[k]
8 years ago
}
key = key.replace(/(\t)|(\n)|( )/g, '')
8 years ago
return {
key: key,
source: source,
optimization: optimization,
missingInputs: missingInputs,
result: result
}
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
}
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
}