Add 'update_hash' and 'list' to tool/ports

Issue #1082
This commit is contained in:
Norman Feske 2014-05-27 12:07:42 +02:00 committed by Christian Helmuth
parent 24f97f9593
commit acf00c29c3
8 changed files with 202 additions and 110 deletions

27
tool/ports/list Executable file
View File

@ -0,0 +1,27 @@
#!/usr/bin/make -f
#
# \brief Tool for listing ports
# \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
#
GENODE_DIR := $(realpath $(dir $(MAKEFILE_LIST))/../..)
include $(GENODE_DIR)/tool/ports/mk/front_end.inc
usage:
@$(ECHO)
@$(ECHO) "--- list available ports ---"
@$(ECHO) "usage: list"
@$(ECHO)
include $(PORT)
$(TARGET):
$(VERBOSE)for i in $(sort $(notdir $(_PORTS:.port=))); do\
echo $$i; done

View File

@ -0,0 +1,24 @@
#
# \brief Check validity of user input
# \author Norman Feske
# \date 2014-05-27
#
ifeq ($(ARGUMENT),)
$(TARGET): missing_argument
missing_argument: usage
@$(ECHO) "Error: Missing port name as argument"; false
endif
ifneq ($(words $(ARGUMENT)),1)
$(TARGET): too_many_arguments
too_many_arguments: usage
@$(ECHO) "Error: Too many arguments specified, expecting one argument"; false
endif
ifeq ($(PORT),)
$(TARGET): nonexisting_port
nonexisting_port:
@$(ECHO) "Error: Port $(PORT_NAME) does not exist"; false
endif

23
tool/ports/mk/common.inc Normal file
View File

