Skip to content

Commit

Permalink
Merge pull request #678 from kyonRay/master
Browse files Browse the repository at this point in the history
<fix>(compiler): fix compiler switch version static final optimization bug.
  • Loading branch information
kyonRay authored Sep 5, 2022
2 parents 2841d53 + df1f772 commit 817d4be
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
11 changes: 9 additions & 2 deletions src/main/java/console/contract/ConsoleContractImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -855,13 +855,20 @@ private String getSolidityAbi(String contractFileName) throws Exception {
List<SolidityCompiler.Option> defaultOptions = Arrays.asList(ABI, BIN, METADATA);
List<SolidityCompiler.Option> options = new ArrayList<>(defaultOptions);

if (org.fisco.solc.compiler.Version.version.compareToIgnoreCase(
ConsoleUtils.COMPILE_WITH_BASE_PATH)
if (ContractCompiler.solcJVersion.compareToIgnoreCase(ConsoleUtils.COMPILE_WITH_BASE_PATH)
>= 0) {
logger.debug(
"compileSolToBinAndAbi, solc version:{} ,basePath: {}",
ContractCompiler.solcJVersion,
solFile.getParentFile().getCanonicalPath());
SolidityCompiler.Option basePath =
new SolidityCompiler.CustomOption(
"base-path", solFile.getParentFile().getCanonicalPath());
options.add(basePath);
} else {
logger.debug(
"compileSolToBinAndAbi, solc version:{}",
org.fisco.solc.compiler.Version.version);
}

// compile ecdsa
Expand Down
30 changes: 26 additions & 4 deletions src/main/java/console/contract/utils/ContractCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,27 @@ public class ContractCompiler {
public static final String BIN_SUFFIX = ".bin";
public static final String ABI_SUFFIX = ".abi";
public static final String WASM_SUFFIX = ".wasm";
public static String solcJVersion;

static {
if (solcJVersion == null) {
try {
String runGetVersionOutput = SolidityCompiler.runGetVersionOutput(false);
solcJVersion =
runGetVersionOutput.substring(
runGetVersionOutput.indexOf("Version: ") + "Version: ".length(),
runGetVersionOutput.lastIndexOf("+commit"));
if (!solcJVersion.matches("^([0-9]\\d|[0-9])(\\.([0-9]\\d|\\d)){2}$")) {
solcJVersion = org.fisco.solc.compiler.Version.version;
}
} catch (Exception e) {
logger.info(
"Load solcJ version error, use default version string, version:{}",
org.fisco.solc.compiler.Version.version);
solcJVersion = org.fisco.solc.compiler.Version.version;
}
}
}

public static AbiAndBin compileContract(
String contractNameOrPath, boolean sm, boolean isContractParallelAnalysis)
Expand Down Expand Up @@ -160,16 +181,17 @@ public static AbiAndBin compileSolToBinAndAbi(
options.add(libraryOption);
}

if (org.fisco.solc.compiler.Version.version.compareToIgnoreCase(
ConsoleUtils.COMPILE_WITH_BASE_PATH)
>= 0) {
if (solcJVersion.compareToIgnoreCase(ConsoleUtils.COMPILE_WITH_BASE_PATH) >= 0) {
logger.debug(
"compileSolToBinAndAbi, basePath: {}",
"compileSolToBinAndAbi, solc version:{} ,basePath: {}",
solcJVersion,
contractFile.getParentFile().getCanonicalPath());
SolidityCompiler.Option basePath =
new SolidityCompiler.CustomOption(
"base-path", contractFile.getParentFile().getCanonicalPath());
options.add(basePath);
} else {
logger.debug("compileSolToBinAndAbi, solc version:{}", solcJVersion);
}
SolidityCompiler.Result res =
SolidityCompiler.compile(
Expand Down

0 comments on commit 817d4be

Please sign in to comment.