remove stored build files

pull/3039/head
Aniket-Engg 2 years ago committed by Aniket
parent 0a62016935
commit 3df7d872a1
  1. 25
      libs/remix-core-plugin/src/lib/compiler-metadata.ts

@ -47,6 +47,20 @@ export class CompilerMetadata extends Plugin {
})
}
// Access each file in build-info, check the input sources
// If they are all same as in current compiled file and sources includes the path of compiled file, remove old build file
async removeStoredBuildInfo (currentInput, path, filePath) {
const allBuildFiles = await this.call('fileManager', 'fileList', this.joinPath(path, this.innerPath, 'build-info/'))
const currentInputFileNames = Object.keys(currentInput.sources)
for (const fileName of allBuildFiles) {
let fileContent = await this.call('fileManager', 'readFile', fileName)
fileContent = JSON.parse(fileContent)
const inputFiles = Object.keys(fileContent.input.sources)
const inputIntersection = currentInputFileNames.filter(element => !inputFiles.includes(element))
if (inputIntersection.length === 0 && inputFiles.includes(filePath)) await this.call('fileManager', 'remove', fileName)
}
}
async setBuildInfo (version, input, output, path, filePath) {
input = JSON.parse(input)
const solcLongVersion = version.replace('.Emscripten.clang', '')
@ -60,15 +74,18 @@ export class CompilerMetadata extends Plugin {
})
const id = createHash('md5').update(Buffer.from(json)).digest().toString('hex')
const buildFilename = this.joinPath(path, this.innerPath, 'build-info/' + id + '.json')
// If there are no file in buildInfoNames,it means compilation is running first time after loading Remix
if (!this.buildInfoNames[filePath]) {
// Check the existing build-info and delete all the previous build files for compiled file
await this.removeStoredBuildInfo(input, path, 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'))
} 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'))
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'))
}
}

Loading…
Cancel
Save