passed config file to compiler

pull/2249/head
lianahus 3 years ago committed by yann300
parent a311dbcac7
commit aa6a348c0e
  1. 14
      apps/solidity-compiler/src/app/compiler.ts
  2. 24
      libs/remix-solidity/src/compiler/compiler.ts
  3. 2
      libs/remix-solidity/src/compiler/types.ts
  4. 29
      libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx
  5. 16
      libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts

@ -19,18 +19,14 @@ const profile = {
methods: ['getCompilationResult', 'compile', 'compileWithParameters', 'setCompilerConfig', 'compileFile', 'getCompilerState']
}
const defaultAppParameters = {
hideWarnings: false,
autoCompile: false,
includeNightlies: false
}
const defaultCompilerParameters = {
runs: '200',
optimize: false,
version: 'soljson-v0.8.7+commit.e28d00a7',
evmVersion: null, // compiler default
language: 'Solidity'
language: 'Solidity',
useFileConfiguration: false,
configFileContent: ''
}
export class CompilerClientApi extends CompilerApiMixin(PluginClient) implements ICompilerApi {
constructor () {
@ -48,7 +44,9 @@ export class CompilerClientApi extends CompilerApiMixin(PluginClient) implements
optimize: localStorage.getItem('optimize') === 'true',
version: localStorage.getItem('version') || defaultCompilerParameters.version,
evmVersion: localStorage.getItem('evmVersion') || defaultCompilerParameters.evmVersion, // default
language: localStorage.getItem('language') || defaultCompilerParameters.language
language: localStorage.getItem('language') || defaultCompilerParameters.language,
useFileConfiguration: localStorage.getItem('useFileConfiguration') || defaultCompilerParameters.useFileConfiguration,
configFileContent: localStorage.getItem('configFileContent') || defaultCompilerParameters.configFileContent
}
return params
}

@ -31,6 +31,8 @@ export class Compiler {
language: 'Solidity',
compilationStartTime: null,
target: null,
useFileConfiguration: false,
configFileContent: '',
lastCompilationResult: {
data: null,
source: null
@ -115,7 +117,13 @@ export class Compiler {
try {
if (source && source.sources) {
const { optimize, runs, evmVersion, language } = this.state
input = compilerInput(source.sources, { optimize, runs, evmVersion, language })
let params = { optimize, runs, evmVersion, language }
if (this.state.useFileConfiguration) {
params = JSON.parse(this.state.configFileContent)
}
input = compilerInput(source.sources, params)
result = JSON.parse(compiler.compile(input, { import: missingInputsCallback }))
}
} catch (exception) {
@ -186,8 +194,13 @@ export class Compiler {
let input: string
try {
if (source && source.sources) {
const { optimize, runs, evmVersion, language } = this.state
input = compilerInput(source.sources, { optimize, runs, evmVersion, language })
const { optimize, runs, evmVersion, language, useFileConfiguration, configFileContent } = this.state
let params = { optimize, runs, evmVersion, language }
if (useFileConfiguration) {
params = JSON.parse(configFileContent)
}
input = compilerInput(source.sources, params)
result = JSON.parse(remoteCompiler.compile(input, { import: missingInputsCallback }))
}
} catch (exception) {
@ -291,6 +304,11 @@ export class Compiler {
if (source && source.sources) {
const { optimize, runs, evmVersion, language } = this.state
jobs.push({ sources: source })
let params = { optimize, runs, evmVersion, language }
if (this.state.useFileConfiguration) {
params = JSON.parse(this.state.configFileContent)
}
this.state.worker.postMessage({
cmd: 'compile',
job: jobs.length - 1,

@ -164,6 +164,8 @@ export interface CompilerState {
language: Language,
compilationStartTime: number| null,
target: string | null,
useFileConfiguration: false,
configFileContent: '',
lastCompilationResult: {
data: CompilationResult | null,
source: SourceWithTarget | null | undefined

@ -160,6 +160,11 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
}
}, [compilerContainer.editor.mode])
useEffect(() => {
compileTabLogic.setUseFileConfiguration(!manualConfig)
if (!manualConfig) compileTabLogic.setConfigFilePath(configFilePath)
}, [manualConfig])
useEffect(() => {
if (configurationSettings) {
setConfiguration(configurationSettings)
@ -176,18 +181,22 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
setConfigFilePath(configFilePathInput.current.value)
}
const handleConfigPathChange = async () => {
if (await api.fileExists(configFilePathInput.current.value))
setConfigFilePath(configFilePathInput.current.value)
else {
modal(
'New configuration file', `The file "${configFilePathInput.current.value}"" you entered does not exist. Do you want to create a new one?`,
'Create',
async () => await createNewConfigFile(),
'Cancel',
() => {}
)
if (configFilePathInput.current.value !== '') {
if (await api.fileExists(configFilePathInput.current.value))
setConfigFilePath(configFilePathInput.current.value)
else {
modal(
'New configuration file', `The file "${configFilePathInput.current.value}"" you entered does not exist. Do you want to create a new one?`,
'Create',
async () => await createNewConfigFile(),
'Cancel',
() => {}
)
}
}
setShowFilePathInput(false)
compileTabLogic.setConfigFilePath(configFilePath)
}
const _retrieveVersion = (version?) => {

@ -18,6 +18,8 @@ export class CompileTabLogic {
public compilerImport
public event
public evmVersions: Array<string>
public useFileConfiguration: boolean
public configFilePath: string
constructor (public api: ICompilerApi, public contentImport) {
this.event = new EventEmitter()
@ -46,6 +48,8 @@ export class CompileTabLogic {
this.api.setCompilerParameters({ evmVersion: this.evmVersion })
this.compiler.set('evmVersion', this.evmVersion)
this.useFileConfiguration = false
this.configFilePath = ''
this.language = getValidLanguage(this.api.getCompilerParameters().language)
if (this.language != null) {
this.compiler.set('language', this.language)
@ -58,6 +62,18 @@ export class CompileTabLogic {
this.compiler.set('optimize', this.optimize)
}
setUseFileConfiguration (useFileConfiguration) {
this.useFileConfiguration = useFileConfiguration
this.compiler.set('useFileConfiguration', useFileConfiguration)
}
setConfigFilePath (path) {
this.configFilePath = path
this.api.readFile(path).then( content => {
this.compiler.set('configFileContent', content)
})
}
setRuns (runs) {
this.runs = runs
this.api.setCompilerParameters({ runs: this.runs })

Loading…
Cancel
Save