Skip to content

Commit 608592c

Browse files
authored
Merge pull request #37603 from JuliaLang/sf/binaryplatforms_add_tags
2 parents 8e1c978 + 57f4ea0 commit 608592c

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

base/binaryplatforms.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,11 @@ end
131131

132132
# Other `Platform` types can override this (I'm looking at you, `AnyPlatform`)
133133
tags(p::Platform) = p.tags
134+
135+
# Make it act more like a dict
136+
Base.getindex(p::AbstractPlatform, k::String) = getindex(tags(p), k)
134137
Base.haskey(p::AbstractPlatform, k::String) = haskey(tags(p), k)
138+
Base.setindex!(p::AbstractPlatform, v::String, k::String) = (setindex!(tags(p), v, k); p)
135139

136140
# Allow us to easily serialize Platform objects
137141
function Base.repr(p::Platform; context=nothing)

test/binaryplatforms.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ end
106106
@test all(haskey.(Ref(t), ("arch", "os", "libc")))
107107
@test haskey(tags(P("x86_64", "linux"; customtag="foo")), "customtag")
108108
@test tags(HostPlatform())["julia_version"] == string(VERSION.major, ".", VERSION.minor, ".", VERSION.patch)
109+
110+
# Test that we can modify tags at will using the dict-like interface:
111+
p = P("x86_64", "linux")
112+
p["foo"] = "bar"
113+
@test tags(p)["foo"] == "bar"
114+
@test p["foo"] == "bar"
115+
@test p["os"] == "linux"
116+
p["os"] = "JuliaOS"
117+
@test p["os"] == "JuliaOS"
109118
end
110119

111120
@testset "Triplet parsing" begin

0 commit comments

Comments
 (0)