From b039608e95198543ce06f186fe1497e19055757a Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Wed, 3 Feb 2016 17:48:54 +0100 Subject: [PATCH] prepare_port: prepare multiple ports at once The tool/prepare_port tool is now able to handle a list of ports that shall be prepared. Additionally, one may state the number of ports that shall be prepared in parallel at a max by using the -j parameter. If -j is not set by the user, the tool acts as with -j1. The previous implementation of the tool that prepares only a single port was moved to tool/ports/mk/prepare_single_port.mk and acts as back end to the new prepare_port tool. The interface of the new prepare_port tool is backwards compatible. When called for one port only, the behavior is the same as when calling tool/ports/mk/prepare_single_port.mk directly. Removes "usage" rule from prepare_single_port.mk. Removes shebang line from prepare_single_port.mk. Ref #1872 --- tool/ports/mk/install.mk | 2 + tool/ports/mk/prepare_single_port.mk | 62 +++++++++++++++++++++ tool/ports/prepare_port | 81 ++++++++-------------------- 3 files changed, 86 insertions(+), 59 deletions(-) create mode 100755 tool/ports/mk/prepare_single_port.mk diff --git a/tool/ports/mk/install.mk b/tool/ports/mk/install.mk index 8e4287059..4c0f4bbde 100644 --- a/tool/ports/mk/install.mk +++ b/tool/ports/mk/install.mk @@ -27,6 +27,8 @@ check_tool = $(if $(shell which $(1)),,$(error Need to have '$(1)' installed.)) default: +.NOTPARALLEL: default + # repository that contains the port description, used to look up patch files REP_DIR := $(realpath $(dir $(PORT))/..) diff --git a/tool/ports/mk/prepare_single_port.mk b/tool/ports/mk/prepare_single_port.mk new file mode 100755 index 000000000..fe903ff98 --- /dev/null +++ b/tool/ports/mk/prepare_single_port.mk @@ -0,0 +1,62 @@ +# +# \brief Tool for downloading and patching 3rd-party source code +# \author Norman Feske +# \date 2014-05-07 +# + +# +# Determine Genode base directory based on the known location of the +# 'create_builddir' tool within the Genode source tree +# +export GENODE_DIR := $(realpath $(dir $(MAKEFILE_LIST))/../../..) + +include $(GENODE_DIR)/tool/ports/mk/front_end.inc +include $(GENODE_DIR)/tool/ports/mk/check_port_arg.inc + +ifeq ($(HASH),) +$(TARGET): nonexisting_hash +nonexisting_hash: + @$(ECHO) "Error: Port $(PORT_NAME) lacks a valid hash"; false +endif + +# +# Default rule that triggers the actual preparation steps +# +$(TARGET): _check_integrity + +_check_integrity : _install_in_port_dir +ifneq ($(CHECK_HASH),no) + $(VERBOSE)diff $(PORT_HASH_FILE) $(HASH_FILE) > /dev/null ||\ + ($(ECHO) "Error: $(_REL_HASH_FILE) is out of date, expected" `cat $(PORT_HASH_FILE)` ""; false) +endif + +# +# During the preparatio steps, the port directory is renamed. We use the suffix +# ".incomplete" to mark this transient state of the port directory. +# +_install_in_port_dir: $(PORT_DIR) + @#\ + # if the transient directory already exists, reuse it as it may contain\ + # finished steps such as downloads. By reusing it, we avoid downloading\ + # the same files again and again while working on a port. However, in this\ + # case, we already have created an empty port directory via the $(PORT_DIR)\ + # rule below. To avoid having both the port directory and the transient\ + # port directory present, remove the just-created port directory.\ + # + $(VERBOSE)(test -d $(PORT_DIR).incomplete && rmdir $(PORT_DIR)) || true + @#\ + # If no transient directory exists, rename the port directory accordingly.\ + # + $(VERBOSE)test -d $(PORT_DIR).incomplete || mv --force $(PORT_DIR) $(PORT_DIR).incomplete + $(VERBOSE)$(MAKE) --no-print-directory \ + -f $(GENODE_DIR)/tool/ports/mk/install.mk \ + -C $(PORT_DIR).incomplete \ + PORT=$(PORT) VERBOSE=$(VERBOSE) + @#\ + # The preparation finished successfully. So we can rename the transient\ + # directory to the real one.\ + # + $(VERBOSE)mv $(PORT_DIR).incomplete $(PORT_DIR) + +$(PORT_DIR): + $(VERBOSE)mkdir -p $@ diff --git a/tool/ports/prepare_port b/tool/ports/prepare_port index 07e5179d3..b390d8039 100755 --- a/tool/ports/prepare_port +++ b/tool/ports/prepare_port @@ -1,70 +1,33 @@ #!/usr/bin/make -f # -# \brief Tool for downloading and patching 3rd-party source code -# \author Norman Feske -# \date 2014-05-07 +# \brief Tool for preparing and updating ports +# \author Martin Stein +# \date 2016-02-03 # -# -# Determine Genode base directory based on the known location of the -# 'create_builddir' tool within the Genode source tree -# +ifndef VERBOSE +MAKEFLAGS += --no-print-directory +endif + export GENODE_DIR := $(realpath $(dir $(MAKEFILE_LIST))/../..) -include $(GENODE_DIR)/tool/ports/mk/front_end.inc -include $(GENODE_DIR)/tool/ports/mk/check_port_arg.inc - -ifeq ($(HASH),) -$(TARGET): nonexisting_hash -nonexisting_hash: - @$(ECHO) "Error: Port $(PORT_NAME) lacks a valid hash"; false -endif - usage: - @$(ECHO) - @$(ECHO) "--- download and patch 3rd-party source code ---" - @$(ECHO) "usage: prepare_port [CHECK_HASH=no]" - @$(ECHO) + @echo + @echo "Tool for preparing and updating ports" + @echo + @echo "usage:" + @echo + @echo " $(notdir $(MAKEFILE_LIST)) [-j] " + @echo + @echo " -j prepare ports in parallel at a max, default is 1" + @echo + @echo " whitespace-separated list of ports" + @echo -# -# Default rule that triggers the actual preparation steps -# -$(TARGET): _check_integrity +TARGETS = $(sort $(MAKECMDGOALS)) -_check_integrity : _install_in_port_dir -ifneq ($(CHECK_HASH),no) - $(VERBOSE)diff $(PORT_HASH_FILE) $(HASH_FILE) > /dev/null ||\ - ($(ECHO) "Error: $(_REL_HASH_FILE) is out of date, expected" `cat $(PORT_HASH_FILE)` ""; false) -endif +.PHONY: $(TARGETS) -# -# During the preparatio steps, the port directory is renamed. We use the suffix -# ".incomplete" to mark this transient state of the port directory. -# -_install_in_port_dir: $(PORT_DIR) - @#\ - # if the transient directory already exists, reuse it as it may contain\ - # finished steps such as downloads. By reusing it, we avoid downloading\ - # the same files again and again while working on a port. However, in this\ - # case, we already have created an empty port directory via the $(PORT_DIR)\ - # rule below. To avoid having both the port directory and the transient\ - # port directory present, remove the just-created port directory.\ - # - $(VERBOSE)(test -d $(PORT_DIR).incomplete && rmdir $(PORT_DIR)) || true - @#\ - # If no transient directory exists, rename the port directory accordingly.\ - # - $(VERBOSE)test -d $(PORT_DIR).incomplete || mv --force $(PORT_DIR) $(PORT_DIR).incomplete - $(VERBOSE)$(MAKE) --no-print-directory \ - -f $(GENODE_DIR)/tool/ports/mk/install.mk \ - -C $(PORT_DIR).incomplete \ - PORT=$(PORT) VERBOSE=$(VERBOSE) - @#\ - # The preparation finished successfully. So we can rename the transient\ - # directory to the real one.\ - # - $(VERBOSE)mv $(PORT_DIR).incomplete $(PORT_DIR) - -$(PORT_DIR): - $(VERBOSE)mkdir -p $@ +$(TARGETS): + @$(MAKE) -f $(GENODE_DIR)/tool/ports/mk/prepare_single_port.mk $@