remove previous build file

pull/5370/head
Aniket-Engg 2 years ago committed by Aniket
parent c04bdebf82
commit 2d15730093
  1. 18
      libs/remix-core-plugin/src/lib/compiler-metadata.ts

@ -13,10 +13,12 @@ const profile = {
export class CompilerMetadata extends Plugin { export class CompilerMetadata extends Plugin {
networks: string[] networks: string[]
innerPath: string innerPath: string
buildInfoNames: Record<string, string>
constructor () { constructor () {
super(profile) super(profile)
this.networks = ['VM:-', 'main:1', 'ropsten:3', 'rinkeby:4', 'kovan:42', 'goerli:5', 'Custom'] this.networks = ['VM:-', 'main:1', 'ropsten:3', 'rinkeby:4', 'kovan:42', 'goerli:5', 'Custom']
this.innerPath = 'artifacts' this.innerPath = 'artifacts'
this.buildInfoNames = {}
} }
_JSONFileName (path, contractName) { _JSONFileName (path, contractName) {
@ -33,7 +35,7 @@ export class CompilerMetadata extends Plugin {
if (!await this.call('settings', 'get', 'settings/generate-contract-metadata')) return if (!await this.call('settings', 'get', 'settings/generate-contract-metadata')) return
const compiler = new CompilerAbstract(languageVersion, data, source, input) const compiler = new CompilerAbstract(languageVersion, data, source, input)
const path = self._extractPathOf(source.target) const path = self._extractPathOf(source.target)
await this.setBuildInfo(version, input, data, path) await this.setBuildInfo(version, input, data, path, file)
compiler.visitContracts((contract) => { compiler.visitContracts((contract) => {
if (contract.file !== source.target) return if (contract.file !== source.target) return
(async () => { (async () => {
@ -45,7 +47,7 @@ export class CompilerMetadata extends Plugin {
}) })
} }
async setBuildInfo (version, input, output, path) { async setBuildInfo (version, input, output, path, filePath) {
input = JSON.parse(input) input = JSON.parse(input)
const solcLongVersion = version.replace('.Emscripten.clang', '') const solcLongVersion = version.replace('.Emscripten.clang', '')
const solcVersion = solcLongVersion.substring(0, solcLongVersion.indexOf('+commit')) const solcVersion = solcLongVersion.substring(0, solcLongVersion.indexOf('+commit'))
@ -58,8 +60,16 @@ export class CompilerMetadata extends Plugin {
}) })
const id = createHash('md5').update(Buffer.from(json)).digest().toString('hex') const id = createHash('md5').update(Buffer.from(json)).digest().toString('hex')
const buildFilename = this.joinPath(path, this.innerPath, 'build-info/' + id + '.json') const buildFilename = this.joinPath(path, this.innerPath, 'build-info/' + id + '.json')
const buildData = {id, _format: format, solcVersion, solcLongVersion, input, output} if (!this.buildInfoNames[filePath]) {
await this.call('fileManager', 'writeFile', buildFilename, JSON.stringify(buildData, null, '\t')) this.buildInfoNames[filePath] = buildFilename
const buildData = {id, _format: format, solcVersion, solcLongVersion, input, output}
await this.call('fileManager', 'writeFile', buildFilename, JSON.stringify(buildData, null, '\t'))
} else if (this.buildInfoNames[filePath] && this.buildInfoNames[filePath] !== buildFilename) {
await this.call('fileManager', 'remove', this.buildInfoNames[filePath])
this.buildInfoNames[filePath] = buildFilename
const buildData = {id, _format: format, solcVersion, solcLongVersion, input, output}
await this.call('fileManager', 'writeFile', buildFilename, JSON.stringify(buildData, null, '\t'))
}
} }
_extractPathOf (file) { _extractPathOf (file) {

Loading…
Cancel
Save