Skip to content

Commit 8502fed

Browse files
committed
Correct string interpolation syntax
1 parent 60a8583 commit 8502fed

File tree

1 file changed

+117
-113
lines changed

1 file changed

+117
-113
lines changed

src/AutoBuild.jl

Lines changed: 117 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,6 +1416,121 @@ function build_jll_package(src_name::String,
14161416
!ispath(pkg_dir) && mkdir(pkg_dir)
14171417
write(joinpath(pkg_dir, "platform_augmentation.jl"), augment_platform_block)
14181418

1419+
overload_parse = """
1420+
# Update Base.parse for Julia <1.12 to support riscv64
1421+
@static if !haskey(BinaryPlatforms.arch_mapping, "riscv64")
1422+
1423+
function bbparse(::Type{Platform}, triplet::AbstractString; validate_strict::Bool = false)
1424+
# setup_riscv64()
1425+
1426+
arch_mapping = BinaryPlatforms.arch_mapping
1427+
os_mapping = BinaryPlatforms.os_mapping
1428+
libc_mapping = BinaryPlatforms.libc_mapping
1429+
call_abi_mapping = BinaryPlatforms.call_abi_mapping
1430+
libgfortran_version_mapping = BinaryPlatforms.libgfortran_version_mapping
1431+
cxxstring_abi_mapping = BinaryPlatforms.cxxstring_abi_mapping
1432+
libstdcxx_version_mapping = BinaryPlatforms.libstdcxx_version_mapping
1433+
1434+
# Helper function to collapse dictionary of mappings down into a regex of
1435+
# named capture groups joined by "|" operators
1436+
c(mapping) = string("(",join(["(?<\$k>\$v)" for (k, v) in mapping], "|"), ")")
1437+
1438+
# We're going to build a mondo regex here to parse everything:
1439+
triplet_regex = Regex(string(
1440+
"^",
1441+
# First, the core triplet; arch/os/libc/call_abi
1442+
c(arch_mapping),
1443+
c(os_mapping),
1444+
c(libc_mapping),
1445+
c(call_abi_mapping),
1446+
# Next, optional things, like libgfortran/libstdcxx/cxxstring abi
1447+
c(libgfortran_version_mapping),
1448+
c(cxxstring_abi_mapping),
1449+
c(libstdcxx_version_mapping),
1450+
# Finally, the catch-all for extended tags
1451+
"(?<tags>(?:-[^-]+\\\\+[^-]+)*)?",
1452+
"\\\$",
1453+
))
1454+
1455+
m = match(triplet_regex, triplet)
1456+
if m !== nothing
1457+
# Helper function to find the single named field within the giant regex
1458+
# that is not `nothing` for each mapping we give it.
1459+
get_field(m, mapping) = begin
1460+
for k in keys(mapping)
1461+
if m[k] !== nothing
1462+
# Convert our sentinel `nothing` values to actual `nothing`
1463+
if endswith(k, "_nothing")
1464+
return nothing
1465+
end
1466+
# Convert libgfortran/libstdcxx version numbers
1467+
if startswith(k, "libgfortran")
1468+
return VersionNumber(parse(Int,k[12:end]))
1469+
elseif startswith(k, "libstdcxx")
1470+
return VersionNumber(3, 4, parse(Int,m[k][11:end]))
1471+
else
1472+
return k
1473+
end
1474+
end
1475+
end
1476+
end
1477+
1478+
# Extract the information we're interested in:
1479+
arch = get_field(m, arch_mapping)
1480+
os = get_field(m, os_mapping)
1481+
libc = get_field(m, libc_mapping)
1482+
call_abi = get_field(m, call_abi_mapping)
1483+
libgfortran_version = get_field(m, libgfortran_version_mapping)
1484+
libstdcxx_version = get_field(m, libstdcxx_version_mapping)
1485+
cxxstring_abi = get_field(m, cxxstring_abi_mapping)
1486+
function split_tags(tagstr)
1487+
tag_fields = filter(!isempty, split(tagstr, "-"))
1488+
if isempty(tag_fields)
1489+
return Pair{String,String}[]
1490+
end
1491+
return map(v -> Symbol(v[1]) => v[2], split.(tag_fields, "+"))
1492+
end
1493+
tags = split_tags(m["tags"])
1494+
1495+
# Special parsing of os version number, if any exists
1496+
function extract_os_version(os_name, pattern)
1497+
m_osvn = match(pattern, m[os_name])
1498+
if m_osvn !== nothing
1499+
return VersionNumber(m_osvn.captures[1])
1500+
end
1501+
return nothing
1502+
end
1503+
os_version = nothing
1504+
if os == "macos"
1505+
os_version = extract_os_version("macos", r".*darwin([\d\.]+)")
1506+
end
1507+
if os == "freebsd"
1508+
os_version = extract_os_version("freebsd", r".*freebsd([\d.]+)")
1509+
end
1510+
1511+
return Platform(
1512+
arch, os;
1513+
validate_strict,
1514+
libc,
1515+
call_abi,
1516+
libgfortran_version,
1517+
cxxstring_abi,
1518+
libstdcxx_version,
1519+
os_version,
1520+
tags...,
1521+
)
1522+
end
1523+
throw(ArgumentError("Platform `$(triplet)` is not an officially supported platform"))
1524+
end
1525+
1526+
else
1527+
# Julia ≥ 1.12, all is fine
1528+
1529+
const bbparse = Base.parse
1530+
1531+
end
1532+
"""
1533+
14191534
write(joinpath(pkg_dir, "select_artifacts.jl"),
14201535
"""
14211536
push!(Base.LOAD_PATH, dirname(@__DIR__))
@@ -1424,118 +1539,7 @@ function build_jll_package(src_name::String,
14241539
include("./platform_augmentation.jl")
14251540
artifacts_toml = joinpath(dirname(@__DIR__), "Artifacts.toml")
14261541
1427-
# Update Base.parse for Julia <1.12 to support riscv64
1428-
@static if !haskey(BinaryPlatforms.arch_mapping, "riscv64")
1429-
1430-
function bbparse(::Type{Platform}, triplet::AbstractString; validate_strict::Bool = false)
1431-
# setup_riscv64()
1432-
1433-
arch_mapping = BinaryPlatforms.arch_mapping
1434-
os_mapping = BinaryPlatforms.os_mapping
1435-
libc_mapping = BinaryPlatforms.libc_mapping
1436-
call_abi_mapping = BinaryPlatforms.call_abi_mapping
1437-
libgfortran_version_mapping = BinaryPlatforms.libgfortran_version_mapping
1438-
cxxstring_abi_mapping = BinaryPlatforms.cxxstring_abi_mapping
1439-
libstdcxx_version_mapping = BinaryPlatforms.libstdcxx_version_mapping
1440-
1441-
# Helper function to collapse dictionary of mappings down into a regex of
1442-
# named capture groups joined by "|" operators
1443-
c(mapping) = string("(",join(["(?<$k>$v)" for (k, v) in mapping], "|"), ")")
1444-
1445-
# We're going to build a mondo regex here to parse everything:
1446-
triplet_regex = Regex(string(
1447-
"^",
1448-
# First, the core triplet; arch/os/libc/call_abi
1449-
c(arch_mapping),
1450-
c(os_mapping),
1451-
c(libc_mapping),
1452-
c(call_abi_mapping),
1453-
# Next, optional things, like libgfortran/libstdcxx/cxxstring abi
1454-
c(libgfortran_version_mapping),
1455-
c(cxxstring_abi_mapping),
1456-
c(libstdcxx_version_mapping),
1457-
# Finally, the catch-all for extended tags
1458-
"(?<tags>(?:-[^-]+\\+[^-]+)*)?",
1459-
"\$",
1460-
))
1461-
1462-
m = match(triplet_regex, triplet)
1463-
if m !== nothing
1464-
# Helper function to find the single named field within the giant regex
1465-
# that is not `nothing` for each mapping we give it.
1466-
get_field(m, mapping) = begin
1467-
for k in keys(mapping)
1468-
if m[k] !== nothing
1469-
# Convert our sentinel `nothing` values to actual `nothing`
1470-
if endswith(k, "_nothing")
1471-
return nothing
1472-
end
1473-
# Convert libgfortran/libstdcxx version numbers
1474-
if startswith(k, "libgfortran")
1475-
return VersionNumber(parse(Int,k[12:end]))
1476-
elseif startswith(k, "libstdcxx")
1477-
return VersionNumber(3, 4, parse(Int,m[k][11:end]))
1478-
else
1479-
return k
1480-
end
1481-
end
1482-
end
1483-
end
1484-
1485-
# Extract the information we're interested in:
1486-
arch = get_field(m, arch_mapping)
1487-
os = get_field(m, os_mapping)
1488-
libc = get_field(m, libc_mapping)
1489-
call_abi = get_field(m, call_abi_mapping)
1490-
libgfortran_version = get_field(m, libgfortran_version_mapping)
1491-
libstdcxx_version = get_field(m, libstdcxx_version_mapping)
1492-
cxxstring_abi = get_field(m, cxxstring_abi_mapping)
1493-
function split_tags(tagstr)
1494-
tag_fields = filter(!isempty, split(tagstr, "-"))
1495-
if isempty(tag_fields)
1496-
return Pair{String,String}[]
1497-
end
1498-
return map(v -> Symbol(v[1]) => v[2], split.(tag_fields, "+"))
1499-
end
1500-
tags = split_tags(m["tags"])
1501-
1502-
# Special parsing of os version number, if any exists
1503-
function extract_os_version(os_name, pattern)
1504-
m_osvn = match(pattern, m[os_name])
1505-
if m_osvn !== nothing
1506-
return VersionNumber(m_osvn.captures[1])
1507-
end
1508-
return nothing
1509-
end
1510-
os_version = nothing
1511-
if os == "macos"
1512-
os_version = extract_os_version("macos", r".*darwin([\d\.]+)")
1513-
end
1514-
if os == "freebsd"
1515-
os_version = extract_os_version("freebsd", r".*freebsd([\d.]+)")
1516-
end
1517-
1518-
return Platform(
1519-
arch, os;
1520-
validate_strict,
1521-
libc,
1522-
call_abi,
1523-
libgfortran_version,
1524-
cxxstring_abi,
1525-
libstdcxx_version,
1526-
os_version,
1527-
tags...,
1528-
)
1529-
end
1530-
throw(ArgumentError("Platform `$(triplet)` is not an officially supported platform"))
1531-
end
1532-
1533-
else
1534-
# Julia ≥ 1.12, all is fine
1535-
1536-
const bbparse = Base.parse
1537-
1538-
end
1542+
$(overload_parse)
15391543
15401544
# Get "target triplet" from ARGS, if given (defaulting to the host triplet otherwise)
15411545
target_triplet = get(ARGS, 1, Base.BinaryPlatforms.host_triplet())
@@ -1546,7 +1550,7 @@ function build_jll_package(src_name::String,
15461550
# Select all downloadable artifacts that match that platform
15471551
artifacts = select_downloadable_artifacts(artifacts_toml; platform, include_lazy=true)
15481552
1549-
#Output the result to `stdout` as a TOML dictionary
1553+
# Output the result to `stdout` as a TOML dictionary
15501554
TOML.print(stdout, artifacts)
15511555
""")
15521556
end

0 commit comments

Comments
 (0)