From 61af2bf5bc30b1347764a6dc4184ed84299c16a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mos=C3=A8=20Giordano?= Date: Tue, 21 Jan 2020 02:31:12 +0000 Subject: [PATCH] Write to the generated README the actual list of products --- src/AutoBuild.jl | 92 +++++++++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 36 deletions(-) diff --git a/src/AutoBuild.jl b/src/AutoBuild.jl index b6984f708..7d5d097c5 100644 --- a/src/AutoBuild.jl +++ b/src/AutoBuild.jl @@ -982,6 +982,7 @@ function build_jll_package(src_name::String, build_version::VersionNumber, code_ mkpath(joinpath(code_dir, "src", "wrappers")) platforms = keys(build_output_meta) + products_info = Dict{Any,Any} for platform in platforms if verbose @info("Generating jll package for $(triplet(platform)) in $(code_dir)") @@ -1218,44 +1219,63 @@ function build_jll_package(src_name::String, build_version::VersionNumber, code_ """) end + product_names(p::ExecutableProduct) = p.binnames + product_names(p::FileProduct) = p.paths + product_names(p::LibraryProduct) = p.libnames # Add a README.md open(joinpath(code_dir, "README.md"), "w") do io - print(io, """ - # $(src_name)_jll.jl - - This is an autogenerated package constructed using [`BinaryBuilder.jl`](https://github.com/JuliaPackaging/BinaryBuilder.jl). - - ## Usage - - 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: - - ```julia - products = [ - FileProduct("src/data.txt", :data_txt), - LibraryProduct("libdataproc", :libdataproc), - ExecutableProduct("mungify", :mungify_exe) - ] - ``` - - 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: - - ```julia - using $(src_name)_jll - - # For file products, you can access its file location directly: - data_lines = open(data_txt, "r") do io - readlines(io) - end - - # For library products, you can use the exported variable name in `ccall()` invocations directly - num_chars = ccall((libdataproc, :count_characters), Cint, (Cstring, Cint), data_lines[1], length(data_lines[1])) - - # For executable products, you can use the exported variable name as a function that you can call - mungify_exe() do mungify_exe_path - run(`\$mungify_exe_path \$num_chars`) - end - ``` - """) + print(io, + """ + # $(src_name)_jll.jl + + This is an autogenerated package constructed using [`BinaryBuilder.jl`](https://github.com/JuliaPackaging/BinaryBuilder.jl). + + """, + iszero(length(keys(products_info))) ? "" : + """ + ## Products + + The code bindings within this package are autogenerated from the following `Products` defined within the `build_tarballs.jl` file that generated this package: + + ```julia + products = [ + $(join(collect(" $(typeof(p))($(product_names(p)), :$(variable_name(p)))" for (p, _) in products_info), ",\n")) + ] + ``` + + """, + """ + ## Usage example + + For example purposes, we will assume that the following products were defined in the imaginary package `Example_jll`: + + ```julia + products = [ + FileProduct("src/data.txt", :data_txt), + LibraryProduct("libdataproc", :libdataproc), + ExecutableProduct("mungify", :mungify_exe) + ] + ``` + + 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: + + ```julia + using Example_jll + + # For file products, you can access its file location directly: + data_lines = open(data_txt, "r") do io + readlines(io) + end + + # For library products, you can use the exported variable name in `ccall()` invocations directly + num_chars = ccall((libdataproc, :count_characters), Cint, (Cstring, Cint), data_lines[1], length(data_lines[1])) + + # For executable products, you can use the exported variable name as a function that you can call + mungify_exe() do mungify_exe_path + run(`\$mungify_exe_path \$num_chars`) + end + ``` + """) end # Generate LICENSE.md