fixe path update

pull/2249/head
lianahus 3 years ago committed by yann300
parent 00ef21edea
commit 78ca100f1b
  1. 2
      apps/remix-ide/contracts/solidity_compiler_config.json
  2. 2
      apps/solidity-compiler/src/app/compiler.ts
  3. 2
      libs/remix-solidity/src/compiler/compiler.ts
  4. 67
      libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx
  5. 6
      libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts

@ -3,7 +3,7 @@
"settings": {
"optimizer": {
"enabled": true,
"runs": 260
"runs": 200
},
"outputSelection": {
"*": {

@ -26,7 +26,7 @@ const defaultCompilerParameters = {
evmVersion: null, // compiler default
language: 'Solidity',
useFileConfiguration: false,
configFilePath: ''
configFilePath: "/compiler_config.json"
}
export class CompilerClientApi extends CompilerApiMixin(PluginClient) implements ICompilerApi {
constructor () {

@ -314,7 +314,7 @@ export class Compiler {
input = compilerInput(source.sources, { optimize, runs, evmVersion, language })
}
} catch (exception) {
this.onCompilationFinished({ error: { formattedMessage: exception.messsage } }, [], source, "", this.state.currentVersion)
this.onCompilationFinished({ error: { formattedMessage: exception.message } }, [], source, "", this.state.currentVersion)
return
}

@ -27,6 +27,8 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
const [state, setState] = useState({
hideWarnings: false,
autoCompile: false,
configFilePath: "/compiler_config.json",
useFileConfiguration: false,
matomoAutocompileOnce: true,
optimize: false,
compileTimeout: null,
@ -41,8 +43,6 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
language: 'Solidity',
evmVersion: ''
})
const [manualConfig, setManualConfig] = useState<boolean>(true)
const [configFilePath, setConfigFilePath] = useState<string>("/compiler_config.json")
const [showFilePathInput, setShowFilePathInput] = useState<boolean>(false)
const [disableCompileButton, setDisableCompileButton] = useState<boolean>(false)
@ -54,15 +54,15 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
const [compilerContainer, dispatch] = useReducer(compilerReducer, compilerInitialState)
useEffect(() => {
setConfigFilePath("/compiler_config.json")
api.setAppParameter('configFilePath', "/compiler_config.json")
api.fileExists("/compiler_config.json").then((exists) => {
if (!exists) createNewConfigFile()
else {
// what to do? discuss
}
})
setConfigFilePath("/compiler_config.json")
setManualConfig(false)
api.setAppParameter('configFilePath', "/compiler_config.json")
api.setAppParameter('useFileConfiguration', false)
setShowFilePathInput(false)
}, [workspaceName])
@ -92,6 +92,10 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
const autocompile = await api.getAppParameter('autoCompile') as boolean || false
const hideWarnings = await api.getAppParameter('hideWarnings') as boolean || false
const includeNightlies = await api.getAppParameter('includeNightlies') as boolean || false
const useFileConfiguration = await api.getAppParameter('useFileConfiguration') as boolean || true
let configFilePath = await api.getAppParameter('configFilePath')
console.log("in useeff init ", configFilePath)
if (!configFilePath || configFilePath == '') configFilePath = "/compiler_config.json"
setState(prevState => {
const params = api.getCompilerParameters()
@ -105,6 +109,8 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
hideWarnings: hideWarnings,
autoCompile: autocompile,
includeNightlies: includeNightlies,
useFileConfiguration: useFileConfiguration,
configFilePath: configFilePath,
optimize: optimize,
runs: runs,
evmVersion: (evmVersion !== null) && (evmVersion !== 'null') && (evmVersion !== undefined) && (evmVersion !== 'undefined') ? evmVersion : 'default',
@ -162,9 +168,9 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
}, [compilerContainer.editor.mode])
useEffect(() => {
compileTabLogic.setUseFileConfiguration(!manualConfig)
if (!manualConfig) compileTabLogic.setConfigFilePath(configFilePath)
}, [manualConfig])
compileTabLogic.setUseFileConfiguration(state.useFileConfiguration)
if (state.useFileConfiguration) compileTabLogic.setConfigFilePath(state.configFilePath)
}, [state.useFileConfiguration])
useEffect(() => {
if (configurationSettings) {
@ -173,31 +179,48 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
}, [configurationSettings])
const toggleConfigType = () => {
setManualConfig(!manualConfig)
setState(prevState => {
return { ...prevState, useFileConfiguration: !state.useFileConfiguration }
})
api.setAppParameter('useFileConfiguration', state.useFileConfiguration)
}
const createNewConfigFile = async () => {
const configFileContent = JSON.stringify(json_config, null, '\t')
await api.writeFile(configFilePathInput.current && configFilePathInput.current.value !== '' ? configFilePathInput.current.value : configFilePath, configFileContent)
setConfigFilePath(configFilePathInput.current.value)
const filePath = configFilePathInput.current && configFilePathInput.current.value !== '' ? configFilePathInput.current.value : state.configFilePath
await api.writeFile(filePath, configFileContent)
console.log("createNewConfigFile ", filePath)
api.setAppParameter('configFilePath', filePath)
setState(prevState => {
return { ...prevState, configFilePath: filePath }
})
compileTabLogic.setConfigFilePath(filePath)
setShowFilePathInput(false)
}
const handleConfigPathChange = async () => {
if (configFilePathInput.current.value !== '') {
if (await api.fileExists(configFilePathInput.current.value))
setConfigFilePath(configFilePathInput.current.value)
else {
if (await api.fileExists(configFilePathInput.current.value)) {
api.setAppParameter('configFilePath', configFilePathInput.current.value)
setState(prevState => {
return { ...prevState, configFilePath: configFilePathInput.current.value }
})
compileTabLogic.setConfigFilePath(configFilePathInput.current.value)
setShowFilePathInput(false)
} 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)
}
)
}
}
setShowFilePathInput(false)
compileTabLogic.setConfigFilePath(configFilePath)
}
const _retrieveVersion = (version?) => {
@ -596,11 +619,11 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
<article>
<header className='pt-0 remixui_compilerSection border-bottom'>
<div className="d-flex remixui_compilerConfig custom-control custom-checkbox">
<input className="custom-control-input" type="checkbox" value="file" onChange={toggleConfigType} checked={!manualConfig} id="sCManualConfig" />
<input className="custom-control-input" type="checkbox" value="file" onChange={toggleConfigType} checked={state.useFileConfiguration} id="sCManualConfig" />
<label className="font-weight-bold pt-1 form-check-label custom-control-label remixui_compilerLabel" htmlFor="sCManualConfig">Use configuration file</label>
</div>
<div className={`pt-2 ml-3 ml-2 align-items-start flex-column ${!manualConfig ? 'd-flex' : 'd-none'}`}>
{ !showFilePathInput && <span className="py-2 text-primary">{configFilePath}</span> }
<div className={`pt-2 ml-3 ml-2 align-items-start flex-column ${state.useFileConfiguration ? 'd-flex' : 'd-none'}`}>
{ !showFilePathInput && <span className="py-2 text-primary">{state.configFilePath}</span> }
<input
ref={configFilePathInput}
className={`py-0 my-0 ${showFilePathInput ? "d-flex" : "d-none"}`}
@ -614,7 +637,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
/>
{ !showFilePathInput && <button className="btn-secondary" onClick={() => {setShowFilePathInput(true)}}>Set new config file</button> }
</div>
<div className={`flex-column ${manualConfig ? 'd-flex' : 'd-none'}`}>
<div className={`flex-column ${!state.useFileConfiguration ? 'd-flex' : 'd-none'}`}>
<div className="pl-0 d-flex remixui_compilerConfig custom-control custom-checkbox">
</div>
<div className="mb-2">

@ -48,7 +48,9 @@ export class CompileTabLogic {
this.api.setCompilerParameters({ evmVersion: this.evmVersion })
this.compiler.set('evmVersion', this.evmVersion)
this.useFileConfiguration = this.api.getCompilerParameters().useFileConfiguration
//this.useFileConfiguration = this.api.getCompilerParameters().useFileConfiguration
console.log("logic this.configFilePath ", this.configFilePath)
console.log("logic this.api.getCompilerParameters().configFilePath ", this.api.getCompilerParameters().configFilePath)
this.configFilePath = this.api.getCompilerParameters().configFilePath
this.language = getValidLanguage(this.api.getCompilerParameters().language)
if (this.language != null) {
@ -68,6 +70,7 @@ export class CompileTabLogic {
}
setConfigFilePath (path) {
console.log("path in logic = ", path)
this.configFilePath = path
}
@ -108,6 +111,7 @@ export class CompileTabLogic {
const sources = { [target]: { content } }
this.event.emit('removeAnnotations')
this.event.emit('startingCompilation')
console.log("compile from ", this.configFilePath)
this.api.readFile(this.configFilePath).then( contentConfig => {
this.compiler.set('configFileContent', contentConfig)
})

Loading…
Cancel
Save