From 96363c652a743aa8ca3ba4fdb2e40d4152571a53 Mon Sep 17 00:00:00 2001 From: jelle Spijker Date: Wed, 19 Oct 2022 01:45:18 +0200 Subject: [PATCH 1/7] Build mo translation files when creating conan package Added a build step which uses the Conan package gettext as a tool_requires to convert the po files to mo files and store these in the resources folder When on Windows the msys2 recipe is used to ensure that we have a bash environment to run gnu gettext Creating the mo files as part of the conan package will ensures that we no longer need to store them in the cura-binary-data and generate them manually. This should result in less risk of human error during the release cycle --- conanfile.py | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/conanfile.py b/conanfile.py index 2dc934e253..32482ccf2f 100644 --- a/conanfile.py +++ b/conanfile.py @@ -4,7 +4,8 @@ from pathlib import Path from jinja2 import Template from conan import ConanFile -from conan.tools.files import copy, rmdir, save +from conan.tools.files import copy, rmdir, save, mkdir +from conan.tools.microsoft import unix_path from conan.tools.env import VirtualRunEnv, Environment from conan.tools.scm import Version from conan.errors import ConanInvalidConfiguration, ConanException @@ -274,6 +275,11 @@ class CuraConan(ConanFile): for req in self._um_data()["internal_requirements"]: self.requires(req) + def build_requirements(self): + if self.settings_build.os == "Windows" and not self.conf.get("tools.microsoft.bash:path", default=False, check_type=bool): + self.tool_requires("msys2/cci.latest") + self.tool_requires("gettext/0.21") + def layout(self): self.folders.source = "." self.folders.build = "venv" @@ -284,7 +290,15 @@ class CuraConan(ConanFile): self.cpp.package.resdirs = ["resources", "plugins", "packaging", "pip_requirements"] # pip_requirements should be the last item in the list def build(self): - pass + if self.settings.os == "Windows": + self.win_bash = True # We need gettext, which requires the bash environment + + for po_file in self.source_path.joinpath("resources", "i18n").glob("**/*.po"): + mo_file = self.build_path.joinpath(po_file.with_suffix('.mo').relative_to(self.source_path)) + mkdir(self, str(unix_path(self, mo_file.parent))) + self.run(f"msgfmt {po_file} -o {mo_file} -f", env="conanbuild") + + self.win_bash = None def generate(self): cura_run_envvars = self._cura_run_env.vars(self, scope = "run") @@ -418,12 +432,13 @@ echo "CURA_VERSION_FULL={{ cura_version_full }}" >> ${{ env_prefix }}GITHUB_ENV entitlements_file = entitlements_file if self.settings.os == "Macos" else "None") def package(self): - self.copy("cura_app.py", src = ".", dst = self.cpp.package.bindirs[0]) - self.copy("*", src = "cura", dst = self.cpp.package.libdirs[0]) - self.copy("*", src = "resources", dst = self.cpp.package.resdirs[0]) - self.copy("*", src = "plugins", dst = self.cpp.package.resdirs[1]) - self.copy("requirement*.txt", src = ".", dst = self.cpp.package.resdirs[-1]) - self.copy("*", src = "packaging", dst = self.cpp.package.resdirs[2]) + copy(self, "cura_app.py", src = self.source_path, dst = self.package_path.joinpath(self.cpp.package.bindirs[0])) + copy(self, "*", src = self.source_path.joinpath("cura"), dst = self.package_path.joinpath(self.cpp.package.libdirs[0])) + copy(self, "*", src = self.source_path.joinpath("resources"), dst = self.package_path.joinpath(self.cpp.package.resdirs[0]), excludes="*.po") + copy(self, "*", src = self.build_path.joinpath("resources"), dst = self.package_path.joinpath(self.cpp.package.resdirs[0])) + copy(self, "*", src = self.source_path.joinpath("plugins"), dst = self.package_path.joinpath(self.cpp.package.resdirs[1])) + copy(self, "requirement*.txt", src = self.source_path, dst = self.package_path.joinpath(self.cpp.package.resdirs[-1])) + copy(self, "*", src = self.source_path.joinpath("packaging"), dst = self.package_path.joinpath(self.cpp.package.resdirs[2])) def package_info(self): self.user_info.pip_requirements = "requirements.txt" From 035815b4210107885d03fea7fe5059dfdfafac7b Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Fri, 21 Oct 2022 17:19:55 +0200 Subject: [PATCH 2/7] Only build mo on Unix Once M4, autoconf and automake are Conan v2 ready this can be reversed --- conanfile.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/conanfile.py b/conanfile.py index 32482ccf2f..9dfe60db81 100644 --- a/conanfile.py +++ b/conanfile.py @@ -291,14 +291,15 @@ class CuraConan(ConanFile): def build(self): if self.settings.os == "Windows": - self.win_bash = True # We need gettext, which requires the bash environment + return + # FIXME: once m4, autoconf, automake are Conan V2 ready self.win_bash = True # We need gettext, which requires the bash environment for po_file in self.source_path.joinpath("resources", "i18n").glob("**/*.po"): mo_file = self.build_path.joinpath(po_file.with_suffix('.mo').relative_to(self.source_path)) mkdir(self, str(unix_path(self, mo_file.parent))) self.run(f"msgfmt {po_file} -o {mo_file} -f", env="conanbuild") - self.win_bash = None + # FIXME: once m4, autoconf, automake are Conan V2 ready self.win_bash = None def generate(self): cura_run_envvars = self._cura_run_env.vars(self, scope = "run") From e400f04319a48577767113932fc7bf27679533f7 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Sun, 23 Oct 2022 15:25:16 +0200 Subject: [PATCH 3/7] Only run gettext in a bash environment Once the msys2 (m4, autoconf, automake) are fixed we can use the msys2 recipe. For now people can use their own bash environment on Windows by setting the tools.microsoft.bash:path and tools.microsoft.bash:subsystem when needed. --- conanfile.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/conanfile.py b/conanfile.py index 9dfe60db81..9476badca6 100644 --- a/conanfile.py +++ b/conanfile.py @@ -276,9 +276,8 @@ class CuraConan(ConanFile): self.requires(req) def build_requirements(self): - if self.settings_build.os == "Windows" and not self.conf.get("tools.microsoft.bash:path", default=False, check_type=bool): - self.tool_requires("msys2/cci.latest") - self.tool_requires("gettext/0.21") + if self.settings_build.os != "Windows" or self.conf.get("tools.microsoft.bash:path", default=False, check_type=bool): + self.tool_requires("gettext/0.21") def layout(self): self.folders.source = "." @@ -290,7 +289,7 @@ class CuraConan(ConanFile): self.cpp.package.resdirs = ["resources", "plugins", "packaging", "pip_requirements"] # pip_requirements should be the last item in the list def build(self): - if self.settings.os == "Windows": + if self.settings_build.os == "Windows" and not self.conf.get("tools.microsoft.bash:path", default=False, check_type=bool): return # FIXME: once m4, autoconf, automake are Conan V2 ready self.win_bash = True # We need gettext, which requires the bash environment @@ -318,6 +317,7 @@ class CuraConan(ConanFile): icon_path = "'{}'".format(Path(self.source_folder, "packaging", self._um_data()["pyinstaller"]["icon"][str(self.settings.os)])).replace("\\", "\\\\"), entitlements_file = entitlements_file if self.settings.os == "Macos" else "None") + def imports(self): self.copy("CuraEngine.exe", root_package = "curaengine", src = "@bindirs", dst = "", keep_path = False) self.copy("CuraEngine", root_package = "curaengine", src = "@bindirs", dst = "", keep_path = False) From 10710fe83874f2ab1726ec5dc955bc7bbac1836a Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Sun, 23 Oct 2022 15:55:56 +0200 Subject: [PATCH 4/7] Update the po files conan install will now update the the po files --- conanfile.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/conanfile.py b/conanfile.py index 9476badca6..e0dd5e9e36 100644 --- a/conanfile.py +++ b/conanfile.py @@ -317,6 +317,13 @@ class CuraConan(ConanFile): icon_path = "'{}'".format(Path(self.source_folder, "packaging", self._um_data()["pyinstaller"]["icon"][str(self.settings.os)])).replace("\\", "\\\\"), entitlements_file = entitlements_file if self.settings.os == "Macos" else "None") + # Update the po files + if self.settings_build.os != "Windows" or self.conf.get("tools.microsoft.bash:path", default = False, check_type = bool): + for po_file in self.source_path.joinpath("resources", "i18n").glob("**/*.po"): + pot_file = self.source_path.joinpath("resources", "i18n", po_file.with_suffix('.pot').name) + mkdir(self, str(unix_path(self, pot_file.parent))) + self.run(f"msgmerge --no-wrap --no-fuzzy-matching -width=140 -o {po_file} {po_file} {pot_file}", env = "conanbuild") + def imports(self): self.copy("CuraEngine.exe", root_package = "curaengine", src = "@bindirs", dst = "", keep_path = False) From f1936dc37ce144ac58ee4c11cf68394d0b545bc8 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Tue, 25 Oct 2022 02:41:35 +0200 Subject: [PATCH 5/7] Ensure that gettext bin can be found --- conanfile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conanfile.py b/conanfile.py index e0dd5e9e36..a39ced56c7 100644 --- a/conanfile.py +++ b/conanfile.py @@ -296,7 +296,7 @@ class CuraConan(ConanFile): for po_file in self.source_path.joinpath("resources", "i18n").glob("**/*.po"): mo_file = self.build_path.joinpath(po_file.with_suffix('.mo').relative_to(self.source_path)) mkdir(self, str(unix_path(self, mo_file.parent))) - self.run(f"msgfmt {po_file} -o {mo_file} -f", env="conanbuild") + self.run(f"msgfmt {po_file} -o {mo_file} -f", env="conanbuild", run_environment=True) # FIXME: once m4, autoconf, automake are Conan V2 ready self.win_bash = None @@ -322,7 +322,7 @@ class CuraConan(ConanFile): for po_file in self.source_path.joinpath("resources", "i18n").glob("**/*.po"): pot_file = self.source_path.joinpath("resources", "i18n", po_file.with_suffix('.pot').name) mkdir(self, str(unix_path(self, pot_file.parent))) - self.run(f"msgmerge --no-wrap --no-fuzzy-matching -width=140 -o {po_file} {po_file} {pot_file}", env = "conanbuild") + self.run(f"msgmerge --no-wrap --no-fuzzy-matching -width=140 -o {po_file} {po_file} {pot_file}", env = "conanbuild", run_environment=True) def imports(self): From fc264133478da9271bc1d40f542a5e5e22b279df Mon Sep 17 00:00:00 2001 From: jelle spijker Date: Wed, 2 Nov 2022 21:16:18 +0100 Subject: [PATCH 6/7] Check against str for conf_info bash path --- conanfile.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/conanfile.py b/conanfile.py index a39ced56c7..88c4289540 100644 --- a/conanfile.py +++ b/conanfile.py @@ -276,7 +276,7 @@ class CuraConan(ConanFile): self.requires(req) def build_requirements(self): - if self.settings_build.os != "Windows" or self.conf.get("tools.microsoft.bash:path", default=False, check_type=bool): + if self.settings_build.os != "Windows" or self.conf.get("tools.microsoft.bash:path", check_type = str): self.tool_requires("gettext/0.21") def layout(self): @@ -289,16 +289,13 @@ class CuraConan(ConanFile): self.cpp.package.resdirs = ["resources", "plugins", "packaging", "pip_requirements"] # pip_requirements should be the last item in the list def build(self): - if self.settings_build.os == "Windows" and not self.conf.get("tools.microsoft.bash:path", default=False, check_type=bool): - return - # FIXME: once m4, autoconf, automake are Conan V2 ready self.win_bash = True # We need gettext, which requires the bash environment + if self.settings_build.os != "Windows" or self.conf.get("tools.microsoft.bash:path", check_type = str): + for po_file in self.source_path.joinpath("resources", "i18n").glob("**/*.po"): + mo_file = self.build_path.joinpath(po_file.with_suffix('.mo').relative_to(self.source_path)) + mkdir(self, str(unix_path(self, mo_file.parent))) + self.run(f"msgfmt {po_file} -o {mo_file} -f", env="conanbuild", run_environment=True) - for po_file in self.source_path.joinpath("resources", "i18n").glob("**/*.po"): - mo_file = self.build_path.joinpath(po_file.with_suffix('.mo').relative_to(self.source_path)) - mkdir(self, str(unix_path(self, mo_file.parent))) - self.run(f"msgfmt {po_file} -o {mo_file} -f", env="conanbuild", run_environment=True) - - # FIXME: once m4, autoconf, automake are Conan V2 ready self.win_bash = None + # FIXME: once m4, autoconf, automake are Conan V2 ready self.win_bash = None def generate(self): cura_run_envvars = self._cura_run_env.vars(self, scope = "run") @@ -318,7 +315,7 @@ class CuraConan(ConanFile): entitlements_file = entitlements_file if self.settings.os == "Macos" else "None") # Update the po files - if self.settings_build.os != "Windows" or self.conf.get("tools.microsoft.bash:path", default = False, check_type = bool): + if self.settings_build.os != "Windows" or self.conf.get("tools.microsoft.bash:path", check_type = str): for po_file in self.source_path.joinpath("resources", "i18n").glob("**/*.po"): pot_file = self.source_path.joinpath("resources", "i18n", po_file.with_suffix('.pot').name) mkdir(self, str(unix_path(self, pot_file.parent))) From 50fad9caf4e6dcb980c94fd497c80ab40df6e00c Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Thu, 3 Nov 2022 07:18:26 +0100 Subject: [PATCH 7/7] Only translate when option devtools is set --- conanfile.py | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/conanfile.py b/conanfile.py index 88c4289540..a122cb85e4 100644 --- a/conanfile.py +++ b/conanfile.py @@ -10,7 +10,7 @@ from conan.tools.env import VirtualRunEnv, Environment from conan.tools.scm import Version from conan.errors import ConanInvalidConfiguration, ConanException -required_conan_version = ">=1.50.0" +required_conan_version = ">=1.52.0" class CuraConan(ConanFile): @@ -276,8 +276,10 @@ class CuraConan(ConanFile): self.requires(req) def build_requirements(self): - if self.settings_build.os != "Windows" or self.conf.get("tools.microsoft.bash:path", check_type = str): - self.tool_requires("gettext/0.21") + if self.options.devtools: + if self.settings.os != "Windows" or self.conf.get("tools.microsoft.bash:path", check_type = str): + # FIXME: once m4, autoconf, automake are Conan V2 ready use self.win_bash and add gettext as base tool_requirement + self.tool_requires("gettext/0.21", force_host_context=True) def layout(self): self.folders.source = "." @@ -289,13 +291,14 @@ class CuraConan(ConanFile): self.cpp.package.resdirs = ["resources", "plugins", "packaging", "pip_requirements"] # pip_requirements should be the last item in the list def build(self): - if self.settings_build.os != "Windows" or self.conf.get("tools.microsoft.bash:path", check_type = str): - for po_file in self.source_path.joinpath("resources", "i18n").glob("**/*.po"): - mo_file = self.build_path.joinpath(po_file.with_suffix('.mo').relative_to(self.source_path)) - mkdir(self, str(unix_path(self, mo_file.parent))) - self.run(f"msgfmt {po_file} -o {mo_file} -f", env="conanbuild", run_environment=True) - - # FIXME: once m4, autoconf, automake are Conan V2 ready self.win_bash = None + if self.options.devtools: + if self.settings.os != "Windows" or self.conf.get("tools.microsoft.bash:path", check_type = str): + # FIXME: once m4, autoconf, automake are Conan V2 ready use self.win_bash and add gettext as base tool_requirement + cpp_info = self.dependencies["gettext"].cpp_info + for po_file in self.source_path.joinpath("resources", "i18n").glob("**/*.po"): + mo_file = self.build_path.joinpath(po_file.with_suffix('.mo').relative_to(self.source_path)) + mkdir(self, str(unix_path(self, mo_file.parent))) + self.run(f"{cpp_info.bindirs[0]}/msgfmt {po_file} -o {mo_file} -f", env="conanbuild", ignore_errors=True) def generate(self): cura_run_envvars = self._cura_run_env.vars(self, scope = "run") @@ -314,13 +317,15 @@ class CuraConan(ConanFile): icon_path = "'{}'".format(Path(self.source_folder, "packaging", self._um_data()["pyinstaller"]["icon"][str(self.settings.os)])).replace("\\", "\\\\"), entitlements_file = entitlements_file if self.settings.os == "Macos" else "None") - # Update the po files - if self.settings_build.os != "Windows" or self.conf.get("tools.microsoft.bash:path", check_type = str): - for po_file in self.source_path.joinpath("resources", "i18n").glob("**/*.po"): - pot_file = self.source_path.joinpath("resources", "i18n", po_file.with_suffix('.pot').name) - mkdir(self, str(unix_path(self, pot_file.parent))) - self.run(f"msgmerge --no-wrap --no-fuzzy-matching -width=140 -o {po_file} {po_file} {pot_file}", env = "conanbuild", run_environment=True) - + # Update the po files + if self.settings.os != "Windows" or self.conf.get("tools.microsoft.bash:path", check_type = str): + # FIXME: once m4, autoconf, automake are Conan V2 ready use self.win_bash and add gettext as base tool_requirement + cpp_info = self.dependencies["gettext"].cpp_info + for po_file in self.source_path.joinpath("resources", "i18n").glob("**/*.po"): + pot_file = self.source_path.joinpath("resources", "i18n", po_file.with_suffix('.pot').name) + mkdir(self, str(unix_path(self, pot_file.parent))) + self.run(f"{cpp_info.bindirs[0]}/msgmerge --no-wrap --no-fuzzy-matching -width=140 -o {po_file} {po_file} {pot_file}", + env = "conanbuild", ignore_errors = True) def imports(self): self.copy("CuraEngine.exe", root_package = "curaengine", src = "@bindirs", dst = "", keep_path = False)