Repository navigation
project: Add source_tree() for nested BUCK files - #424
Conversation
martinpitt
left a comment
There was a problem hiding this comment.
That commit message is quite a mouthful. It doesn't help that it mentions rpm.package and RPMs have subpackages and source trees, but this is really about buck (sub)packages. Also, the topmost commit bundles three changes:
- The
has_files()dotfile fix is an independent bug fix and should be its own preparatory commit. - The
source_tree()listing mechanism. - The dev-mode change: configured_dev becomes optional and the path is resolved by the tree.
I think the motivation was to lose another two commits in our fork? A lot of the commit message is also restating the "how".
Perhaps, for the second part:
rpm.package(source_tree = ".")can't build a project that has BUCK files in subdirectories, because Buck refuses a directory source that contains another Buck package, and the empty root path needs two patches in our buck2 fork.Have each BUCK file list its files with
project.source_tree()and pass that to the build instead of.to work around that.
(I have no idea whether this is actually right.)
Bot review: pr-source-tree-review.md
Honestly, this may be a case where you just need to play the "trust me bro" card, I can't say anything useful as this is still too hard to understand for me 😢
The rpm drivers treat the spec as an in-place spec when its path is inside
the source tree. A source tree can be the project root, given as ".", and
every relative path is inside ".". A declared spec in the project or a spec
in buck-out then builds as an in-place spec, and the build doesn't stage the
declared sources. Take this package:
rpm.package(
name = "hello",
spec = "rpm/hello.spec",
srcs = ["patches/fix.patch"],
source_tree = ".",
...
)
The build doesn't copy patches/fix.patch into SOURCES. rpm looks for the
patch in the directory of the spec, rpm/, and the build fails because the
patch isn't there.
Let's pass the path of an in-place spec relative to the source tree as a
field of its own. The drivers then build a spec in place only when the rule
asks for it.
Signed-off-by: Daan De Meyer <daan@amutable.com>
A package built with source_tree = "." reads an overlay of the whole project. The sandbox mounts the action's scratch directory in buck-out at /var/tmp, and source_overlay() puts the overlay's upper and work directories there. The upper and work directories are then inside the overlay's lower directory. overlayfs fails a lookup of them through the overlay with ELOOP, so a spec that walks the checkout, for example with cp -a ., fails. Let's mount an empty tmpfs over Buck's output directory in the overlay. The build doesn't need buck-out, and the content of buck-out changes while the build runs. Signed-off-by: Daan De Meyer <daan@amutable.com>
Without a [tine] dev setting, is_dev() reads the configured paths as one empty entry. The project path of a source "." in the root package of the root cell is empty as well. rpm.package(source_tree = ".") or cargo.package(src = ".") there is then always a dev build: it keeps its build directory and never uploads to the cache. Let's drop empty entries, and give a source "." in the root package the project path ".", so that [tine] dev = "." selects it. Signed-off-by: Daan De Meyer <daan@amutable.com>
has_files() misses a file whose path contains two names that start with a dot, such as .github/.keep. A checkout slot that only contains such files counts as empty, and the build falls back to the remote fetch. Buck's glob() matches a name that starts with a dot only with a pattern component like .*. has_files() has a pattern for one such name only. Let's glob with one pattern for each count of such names, up to four. Signed-off-by: Daan De Meyer <daan@amutable.com>
An upstream project can build an RPM of itself from its own checkout with
rpm.package(source_tree = "."). Buck rejects that as soon as a
subdirectory has a BUCK file of its own:
Directory `` of package `tine//project/fixture` may not cover any subpackages, but includes subpackage `sub`.
Let's add project.source_tree(), which lists the files of the project the
way the prelude's source listing does. Each BUCK file lists its own files
with project.source_listing() and includes the lists of the BUCK files
below it. The build gets the project path with the listed files as hidden
inputs and reads the directory in place, like a checkout.
Signed-off-by: Daan De Meyer <daan@amutable.com>
rpm.package() looks up its source tree in [tine] dev by the tree's label. For the checkout slot :hello.source in packages/hello, that's packages/hello/hello.source, the directory that the build reads. For project.source_tree(name = "source") in the root BUCK file, it's "source", but the build reads the project root. [tine] dev = "." then doesn't select a dev build. Let's have project.source_tree() look up the directory that it reads in [tine] dev and pass the result to the build. dev = True or dev = False on rpm.package() still takes precedence. Signed-off-by: Daan De Meyer <daan@amutable.com>
118dd22 to
75df6e0
Compare
martinpitt
left a comment
There was a problem hiding this comment.
Thanks! That documentation is so much better now! 🤗
An upstream project, such as systemd, can build an RPM of itself from its own checkout with
rpm.package(source_tree = "."). Buck rejects that as soon as a subdirectory has a BUCK file of its own,because a directory source can't include another Buck package.
project.source_tree()lists the files of the project instead, the way the prelude's source listing does.Every other BUCK file in the project calls
project.source_listing()to list its own files. The build readsthe project directory in place, with the listed files as its inputs.
The first three commits fix what a build of the project root hits: an in-place spec, the overlay over
buck-outand an unset[tine] dev. The fourth makeshas_files()find files below nested dot directorieswith the glob patterns that the listing uses. The last commit lets
[tine] dev = "."select a dev build ofthe tree.