fixe path update

compilerCong
lianahus 3 years ago
parent 937b9ab2b3
commit d00d0ff592
  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": { "settings": {
"optimizer": { "optimizer": {
"enabled": true, "enabled": true,
"runs": 260 "runs": 200
}, },
"outputSelection": { "outputSelection": {
"*": { "*": {

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

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

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

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

Loading…
Cancel
Save