Merge pull request #4229 from ethereum/remaps

consider remappings while compilation
add_template_0
yann300 1 year ago committed by GitHub
commit e79bd99212
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      libs/remix-solidity/src/compiler/compiler-input.ts
  2. 15
      libs/remix-solidity/src/compiler/compiler.ts
  3. 4
      libs/remix-solidity/src/compiler/types.ts
  4. 1
      libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx
  5. 7
      libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts

@ -17,7 +17,8 @@ export default (sources: Source, opts: CompilerInputOptions): string => {
'': ['ast'],
'*': ['abi', 'metadata', 'devdoc', 'userdoc', 'storageLayout', 'evm.legacyAssembly', 'evm.bytecode', 'evm.deployedBytecode', 'evm.methodIdentifiers', 'evm.gasEstimates', 'evm.assembly']
}
}
},
remappings: opts.remappings || []
}
}
if (opts.evmVersion) {

@ -32,6 +32,7 @@ export class Compiler {
runs: 200,
evmVersion: null,
language: 'Solidity',
remappings: [],
compilationStartTime: null,
target: null,
useFileConfiguration: false,
@ -213,12 +214,11 @@ export class Compiler {
let input = ""
try {
if (source && source.sources) {
const { optimize, runs, evmVersion, language, useFileConfiguration, configFileContent } = this.state
const { optimize, runs, evmVersion, language, remappings, useFileConfiguration, configFileContent } = this.state
if (useFileConfiguration) {
input = compilerInputForConfigFile(source.sources, JSON.parse(configFileContent))
} else {
input = compilerInput(source.sources, { optimize, runs, evmVersion, language })
input = compilerInput(source.sources, { optimize, runs, evmVersion, language, remappings })
}
result = JSON.parse(remoteCompiler.compile(input, { import: missingInputsCallback }))
@ -331,15 +331,18 @@ export class Compiler {
this.state.compileJSON = (source: SourceWithTarget, timeStamp: number) => {
if (source && source.sources) {
const { optimize, runs, evmVersion, language, useFileConfiguration, configFileContent } = this.state
const { optimize, runs, evmVersion, language, remappings, useFileConfiguration, configFileContent } = this.state
jobs.push({ sources: source })
let input = ""
try {
if (useFileConfiguration) {
input = compilerInputForConfigFile(source.sources, JSON.parse(configFileContent))
const compilerInput = JSON.parse(configFileContent)
if (compilerInput.settings.remappings?.length) compilerInput.settings.remappings.push(...remappings)
else compilerInput.settings.remappings = remappings
input = compilerInputForConfigFile(source.sources, compilerInput)
} else {
input = compilerInput(source.sources, { optimize, runs, evmVersion, language })
input = compilerInput(source.sources, { optimize, runs, evmVersion, language, remappings })
}
} catch (exception) {
this.onCompilationFinished({ error: { formattedMessage: exception.message } }, [], source, "", this.state.currentVersion)

@ -147,7 +147,8 @@ export interface CompilerInputOptions {
[fileName: string]: Record<string, string>
},
evmVersion?: EVMVersion,
language?: Language
language?: Language,
remappings?: string[]
}
export type EVMVersion = 'homestead' | 'tangerineWhistle' | 'spuriousDragon' | 'byzantium' | 'constantinople' | 'petersburg' | 'istanbul' | 'berlin' | 'london' | 'paris' | null
@ -168,6 +169,7 @@ export interface CompilerState {
runs: number
evmVersion: EVMVersion| null,
language: Language,
remappings: string[]
compilationStartTime: number| null,
target: string | null,
useFileConfiguration: boolean,

@ -59,6 +59,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
compiledFileName: '',
includeNightlies: false,
language: 'Solidity',
remappings: [],
evmVersion: '',
createFileOnce: true
})

@ -106,10 +106,15 @@ export class CompileTabLogic {
compileFile (target) {
if (!target) throw new Error('No target provided for compiliation')
return new Promise((resolve, reject) => {
this.api.readFile(target).then((content) => {
this.api.readFile(target).then(async(content) => {
const sources = { [target]: { content } }
this.event.emit('removeAnnotations')
this.event.emit('startingCompilation')
if(await this.api.fileExists('remappings.txt')) {
this.api.readFile('remappings.txt').then( remappings => {
this.compiler.set('remappings', remappings.split('\n'))
})
}
if (this.configFilePath) {
this.api.readFile(this.configFilePath).then( contentConfig => {
this.compiler.set('configFileContent', contentConfig)

Loading…
Cancel
Save