Handle cases where there are multiple source files

This commit is contained in:
r0qs 2023-09-20 12:46:28 +02:00
parent fbec7c5a31
commit 62ff0fb0cb
No known key found for this signature in database
GPG Key ID: 61503DBA6667276C

View File

@ -179,28 +179,33 @@ function split_combined_json
{ {
local json_file="$1" local json_file="$1"
local output_path="$2" local output_path="$2"
local prefix="${3:-}" local path_to_contract_file="${3:-}"
for path_with_contract in $(jq '.contracts | keys | .[]' "${json_file}" 2> /dev/null) for path_with_contract in $(jq --raw-output '.contracts | keys | .[]' "${json_file}" 2> /dev/null)
do do
local path=${path_with_contract}
local contract="" local contract=""
local delimiter if [[ -z "${path_to_contract_file}" ]]
delimiter=$("${EXPR}" index "${path}" ":") || true
if [[ -z "${prefix}" ]]
then then
path=${path_with_contract:0:((${delimiter} - 1))} if [[ ${path_with_contract} =~ ^([[:alpha:]]:[[:alpha:]]) ]]
contract=${path_with_contract:((${delimiter})):((${#path_with_contract} - ${delimiter} - 1))} then
# contract name with the format "A:C" to be saved as "A_C.{type}"
contract=$(echo "${BASH_REMATCH[1]/:/_}" | tr -d '"')
else else
path=${path_with_contract} local delimiter
contract="" delimiter=$("${EXPR}" index "${path_with_contract}" ":") || true
# contract name with the format "<some-filepath>.sol:C" to be saved as "C.{type}"
contract=${path_with_contract:((${delimiter})):((${#path_with_contract} - ${delimiter}))}
fi fi
for type in $(jq --raw-output ".contracts.${path_with_contract} | keys | .[]" "${json_file}" 2> /dev/null) else
# Otherwise the contract name will be given by the provided path to the file, e.g. "yul/A_C.yul.{type}"
contract="${path_to_contract_file}"
fi
for type in $(jq --raw-output ".contracts.\"${path_with_contract}\" | keys | .[]" "${json_file}" 2> /dev/null)
do do
local output local output
output=$(jq --raw-output ".contracts.${path_with_contract}.\"${type}\"" "${json_file}") output=$(jq --raw-output ".contracts.\"${path_with_contract}\".\"${type}\"" "${json_file}")
if [[ -n "${output}" ]] if [[ -n "${output}" ]]
then then
echo "${output}" > "${output_path}/${prefix}${contract}.${type}" echo "${output}" > "${output_path}/${contract}.${type}"
fi fi
done done
done done