Skip to content

Commit

Permalink
add Base.isless for ordering ExecutableProduct vs LibraryProduct (#180)
Browse files Browse the repository at this point in the history
* add Base.isless for ordering ExecutableProduct vs LibraryProduct

* switch so that LibraryProducts come first and then ExecutableProducts

* fix sorting tests
  • Loading branch information
Crghilardi authored Nov 24, 2021
1 parent c213d27 commit dea18f2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/Products.jl
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ function locate(fp::FileProduct, prefix::Prefix; platform::AbstractPlatform = Ho
end

# Necessary to get the products in the wrappers always sorted consistently
Base.isless(x::LibraryProduct, y::ExecutableProduct) = true
Base.isless(x::ExecutableProduct, y::LibraryProduct) = false
Base.isless(x::Product, y::Product) = isless(variable_name(x), variable_name(y))
Base.sort(d::Dict{Product}) = sort(collect(d), by = first)

Expand Down
4 changes: 2 additions & 2 deletions test/products.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ const platform = HostPlatform()

# Test sorting of products....
@test sort([LibraryProduct("libbar", :libbar), ExecutableProduct("foo", :foo), FrameworkProduct("buzz", :buzz)]) ==
[FrameworkProduct("buzz", :buzz), ExecutableProduct("foo", :foo), LibraryProduct("libbar", :libbar)]
[FrameworkProduct("buzz", :buzz), LibraryProduct("libbar", :libbar), ExecutableProduct("foo", :foo)]
# ...and products info
p1 = LibraryProduct(["libchafa"], :libchafa, ) => Dict("soname" => "libchafa.so.0","path" => "lib/libchafa.so")
p2 = ExecutableProduct(["chafa"], :chafa, ) => Dict("path" => "bin/chafa")
products_info = Dict{Product,Any}(p1, p2)
@test sort(products_info) == [p2, p1]
@test sort(products_info) == [p1, p2]

temp_prefix() do prefix
# Test that basic satisfication is not guaranteed
Expand Down

0 comments on commit dea18f2

Please sign in to comment.