@ -0,0 +1,23 @@
#
# \brief Common environment
# \author Norman Feske
# \date 2014-05-27
#
SHELL := bash
VERBOSE ?= @
ECHO := echo -e
HASHSUM := sha1sum
BRIGHT_COL ?= \033[01;33m
DARK_COL ?= \033[00;33m
DEFAULT_COL ?= \033[0m
MSG_PREFIX := $(ECHO) "$(DARK_COL)$(notdir $(PORT:.port=)) $(DEFAULT_COL)"
MSG_DOWNLOAD := $(MSG_PREFIX)"download "
MSG_APPLY := $(MSG_PREFIX)"apply "
MSG_UPDATE := $(MSG_PREFIX)"update "
MSG_INSTALL := $(MSG_PREFIX)"install "
MSG_GENERATE := $(MSG_PREFIX)"generate "
MSG_EXTRACT := $(MSG_PREFIX)"extract "

View File

@ -0,0 +1,51 @@
#
# \brief Common front-end code shared among different ports tools
# \author Norman Feske
# \date 2014-05-27
#
include $(GENODE_DIR)/tool/ports/mk/common.inc
#
# Always execute the $(TARGET) rule regardless of the supplied command-line
# argument
#
TARGET := $(MAKECMDGOALS) default
$(MAKECMDGOALS) default:
# the single argument is the name of the port to prepare
ARGUMENT := $(MAKECMDGOALS)
PORT_NAME := $(firstword $(ARGUMENT))
# compound directory where all 3rd-party source codes are installed
CONTRIB_DIR ?= $(GENODE_DIR)/contrib
# list of all repositories located at '<genode-dir>/repos/'
REPOSITORIES ?= $(shell find $(GENODE_DIR)/repos -follow -mindepth 1 -maxdepth 1 -type d)
# list of all repositories that contain ports of 3rd-party source code
_REP_PORTS_DIRS := $(wildcard $(addsuffix /ports,$(REPOSITORIES)))
# list of all available ports
_PORTS := $(foreach DIR,$(_REP_PORTS_DIRS),$(wildcard $(DIR)/*.port))
# port file to use
PORT := $(filter %/$(PORT_NAME).port,$(_PORTS))
# repository that contains the port description, used to look up patch files
REP_DIR := $(realpath $(dir $(PORT))/..)
# read hash that uniquely identifies the version to install
HASH_FILE := $(wildcard $(PORT:.port=.hash))
HASH := $(if $(HASH_FILE),$(shell cat $(HASH_FILE)),)
# path to hash file relative to '<genode-dir>/repos', used for error messages
_REL_HASH_FILE := $(notdir $(REP_DIR))/ports/$(notdir $(PORT))
# directory where to install the port
PORT_DIR := $(CONTRIB_DIR)/$(PORT_NAME)-$(HASH)
# path to hash file generated during installation
PORT_HASH_FILE := $(PORT_DIR)/$(PORT_NAME).hash
# vi: set ft=make :

35
tool/ports/mk/hash.inc Normal file
View File

@ -0,0 +1,35 @@
#
# \brief Utilities for generating and checking port hashes
# \author Norman Feske
# \date 2014-05-27
#
#
# The hash depends on the content of the port description file and the
# patches originating from REP_DIR. Patches that are downloaded are already
# captured by the hash sums of the downloaded files, which are declared in the
# port description file.
#
# During development when the files of MAKEFILE_LIST often change, the
# keeping all port hashes up to date is an inconvenience. By setting
# STRICT_HASH to 'no', the MAKEFILE_LIST can be exluded.
#
_PATCHES_IN_REP_DIR := $(foreach P,$(PATCHES),$(wildcard $(REP_DIR)/$(P)))
HASH_INPUT += $(_PATCHES_IN_REP_DIR) $(PORT)
ifneq ($(STRICT_HASH),no)
HASH_INPUT += $(MAKEFILE_LIST)
endif
$(_DST_HASH_FILE): $(HASH_INPUT) $(MAKEFILE_LIST)
@$(MSG_GENERATE)$(notdir $@)
$(VERBOSE)cat $(HASH_INPUT) | $(HASHSUM) | sed "s/ .*//" > $@
_check_hash: $(_DST_HASH_FILE)
ifneq ($(CHECK_HASH),no)
$(VERBOSE)diff $< $(HASH_FILE) > /dev/null ||\
($(ECHO) "Error: $(_REL_HASH_FILE) is out of date, expected" `cat $<` ""; false)
endif

View File

@ -41,24 +41,9 @@ _prefer = $(if $1,$1,$2)
include $(PORT) include $(PORT)
# #
# Common environment # Include common definitions
# #
SHELL := bash include $(GENODE_DIR)/tool/ports/mk/common.inc
VERBOSE ?= @
ECHO := echo -e
HASHSUM := sha1sum
BRIGHT_COL ?= \033[01;33m
DARK_COL ?= \033[00;33m
DEFAULT_COL ?= \033[0m
MSG_PREFIX := $(ECHO) "$(DARK_COL)$(notdir $(PORT:.port=)) $(DEFAULT_COL)"
MSG_DOWNLOAD := $(MSG_PREFIX)"download "
MSG_APPLY := $(MSG_PREFIX)"apply "
MSG_UPDATE := $(MSG_PREFIX)"update "
MSG_INSTALL := $(MSG_PREFIX)"install "
MSG_GENERATE := $(MSG_PREFIX)"generate "
MSG_EXTRACT := $(MSG_PREFIX)"extract "
# #
# Assertion for the presence of a LICENSE and VERSION declarations in the port # Assertion for the presence of a LICENSE and VERSION declarations in the port
@ -76,9 +61,6 @@ version_undefined:
@$(ECHO) "Error: Version undefined"; false @$(ECHO) "Error: Version undefined"; false
endif endif
_PATCHES_IN_REP_DIR := $(foreach P,$(PATCHES),$(wildcard $(REP_DIR)/$(P)))
_DST_HASH_FILE := $(notdir $(PORT:.port=)).hash _DST_HASH_FILE := $(notdir $(PORT:.port=)).hash
@ -94,30 +76,7 @@ _dirs: $(DOWNLOADS)
## Generate the HASH file ## Generate the HASH file
## ##
# The hash depends on the content of the port description file and the include $(GENODE_DIR)/tool/ports/mk/hash.inc
# patches originating from REP_DIR. Patches that are downloaded are already
# captured by the hash sums of the downloaded files, which are declared in the
# port description file.
#
# During development when the files of MAKEFILE_LIST often change, the
# keeping all port hashes up to date is an inconvenience. By setting
# STRICT_HASH to 'no', the MAKEFILE_LIST can be exluded.
#
HASH_INPUT += $(_PATCHES_IN_REP_DIR) $(PORT)
ifneq ($(STRICT_HASH),no)
HASH_INPUT += $(MAKEFILE_LIST)
endif
$(_DST_HASH_FILE): $(HASH_INPUT) $(MAKEFILE_LIST)
@$(MSG_GENERATE)$(notdir $@)
$(VERBOSE)cat $(HASH_INPUT) | $(HASHSUM) | sed "s/ .*//" > $@
_check_hash: $(_DST_HASH_FILE)
ifneq ($(CHECK_HASH),no)
$(VERBOSE)diff $< $(HASH_FILE) > /dev/null ||\
($(ECHO) "Error: $(_REL_HASH_FILE) is out of date, expected" `cat $<` ""; false)
endif
## ##

View File

@ -6,77 +6,14 @@
# \date 2014-05-07 # \date 2014-05-07
# #
VERBOSE ?= @
ECHO := echo -e
#
# Always execute the $(TARGET) rule regardless of the supplied command-line
# argument
#
TARGET := $(MAKECMDGOALS) default
$(MAKECMDGOALS) default:
# the single argument is the name of the port to prepare
ARGUMENT := $(MAKECMDGOALS)
PORT_NAME := $(firstword $(ARGUMENT))
# #
# Determine Genode base directory based on the known location of the # Determine Genode base directory based on the known location of the
# 'create_builddir' tool within the Genode source tree # 'create_builddir' tool within the Genode source tree
# #
GENODE_DIR ?= $(realpath $(dir $(MAKEFILE_LIST))/../..) export GENODE_DIR := $(realpath $(dir $(MAKEFILE_LIST))/../..)
# compound directory where all 3rd-party source codes are installed include $(GENODE_DIR)/tool/ports/mk/front_end.inc
CONTRIB_DIR ?= $(GENODE_DIR)/contrib include $(GENODE_DIR)/tool/ports/mk/check_port_arg.inc
# list of all repositories located at '<genode-dir>/repos/'
REPOSITORIES ?= $(shell find $(GENODE_DIR)/repos -follow -mindepth 1 -maxdepth 1 -type d)
# list of all repositories that contain ports of 3rd-party source code
_REP_PORTS_DIRS := $(wildcard $(addsuffix /ports,$(REPOSITORIES)))
# list of all available ports
_PORTS := $(foreach DIR,$(_REP_PORTS_DIRS),$(wildcard $(DIR)/*.port))
# port file to use
PORT := $(filter %/$(PORT_NAME).port,$(_PORTS))
# repository that contains the port description, used to look up patch files
REP_DIR := $(realpath $(dir $(PORT))/..)
# read hash that uniquely identifies the version to install
HASH_FILE := $(wildcard $(PORT:.port=.hash))
HASH := $(if $(HASH_FILE),$(shell cat $(HASH_FILE)),)
# path to hash file relative to '<genode-dir>/repos', used for error messages
_REL_HASH_FILE := $(notdir $(REP_DIR))/ports/$(notdir $(PORT))
# directory where to install the port
PORT_DIR := $(CONTRIB_DIR)/$(PORT_NAME)-$(HASH)
# path to hash file generated during installation
PORT_HASH_FILE := $(PORT_DIR)/$(PORT_NAME).hash
#
# Check validity of user input
#
ifeq ($(ARGUMENT),)
$(TARGET): missing_argument
missing_argument: usage
@$(ECHO) "Error: Missing port name as argument"; false
endif
ifneq ($(words $(ARGUMENT)),1)
$(TARGET): too_many_arguments
too_many_arguments: usage
@$(ECHO) "Error: Too many arguments specified, expecting one argument"; false
endif
ifeq ($(PORT),)
$(TARGET): nonexisting_port
nonexisting_port:
@$(ECHO) "Error: Port $(PORT_NAME) does not exist"; false
endif
ifeq ($(HASH),) ifeq ($(HASH),)
$(TARGET): nonexisting_hash $(TARGET): nonexisting_hash

36
tool/ports/update_hash Executable file
View File

@ -0,0 +1,36 @@
#!/usr/bin/make -f
#
# \brief Tool for updating the hash file of a port
# \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
#
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
usage:
@$(ECHO)
@$(ECHO) "--- update hash file of a port ---"
@$(ECHO) "usage: update_hash <port-name>"
@$(ECHO)
include $(PORT)
_DST_HASH_FILE := $(HASH_FILE)
# XXX remove this line when the tool has stabilized
STRICT_HASH ?= no
include $(GENODE_DIR)/tool/ports/mk/hash.inc
.PHONY: $(_DST_HASH_FILE)
$(TARGET): $(_DST_HASH_FILE)