Skip to content

Commit 5d105fb

Browse files
committed
depends: Switch libmultiprocess packages to use local git subtree
With newly introduced libmultiprocess subtree, there's no need for depends system to download and track changes to the upstream repository. Note that adding the libmultiprocess subtree does not allow dropping libmultiprocess packages from the depends build, because libmultiprocess includes a code generation tool called mpgen, and in cross-compiled builds, bitcoin core's cmake build system doesn't have access to a native toolchain and can't build mpgen itself, so the depends system (or the native environment if not using depends) needs to supply it.
1 parent 9b35518 commit 5d105fb

File tree

4 files changed

+52
-5
lines changed

4 files changed

+52
-5
lines changed

depends/funcs.mk

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,33 @@ define fetch_file
3939
$(call fetch_file_inner,$(1),$(FALLBACK_DOWNLOAD_PATH),$(3),$(4),$(5))))
4040
endef
4141

42+
# Shell script to create a source tarball in $(1)_source from local directory
43+
# $(1)_local_dir instead of downloading remote sources. Tarball is recreated if
44+
# any paths in the local directory have a newer mtime, and checksum of the
45+
# tarball is saved to $(1)_fetched and returned as output.
46+
define fetch_local_dir_sha256
47+
if ! [ -f $($(1)_source) ] || [ -n "$$(find $($(1)_local_dir) -newer $($(1)_source) | head -n1)" ]; then \
48+
mkdir -p $(dir $($(1)_source)) && \
49+
$(build_TAR) -c -f $($(1)_source) -C $($(1)_local_dir) . && \
50+
rm -f $($(1)_fetched); \
51+
fi && \
52+
if ! [ -f $($(1)_fetched) ] || [ -n "$$(find $($(1)_source) -newer $($(1)_fetched))" ]; then \
53+
mkdir -p $(dir $($(1)_fetched)) && \
54+
cd $($(1)_source_dir) && \
55+
$(build_SHA256SUM) $($(1)_all_sources) > $($(1)_fetched); \
56+
fi && \
57+
cut -d" " -f1 $($(1)_fetched)
58+
endef
59+
4260
define int_get_build_recipe_hash
4361
$(eval $(1)_patches_path?=$(PATCHES_PATH)/$(1))
4462
$(eval $(1)_all_file_checksums:=$(shell $(build_SHA256SUM) $(meta_depends) packages/$(1).mk $(addprefix $($(1)_patches_path)/,$($(1)_patches)) | cut -d" " -f1))
63+
# If $(1)_local_dir is set, create a tarball of the local directory contents to
64+
# use as the source of the package, and include a hash of the tarball in the
65+
# package id, so if directory contents change, the package and packages
66+
# depending on it will be rebuilt.
67+
$(if $($(1)_local_dir),$(eval $(1)_sha256_hash:=$(shell $(call fetch_local_dir_sha256,$(1)))))
68+
$(if $($(1)_local_dir),$(eval $(1)_all_file_checksums+=$($(1)_sha256_hash)))
4569
$(eval $(1)_recipe_hash:=$(shell echo -n "$($(1)_all_file_checksums)" | $(build_SHA256SUM) | cut -d" " -f1))
4670
endef
4771

@@ -64,10 +88,19 @@ $(1)_cached:=$(BASE_CACHE)/$(host)/$(1)/$(1)-$($(1)_version)-$($(1)_build_id).ta
6488
$(1)_build_log:=$(BASEDIR)/$(1)-$($(1)_version)-$($(1)_build_id).log
6589
endef
6690

91+
# Convert a string to a human-readable filename, replacing dot, slash, and space
92+
# characters that could cause problems with dashes and collapsing them.
93+
define int_friendly_file_name
94+
$(subst $(null) $(null),-,$(strip $(subst ., ,$(subst /, ,$(1)))))
95+
endef
96+
6797
define int_get_build_properties
6898
$(1)_build_subdir?=.
6999
$(1)_download_file?=$($(1)_file_name)
70100
$(1)_source_dir:=$(SOURCES_PATH)
101+
# If $(1)_file_name is empty and $(1)_local_dir is nonempty, set file name to a
102+
# .tar file with a friendly filename named after the directory path.
103+
$(if $($(1)_file_name),,$(if $($(1)_local_dir),$(eval $(1)_file_name:=$(call int_friendly_file_name,$($(1)_local_dir)).tar)))
71104
$(1)_source:=$$($(1)_source_dir)/$($(1)_file_name)
72105
$(1)_download_dir:=$(base_download_dir)/$(1)-$($(1)_version)
73106
$(1)_prefixbin:=$($($(1)_type)_prefix)/bin/

depends/packages.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ General tips:
1111
[below](#secondary-dependencies) for more details.
1212

1313
## Identifiers
14-
Each package is required to define at least these variables:
14+
If package does not define a `$(package)_local_dir` variable, it is required to
15+
define these variables:
1516

1617
$(package)_version:
1718
Version of the upstream library or program. If there is no version, a
@@ -28,6 +29,9 @@ Each package is required to define at least these variables:
2829
$(package)_sha256_hash:
2930
The sha256 hash of the upstream file
3031

32+
If a package does define a `$(package)_local_dir` variable, the above variables
33+
are not required and will be ignored.
34+
3135
These variables are optional:
3236

3337
$(package)_build_subdir:
@@ -48,6 +52,18 @@ These variables are optional:
4852
Any extra files that will be fetched via $(package)_fetch_cmds. These are
4953
specified so that they can be fetched and verified via 'make download'.
5054

55+
## Local packages
56+
57+
If a package defines a `$(package)_local_dir` variable, the specified directory
58+
will be treated as a download source, and a tarball of its contents will be
59+
saved to `sources/`. A hash of the tarball will also become part of the package
60+
build id, so if the directory contents change, the package and everything
61+
depending on it will be rebuilt. For efficiency, the tarball is cached once it
62+
has been created, but if the local directory is touched, it will be rebuilt.
63+
64+
Local packages can be useful for using git submodules or subtrees to manage
65+
package sources, or for testing local changes that are not available to
66+
download from an external source.
5167

5268
## Build Variables:
5369
After defining the main identifiers, build variables may be added or customized

depends/packages/libmultiprocess.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package=libmultiprocess
22
$(package)_version=$(native_$(package)_version)
3+
$(package)_local_dir=$(native_$(package)_local_dir)
34
$(package)_download_path=$(native_$(package)_download_path)
45
$(package)_file_name=$(native_$(package)_file_name)
56
$(package)_sha256_hash=$(native_$(package)_sha256_hash)

depends/packages/native_libmultiprocess.mk

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package=native_libmultiprocess
2-
$(package)_version=35944ffd23fa26652b82210351d50e896ce16c8f
3-
$(package)_download_path=https://github.com/bitcoin-core/libmultiprocess/archive
4-
$(package)_file_name=$($(package)_version).tar.gz
5-
$(package)_sha256_hash=b542f270c076d0287c124e7f97b21ab7e32b979ff182491c157c2da9dec723c4
2+
$(package)_local_dir=../src/ipc/libmultiprocess
63
$(package)_dependencies=native_capnp
74

85
define $(package)_config_cmds

0 commit comments

Comments
 (0)