Skip to content

Write to the generated README the actual list of products #626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 56 additions & 36 deletions src/AutoBuild.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down Expand Up @@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make the example use the library in question? i.e. base the ccall on the first LibraryProduct (or drop it if it doesn't exist), etc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought so initially, but the call would be completely made up, potentially confusing a user reading the example and trying it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you allow it to be set in the build_tarballs.jl? I think the benefit of having runnable examples would be worth the additional complexity.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some recipes build dozens of libraries; I don't think it's going to be easy to get people to give examples for all of them. On the other hand, it would be neat to have people be able to specify them. We could have a "example ccall()" parser where in the wizard we can ask you "just paste in an exemplary ccall() if one exists", and you can provide that ccall in the build_tarballs.jl as well.

Hmmm, I'm not sold, but it's an interesting idea.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a single ccall would be fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also just link to proper docs about how to use executable products, library products and file products.


```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
Expand Down