From patchwork Wed Oct 9 14:56:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13828581 Received: from fout-a3-smtp.messagingengine.com (fout-a3-smtp.messagingengine.com [103.168.172.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1D421DF730 for ; Wed, 9 Oct 2024 14:56:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728485816; cv=none; b=Y6DKEArWXmCN61jn1I1jkUJ1O5UqtA+GdAmO34/6XrvY9aBdd4+zacFbo8C9zRvAt9b3HmTgrMpA5BTUt8diP3u3v0KEruQq9qy/ZnwISs+WOOXQulML9V16VvccLWmcUablK2BA2yk5ESkCW/CnZR6UXYsrNCunAdi05+U6eOc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728485816; c=relaxed/simple; bh=SccM7wx0WnBJFIwkTMNFkPtdsI/iO7mPhqZcdufyK78=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=htzD+CMNgWtQTh9sgpYEv9Mrqj1d9sOx5RmPENq/e2WQOjTH49tVpM794uaUFon5AHuouGd0+IYHeTUxu+4JXEKJ18Fo2Gd2Ic+KhVeILgxdb4bEp08fp6mlQJAvfuIMgXx0ORETm0mlz4ExmY82zTmNGgR3NnCGHo3DnMhn7aY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=DmTLxpFw; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=PYsfcZDi; arc=none smtp.client-ip=103.168.172.146 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="DmTLxpFw"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="PYsfcZDi" Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfout.phl.internal (Postfix) with ESMTP id D116B13801BD; Wed, 9 Oct 2024 10:56:53 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Wed, 09 Oct 2024 10:56:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1728485813; x=1728572213; bh=299VxPpkE9 JMx5kPGt38rx7Pp0ANf7pBLEI6RlE8EP4=; b=DmTLxpFw8o6is9xA5JGnB/Wv7e USkJhmWSv6sGCsIaIPNxHt/FSWa3tz2QXcaWda/8dPW2IkCT51/i7zTSFVyNyXmm q9T5ytgmNd04ODZPcXcgPmYEWrrcuuECJNUIRKISgNU7PocqMgAwHzkHdI9OMyjZ 1+ZYmXlxw0OvKFupFcAwuDz59GNKuITNT42ypnSBHI+ew56d4StUZ1yCfcAwMKgY J2vFNWW3q1vwQhgGf/jorrQi0H20VYxUo7tz3mz35REh72e6U82t5xf2ZUDHWe9A ejudxoknBvxqNt7mrdVI1J80aT2hlzg6gqM4cRGzflK41SOlR6+PNyszn3Ug== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1728485813; x=1728572213; bh=299VxPpkE9JMx5kPGt38rx7Pp0AN f7pBLEI6RlE8EP4=; b=PYsfcZDiQhk2hcaufo482w1yNbhMynX8DdfE1dx63Jbv LbXkbr7UhbQrRzGQW19xExnS+5mNjnn4dpzpPMb7sm+G9FpIU3+4mCBTxyTKbyVi uNOgHnqh3KY4kv9KP2xEXv9ztb/mH7e56Pl7co8jSQ/LJY56eUu148H10cUhl9dL q1NBExOrsZGwsbu6mjSM4OTqU4JR0dnSKNHRqGS5uDSr5WoYE4s4HgSaZxIjOQpk KyLAhfEzWJf6tMBbsfEQxBKDPzEt/Xc9eajpFHlD89hGUf4cXyramLB+JKhulknF pJTbVp1IcdkMPiYCZQVBRZCaRC4IpJPNrNjf2KOeZQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdeffedgkeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepvghstghhfigrrhhtiiesghgvnhhtohhordhorhhgpd hrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehp hhhilhhlihhprdifohhougduvdefsehgmhgrihhlrdgtohhmpdhrtghpthhtohepghhith hsthgvrhesphhosghogidrtghomhdprhgtphhtthhopehsuhhnshhhihhnvgesshhunhhs hhhinhgvtghordgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 9 Oct 2024 10:56:52 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 581a9f15 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 9 Oct 2024 14:55:49 +0000 (UTC) Date: Wed, 9 Oct 2024 16:56:51 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Eli Schwartz , Eric Sunshine , Phillip Wood , Junio C Hamano Subject: [RFC PATCH v2 15/24] Makefile: refactor generators to be PWD-independent Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: We have multiple scripts that generate headers from other data. All of these scripts have the assumption built-in that they are executed in the current source directory, which makes them a bit unwieldy to use during out-of-tree builds. This makes them a bit unwieldy to use. Refactor them to instead take the source directory as well as the output file as arguments. Signed-off-by: Patrick Steinhardt --- Makefile | 6 ++--- contrib/buildsystems/CMakeLists.txt | 12 +++------ generate-cmdlist.sh | 42 ++++++++++++++++++----------- generate-configlist.sh | 20 ++++++++++---- generate-hooklist.sh | 15 ++++++++++- 5 files changed, 61 insertions(+), 34 deletions(-) diff --git a/Makefile b/Makefile index cd28f88e1b3..0a7d07c9dfb 100644 --- a/Makefile +++ b/Makefile @@ -2523,17 +2523,17 @@ $(BUILT_INS): git$X config-list.h: generate-configlist.sh config-list.h: Documentation/*config.txt Documentation/config/*.txt - $(QUIET_GEN)$(SHELL_PATH) ./generate-configlist.sh >$@ + $(QUIET_GEN)$(SHELL_PATH) ./generate-configlist.sh . $@ command-list.h: generate-cmdlist.sh command-list.txt command-list.h: $(wildcard Documentation/git*.txt) $(QUIET_GEN)$(SHELL_PATH) ./generate-cmdlist.sh \ $(patsubst %,--exclude-program %,$(EXCLUDED_PROGRAMS)) \ - command-list.txt >$@ + . $@ hook-list.h: generate-hooklist.sh Documentation/githooks.txt - $(QUIET_GEN)$(SHELL_PATH) ./generate-hooklist.sh >$@ + $(QUIET_GEN)$(SHELL_PATH) ./generate-hooklist.sh . $@ SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):\ $(localedir_SQ):$(USE_GETTEXT_SCHEME):$(SANE_TOOL_PATH_SQ):\ diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index 21d6bce26c7..330a3f3504a 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -655,23 +655,17 @@ set(EXCLUSION_PROGS_CACHE ${EXCLUSION_PROGS} CACHE STRING "Programs not built" F if(NOT EXISTS ${CMAKE_BINARY_DIR}/command-list.h OR NOT EXCLUSION_PROGS_CACHE STREQUAL EXCLUSION_PROGS) list(REMOVE_ITEM EXCLUSION_PROGS empty) message("Generating command-list.h") - execute_process(COMMAND ${SH_EXE} ${CMAKE_SOURCE_DIR}/generate-cmdlist.sh ${EXCLUSION_PROGS} command-list.txt - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_FILE ${CMAKE_BINARY_DIR}/command-list.h) + execute_process(COMMAND ${SH_EXE} ${CMAKE_SOURCE_DIR}/generate-cmdlist.sh ${EXCLUSION_PROGS} ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/command-list.h) endif() if(NOT EXISTS ${CMAKE_BINARY_DIR}/config-list.h) message("Generating config-list.h") - execute_process(COMMAND ${SH_EXE} ${CMAKE_SOURCE_DIR}/generate-configlist.sh - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_FILE ${CMAKE_BINARY_DIR}/config-list.h) + execute_process(COMMAND ${SH_EXE} ${CMAKE_SOURCE_DIR}/generate-configlist.sh ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/config.list) endif() if(NOT EXISTS ${CMAKE_BINARY_DIR}/hook-list.h) message("Generating hook-list.h") - execute_process(COMMAND ${SH_EXE} ${CMAKE_SOURCE_DIR}/generate-hooklist.sh - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_FILE ${CMAKE_BINARY_DIR}/hook-list.h) + execute_process(COMMAND ${SH_EXE} ${CMAKE_SOURCE_DIR}/generate-hooklist.sh ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/hook-list.h) endif() include_directories(${CMAKE_BINARY_DIR}) diff --git a/generate-cmdlist.sh b/generate-cmdlist.sh index 205541e0f7f..b923a5aab80 100755 --- a/generate-cmdlist.sh +++ b/generate-cmdlist.sh @@ -64,7 +64,7 @@ define_category_names () { print_command_list () { echo "static struct cmdname_help command_list[] = {" - echo "$1" | + echo "$2" | while read cmd rest do synopsis= @@ -76,7 +76,7 @@ print_command_list () { break ;; esac - done <"Documentation/$cmd.txt" + done <"$1/Documentation/$cmd.txt" printf '\t{ "%s", N_("%s"), 0' "$cmd" "$synopsis" printf " | CAT_%s" $rest @@ -93,18 +93,28 @@ do shift done -commands="$(command_list "$1")" -categories="$(category_list "$commands")" +if test "$#" -ne 2 +then + die "USAGE: $0 " +fi + +SOURCE_DIR="$1" +OUTPUT="$2" + +{ + commands="$(command_list "$SOURCE_DIR"/command-list.txt)" + categories="$(category_list "$commands")" -echo "/* Automatically generated by generate-cmdlist.sh */ -struct cmdname_help { - const char *name; - const char *help; - uint32_t category; -}; -" -define_categories "$categories" -echo -define_category_names "$categories" -echo -print_command_list "$commands" + echo "/* Automatically generated by generate-cmdlist.sh */ + struct cmdname_help { + const char *name; + const char *help; + uint32_t category; + }; + " + define_categories "$categories" + echo + define_category_names "$categories" + echo + print_command_list "$SOURCE_DIR" "$commands" +} >"$OUTPUT" diff --git a/generate-configlist.sh b/generate-configlist.sh index 8692fe5cf4d..512804a1ca1 100755 --- a/generate-configlist.sh +++ b/generate-configlist.sh @@ -1,13 +1,19 @@ #!/bin/sh -echo "/* Automatically generated by generate-configlist.sh */" -echo +SOURCE_DIR="$1" +OUTPUT="$2" + +if test -z "$SOURCE_DIR" || ! test -d "$SOURCE_DIR" || test -z "$OUTPUT" +then + echo "USAGE: $0 " >&2 + exit 1 +fi print_config_list () { cat <"$OUTPUT" diff --git a/generate-hooklist.sh b/generate-hooklist.sh index 2f9f54eb545..0ff2a0b6fbd 100755 --- a/generate-hooklist.sh +++ b/generate-hooklist.sh @@ -2,6 +2,17 @@ # # Usage: ./generate-hooklist.sh >hook-list.h +SOURCE_DIR="$1" +OUTPUT="$2" + +if test -z "$SOURCE_DIR" || ! test -d "$SOURCE_DIR" || test -z "$OUTPUT" +then + echo "USAGE: $0 " >&2 + exit 1 +fi + +{ + cat <"$OUTPUT"