Skip to contentSkip to conversation

cpupower: add checks for xgettext and msgfmt

PATCH Superseded Siddharth Menon 3 participants 4 messages Oct 15, 2024 CPU power monitoring

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpupower: add checks for xgettext and msgfmt

Check whether xgettext and msgfmt are available on the system before attempting to generate the .pot and .gmo files and generate. In case of missing dependency, generate error message directing user to install the necessary package.

---
 tools/power/cpupower/Makefile | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
tools/power/cpupower/Makefile +11 -3
index 6c02f401069e..38e7daacecf4 100644
@@ -220,12 +220,20 @@ endif
 
 $(OUTPUT)po/$(PACKAGE).pot: $(UTIL_SRC)
 	$(ECHO) "  GETTEXT " $@
-	$(QUIET) xgettext --default-domain=$(PACKAGE) --add-comments \
-		--keyword=_ --keyword=N_ $(UTIL_SRC) -p $(@D) -o $(@F)
+	$(QUIET) if ! command -v xgettext > /dev/null; then \
+		echo "Error: gettext not found. Please install gettext."; \
+	else \
+		xgettext --default-domain=$(PACKAGE) --add-comments \
+		--keyword=_ --keyword=N_ $(UTIL_SRC) -p $(@D) -o $(@F); \
+	fi
 
 $(OUTPUT)po/%.gmo: po/%.po
 	$(ECHO) "  MSGFMT  " $@
-	$(QUIET) msgfmt -o $@ po/$*.po
+	$(QUIET) if ! command -v msgfmt > /dev/null; then \
+		echo "Error: msgfmt not found. Make sure gettext is set up correctly."; \
+	else \
+		msgfmt -o $@ po/$*.po; \
+	fi
 
 create-gmo: ${GMO_FILES}
 
Signature · 1 line
2.39.5
maintainer
#1 lore raw
Quoted 4 lines · Siddharth Menon

Check whether xgettext and msgfmt are available on the system before attempting to generate the .pot and .gmo files and generate. In case of missing dependency, generate error message directing user to install the necessary package.

Thank you for your patch. Tried a quick few tests by running make without gettext installed.

tools/power/cpupower/Makefile endif · line 228

Quoted 10 lines

$(OUTPUT)po/$(PACKAGE).pot: $(UTIL_SRC)

tools/power/cpupower/Makefile +6 -2
 	$(ECHO) "  GETTEXT " $@
-	$(QUIET) xgettext --default-domain=$(PACKAGE) --add-comments \
-		--keyword=_ --keyword=N_ $(UTIL_SRC) -p $(@D) -o $(@F)
+	$(QUIET) if ! command -v xgettext > /dev/null; then \
+		echo "Error: gettext not found. Please install gettext."; \
+	else \
+		xgettext --default-domain=$(PACKAGE) --add-comments \
+		--keyword=_ --keyword=N_ $(UTIL_SRC) -p $(@D) -o $(@F); \
+	fi

I tested this on a Fedora 40 server. I was not able to get this message to print despite xgettext not being in the path.

tools/power/cpupower/Makefile endif · line 236

Quoted 9 lines

$(OUTPUT)po/%.gmo: po/%.po

tools/power/cpupower/Makefile +5 -1
 	$(ECHO) "  MSGFMT  " $@
-	$(QUIET) msgfmt -o $@ po/$*.po
+	$(QUIET) if ! command -v msgfmt > /dev/null; then \
+		echo "Error: msgfmt not found. Make sure gettext is set up correctly."; \
+	else \
+		msgfmt -o $@ po/$*.po; \
+	fi

I was able to get this to print without the gettext pkg being installed and it did not print with it installed. This ran fine.

Signature · 4 lines
Sincerely,
John Wyatt
Software Engineer, Core Kernel
Red Hat
author
#2 lore raw
Quoted 3 lines · John B. Wyatt IV

I tested this on a Fedora 40 server. I was not able to get this message to print despite xgettext not being in the path.

Thank you for testing out my patch. The .pot file for cpupower is required in order to enter this code block.

Should I send in another patch to generate cpupower.pot in the makefile itself?

Resending my previous response as I accidentally left text-only mode disabled.

--
Sincerely,
Siddharth Menon

maintainer
#3 lore raw
Quoted 4 lines · Sid
Quoted 3 lines · John B. Wyatt IV

I tested this on a Fedora 40 server. I was not able to get this message to print despite xgettext not being in the path.

Quoted 9 lines

Thank you for testing out my patch. The .pot file for cpupower is required in order to enter this code block.

Should I send in another patch to generate cpupower.pot in the makefile itself?

Resending my previous response as I accidentally left text-only mode disabled.

As mentioned earlier multiple error messages clutter the output. How about the following simpler fix:

===========================================================================

tools/power/cpupower/Makefile +12 -0
index 6c02f401069e..d1171385b552 100644
@@ -218,17 +218,28 @@ else
 endif
        $(QUIET) $(STRIPCMD) $@
 
+ifeq (, $(shell which xgettext))
+$(warning "Install xgettext to generate GNU gettext Language Translations")
+else
 $(OUTPUT)po/$(PACKAGE).pot: $(UTIL_SRC)
        $(ECHO) "  GETTEXT " $@
        $(QUIET) xgettext --default-domain=$(PACKAGE) --add-comments \
                --keyword=_ --keyword=N_ $(UTIL_SRC) -p $(@D) -o $(@F)
+endif
 
+ifeq (, $(shell which msgfmt))
+$(warning "Install msgfmt to generate GNU gettext Language Translations")
+else
 $(OUTPUT)po/%.gmo: po/%.po
        $(ECHO) "  MSGFMT  " $@
        $(QUIET) msgfmt -o $@ po/$*.po
+endif
 
 create-gmo: ${GMO_FILES}
 
+ifeq (, $(shell which msgmerge))
+$(warning "Install msgmerge to generate GNU gettext Language Translations")
+else
 update-po: $(OUTPUT)po/$(PACKAGE).pot
        $(ECHO) "  MSGMRG  " $@
        $(QUIET) @for HLANG in $(LANGUAGES); do \
@@ -241,6 +252,7 @@ update-po: $(OUTPUT)po/$(PACKAGE).pot
                        rm -f $(OUTPUT)po/$$HLANG.new.po; \
                fi; \
        done;
+endif
 
 compile-bench: $(OUTPUT)libcpupower.so.$(LIB_MAJ)
        @V=$(V) confdir=$(confdir) $(MAKE) -C bench O=$(OUTPUT)

===========================================================================