Skip to content

Commit 7b3f073

Browse files
authored
Write to the generated README the actual list of products (#626)
1 parent b0231bd commit 7b3f073

File tree

1 file changed

+56
-36
lines changed

1 file changed

+56
-36
lines changed

src/AutoBuild.jl

Lines changed: 56 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,7 @@ function build_jll_package(src_name::String, build_version::VersionNumber, code_
987987
mkpath(joinpath(code_dir, "src", "wrappers"))
988988

989989
platforms = keys(build_output_meta)
990+
products_info = Dict{Any,Any}
990991
for platform in platforms
991992
if verbose
992993
@info("Generating jll package for $(triplet(platform)) in $(code_dir)")
@@ -1223,44 +1224,63 @@ function build_jll_package(src_name::String, build_version::VersionNumber, code_
12231224
""")
12241225
end
12251226

1227+
product_names(p::ExecutableProduct) = p.binnames
1228+
product_names(p::FileProduct) = p.paths
1229+
product_names(p::LibraryProduct) = p.libnames
12261230
# Add a README.md
12271231
open(joinpath(code_dir, "README.md"), "w") do io
1228-
print(io, """
1229-
# $(src_name)_jll.jl
1230-
1231-
This is an autogenerated package constructed using [`BinaryBuilder.jl`](https://github.com/JuliaPackaging/BinaryBuilder.jl).
1232-
1233-
## Usage
1234-
1235-
The code bindings within this package are autogenerated from the `Products` defined within the `build_tarballs.jl` file that generated this package. For example purposes, we will assume that the following products were defined:
1236-
1237-
```julia
1238-
products = [
1239-
FileProduct("src/data.txt", :data_txt),
1240-
LibraryProduct("libdataproc", :libdataproc),
1241-
ExecutableProduct("mungify", :mungify_exe)
1242-
]
1243-
```
1244-
1245-
With such products defined, this package will contain `data_txt`, `libdataproc` and `mungify_exe` symbols exported. For `FileProduct` variables, the exported value is a string pointing to the location of the file on-disk. For `LibraryProduct` variables, it is a string corresponding to the `SONAME` of the desired library (it will have already been `dlopen()`'ed, so typical `ccall()` usage applies), and for `ExecutableProduct` variables, the exported value is a function that can be called to set appropriate environment variables. Example:
1246-
1247-
```julia
1248-
using $(src_name)_jll
1249-
1250-
# For file products, you can access its file location directly:
1251-
data_lines = open(data_txt, "r") do io
1252-
readlines(io)
1253-
end
1254-
1255-
# For library products, you can use the exported variable name in `ccall()` invocations directly
1256-
num_chars = ccall((libdataproc, :count_characters), Cint, (Cstring, Cint), data_lines[1], length(data_lines[1]))
1257-
1258-
# For executable products, you can use the exported variable name as a function that you can call
1259-
mungify_exe() do mungify_exe_path
1260-
run(`\$mungify_exe_path \$num_chars`)
1261-
end
1262-
```
1263-
""")
1232+
print(io,
1233+
"""
1234+
# $(src_name)_jll.jl
1235+
1236+
This is an autogenerated package constructed using [`BinaryBuilder.jl`](https://github.com/JuliaPackaging/BinaryBuilder.jl).
1237+
1238+
""",
1239+
iszero(length(keys(products_info))) ? "" :
1240+
"""
1241+
## Products
1242+
1243+
The code bindings within this package are autogenerated from the following `Products` defined within the `build_tarballs.jl` file that generated this package:
1244+
1245+
```julia
1246+
products = [
1247+
$(join(collect(" $(typeof(p))($(product_names(p)), :$(variable_name(p)))" for (p, _) in products_info), ",\n"))
1248+
]
1249+
```
1250+
1251+
""",
1252+
"""
1253+
## Usage example
1254+
1255+
For example purposes, we will assume that the following products were defined in the imaginary package `Example_jll`:
1256+
1257+
```julia
1258+
products = [
1259+
FileProduct("src/data.txt", :data_txt),
1260+
LibraryProduct("libdataproc", :libdataproc),
1261+
ExecutableProduct("mungify", :mungify_exe)
1262+
]
1263+
```
1264+
1265+
With such products defined, `Example_jll` would contain `data_txt`, `libdataproc` and `mungify_exe` symbols exported. For `FileProduct` variables, the exported value is a string pointing to the location of the file on-disk. For `LibraryProduct` variables, it is a string corresponding to the `SONAME` of the desired library (it will have already been `dlopen()`'ed, so typical `ccall()` usage applies), and for `ExecutableProduct` variables, the exported value is a function that can be called to set appropriate environment variables. Example:
1266+
1267+
```julia
1268+
using Example_jll
1269+
1270+
# For file products, you can access its file location directly:
1271+
data_lines = open(data_txt, "r") do io
1272+
readlines(io)
1273+
end
1274+
1275+
# For library products, you can use the exported variable name in `ccall()` invocations directly
1276+
num_chars = ccall((libdataproc, :count_characters), Cint, (Cstring, Cint), data_lines[1], length(data_lines[1]))
1277+
1278+
# For executable products, you can use the exported variable name as a function that you can call
1279+
mungify_exe() do mungify_exe_path
1280+
run(`\$mungify_exe_path \$num_chars`)
1281+
end
1282+
```
1283+
""")
12641284
end
12651285

12661286
# Generate LICENSE.md

0 commit comments

Comments
 (0)