ScriptCollection 4.4.18__py3-none-any.whl → 4.4.19__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -39,7 +39,7 @@ from .ProgramRunnerBase import ProgramRunnerBase
39
39
  from .ProgramRunnerPopen import ProgramRunnerPopen
40
40
  from .SCLog import SCLog, LogLevel
41
41
 
42
- version = "4.4.18"
42
+ version = "4.4.19"
43
43
  __version__ = version
44
44
 
45
45
  class VSCodeWorkspaceShellTask:
@@ -187,6 +187,11 @@ class ProjectServerIssue:
187
187
  self.description=description
188
188
  self.comments=comments
189
189
 
190
+ class TranslationState:
191
+ Initial:int = 0
192
+ Translated:int = 1
193
+ Reviewed:int = 2
194
+ Final:int = 3
190
195
 
191
196
  class ScriptCollectionCore:
192
197
 
@@ -3165,8 +3170,7 @@ Currently there are no technical depts.""")
3165
3170
  | Abbreviation | Meaning |
3166
3171
  | ------------ | ------- |""")
3167
3172
 
3168
- GeneralUtilities.append_to_file(main_reference_file, """
3169
-
3173
+ GeneralUtilities.append_lines_to_file(main_reference_file, """
3170
3174
  ## Responsibilities
3171
3175
 
3172
3176
  | Responsibility | Name and contact-information |
@@ -3183,8 +3187,7 @@ TXDX
3183
3187
 
3184
3188
  - [Repository](TXDX)
3185
3189
  - [Productive-System](TXDX)
3186
- - [QualityCheck-system](TXDX)
3187
- """.replace("XDX", "ODO"))
3190
+ - [QualityCheck-system](TXDX)""".replace("XDX", "ODO").split("\n"))
3188
3191
 
3189
3192
  @GeneralUtilities.check_arguments
3190
3193
  def run_with_timeout(self, method, timeout_in_seconds: float) -> bool:
@@ -3900,6 +3903,18 @@ OCR-content:
3900
3903
 
3901
3904
  @GeneralUtilities.check_arguments
3902
3905
  def generate_chart_diagram(self,source_file:str,target_file:str):
3906
+ """Renders a Vega-Lite diagram-specification (source_file) into an svg-file (target_file) using "vl2svg". Use
3907
+ generate_full_vega_chart_diagram instead for a diagram-specification which uses the full Vega-syntax."""
3908
+ self.__generate_chart_diagram_with_renderer("vl2svg",source_file,target_file)
3909
+
3910
+ @GeneralUtilities.check_arguments
3911
+ def generate_full_vega_chart_diagram(self,source_file:str,target_file:str):
3912
+ """Renders a (full-syntax) Vega diagram-specification (source_file) into an svg-file (target_file) using
3913
+ "vg2svg". Use generate_chart_diagram instead for a diagram-specification which uses the Vega-Lite-syntax."""
3914
+ self.__generate_chart_diagram_with_renderer("vg2svg",source_file,target_file)
3915
+
3916
+ @GeneralUtilities.check_arguments
3917
+ def __generate_chart_diagram_with_renderer(self,renderer_program:str,source_file:str,target_file:str):
3903
3918
  workingfolder=os.path.dirname(source_file)
3904
3919
  argument=f"\"{source_file}\" \"{target_file}\""
3905
3920
  loglevelMap = {
@@ -3910,8 +3925,7 @@ OCR-content:
3910
3925
  }
3911
3926
  if self.log.loglevel==LogLevel.Debug:
3912
3927
  argument=f"-l {loglevelMap[self.log.loglevel]} {argument}"
3913
- self.run_with_epew("vl2svg",argument,workingfolder,encode_argument_in_base64=True)
3914
- #this uses vega-light. to use vega "vg2svg" should be used instead.
3928
+ self.run_with_epew(renderer_program,argument,workingfolder,encode_argument_in_base64=True)
3915
3929
 
3916
3930
  @GeneralUtilities.check_arguments
3917
3931
  def add_tooltips_to_chart_diagram(self, svg_file: str) -> int:
@@ -4177,11 +4191,13 @@ OCR-content:
4177
4191
  def __sync_xlf2_files(self,base_file:ET.ElementTree, language_files:dict [
4178
4192
  str,#filepath
4179
4193
  ET.ElementTree#parsed file
4180
- ]):
4194
+ ])->dict[str,dict[int,float]]:
4181
4195
  """This function assumes that all files are valid xliff2 files and that the base file is the reference for syncing.
4182
4196
  This function adds new entries from the base file to the language files if they do not already exist using the value from base_file.
4183
4197
  This function removes entries from the language files if they do not exist in the base file anymore.
4184
- In the end the updated language files are written to the disk. The base file is not changed."""
4198
+ In the end the updated language files are written to the disk. The base file is not changed.
4199
+ Returns for each language (derived from the filename of the language-file) a dict which contains for each TranslationState
4200
+ the percentage (as a value between 0.0 and 1.0) of translation-units which are in that state."""
4185
4201
  #The file which was parsed looks like:
4186
4202
  #<?xml version="1.0" encoding="UTF-8" ?>
4187
4203
  #<xliff version="2.0" xmlns="urn:oasis:names:tc:xliff:document:2.0" srcLang="en">
@@ -4226,6 +4242,7 @@ OCR-content:
4226
4242
  for unit in base_file_element.findall("x:unit", namespaces=NSMAP)
4227
4243
  }
4228
4244
  base_ids = set(base_units.keys())
4245
+ result:dict[str,dict[int,float]]=dict()
4229
4246
  for filepath, lang_tree in language_files.items():
4230
4247
  lang_root = lang_tree.getroot()
4231
4248
  lang_file_element = lang_root.find("x:file", namespaces=NSMAP)
@@ -4255,6 +4272,27 @@ OCR-content:
4255
4272
  unit.get("id"): unit
4256
4273
  for unit in lang_file_element.findall("x:unit", namespaces=NSMAP)
4257
4274
  }
4275
+
4276
+ # Calculate translation-state-statistics
4277
+ state_name_to_state = {
4278
+ "initial": TranslationState.Initial,
4279
+ "translated": TranslationState.Translated,
4280
+ "reviewed": TranslationState.Reviewed,
4281
+ "final": TranslationState.Final,
4282
+ }
4283
+ state_counts = {state: 0 for state in state_name_to_state.values()}
4284
+ total_segments = 0
4285
+ for unit in current_units.values():
4286
+ for segment in unit.findall("x:segment", namespaces=NSMAP):
4287
+ state_counts[state_name_to_state[segment.get("state", "initial")]] += 1
4288
+ total_segments += 1
4289
+ if total_segments == 0:
4290
+ percentages = {state: 0.0 for state in state_counts}
4291
+ else:
4292
+ percentages = {state: count / total_segments for state, count in state_counts.items()}
4293
+ language = os.path.basename(filepath).split(".")[-2]
4294
+ result[language] = percentages
4295
+
4258
4296
  for unit in list(lang_file_element.findall("x:unit", namespaces=NSMAP)):
4259
4297
  lang_file_element.remove(unit)
4260
4298
  for unit_id in base_units.keys():
@@ -4274,17 +4312,112 @@ OCR-content:
4274
4312
  )
4275
4313
  ScriptCollectionCore().format_xml_file(filepath)
4276
4314
 
4315
+ return result
4316
+
4277
4317
  @GeneralUtilities.check_arguments
4278
- def sync_xlf2_files(self,prefix:str, languages:list[str], folder:str):
4318
+ def generate_translation_state_diagram(self, statistics:dict[str,dict[int,float]],target_file:str)->None:
4319
+ """Writes a Vega-Lite specification (see sync_xlf2_files/TranslationState) to target_file (which must already
4320
+ have the appropriate file-extension, usually ".json") which visualizes, for each language contained in
4321
+ "statistics" (sorted alphabetically), a stacked horizontal bar showing the share of translation-units which
4322
+ are in each TranslationState, plus the exact percentages as text next to it. Rendering that specification
4323
+ into an image (for example via generate_chart_diagram) is not done by this function."""
4324
+ state_order = [TranslationState.Initial, TranslationState.Translated, TranslationState.Reviewed, TranslationState.Final]
4325
+ state_names = {
4326
+ TranslationState.Initial: "Initial",
4327
+ TranslationState.Translated: "Translated",
4328
+ TranslationState.Reviewed: "Reviewed",
4329
+ TranslationState.Final: "Final",
4330
+ }
4331
+ #single-hue ordinal ramp (light->dark, light-surface-safe), since the states represent an ordered progress and not just distinct categories
4332
+ state_colors = {
4333
+ TranslationState.Initial: "#86b6ef",
4334
+ TranslationState.Translated: "#3987e5",
4335
+ TranslationState.Reviewed: "#1c5cab",
4336
+ TranslationState.Final: "#0d366b",
4337
+ }
4338
+ languages = sorted(statistics.keys())
4339
+
4340
+ bar_data = []
4341
+ label_data = []
4342
+ for language in languages:
4343
+ percentages = statistics[language]
4344
+ label_parts = []
4345
+ for state_index, state in enumerate(state_order):
4346
+ percentage = percentages.get(state, 0.0)
4347
+ bar_data.append({
4348
+ "language": language,
4349
+ "state": state_names[state],
4350
+ "state_order": state_index,
4351
+ "percentage": percentage,
4352
+ })
4353
+ label_parts.append(f"{state_names[state]} {percentage:.0%}")
4354
+ label_data.append({"language": language, "label": " ".join(label_parts)})
4355
+
4356
+ row_height = 24
4357
+ spec = {
4358
+ "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
4359
+ "description": "Translation-state of the translation-units per language",
4360
+ "config": {"view": {"stroke": None}, "background": "#fcfcfb"},
4361
+ "hconcat": [
4362
+ {
4363
+ "height": {"step": row_height},
4364
+ "width": 400,
4365
+ "data": {"values": bar_data},
4366
+ "mark": {"type": "bar"},
4367
+ "encoding": {
4368
+ "y": {"field": "language", "type": "nominal", "sort": languages, "title": None},
4369
+ "x": {"field": "percentage", "type": "quantitative", "stack": "normalize", "axis": {"format": "%", "title": "Share of translation-units"}},
4370
+ "order": {"field": "state_order", "type": "quantitative"},
4371
+ "color": {
4372
+ "field": "state",
4373
+ "type": "nominal",
4374
+ "sort": [state_names[state] for state in state_order],
4375
+ "scale": {
4376
+ "domain": [state_names[state] for state in state_order],
4377
+ "range": [state_colors[state] for state in state_order],
4378
+ },
4379
+ "legend": {"title": "Translation state"},
4380
+ },
4381
+ "tooltip": [
4382
+ {"field": "language", "type": "nominal", "title": "Language"},
4383
+ {"field": "state", "type": "nominal", "title": "State"},
4384
+ {"field": "percentage", "type": "quantitative", "title": "Share", "format": ".1%"},
4385
+ ],
4386
+ },
4387
+ },
4388
+ {
4389
+ "height": {"step": row_height},
4390
+ "width": 220,
4391
+ "data": {"values": label_data},
4392
+ "mark": {"type": "text", "align": "left", "baseline": "middle", "color": "#52514e"},
4393
+ "encoding": {
4394
+ "y": {"field": "language", "type": "nominal", "sort": languages, "axis": None},
4395
+ "x": {"value": 0},
4396
+ "text": {"field": "label", "type": "nominal"},
4397
+ },
4398
+ },
4399
+ ],
4400
+ }
4401
+ GeneralUtilities.ensure_file_exists(target_file)
4402
+ GeneralUtilities.write_text_to_file(target_file, json.dumps(spec, indent=2, ensure_ascii=False)+"\n")
4403
+
4404
+
4405
+ @GeneralUtilities.check_arguments
4406
+ def sync_xlf2_files(self,prefix:str, languages:list[str], folder:str)->dict[str,dict[int, float]]:
4279
4407
  #languages=["de", "fr"] for example. the default-language (usually english) must not be included.
4408
+ #languages may contain culture-specific entries with a country-code (e.g. "de-AT"); in that case the language without the
4409
+ #country-code (e.g. "de") must also be contained in languages.
4280
4410
  base_file=os.path.join(folder, f"{prefix}.xlf")
4281
4411
  base_file_xml:ET.ElementTree=ET.parse(base_file)
4282
4412
  GeneralUtilities.assert_condition(self.is_xliff2_file(base_file), f"The base file '{base_file}' is not a valid XLIFF 2.0 file.")
4283
4413
  GeneralUtilities.assert_file_exists(base_file)
4284
4414
  if len(languages)==0:
4285
4415
  raise ValueError("No files provided for syncing.")
4286
- if len(languages)==1:
4287
- return
4416
+ for language in languages:
4417
+ if "-" in language:
4418
+ base_language = language.split("-")[0]
4419
+ if base_language != "en": # "en" is always the implicit default-language (see above) and therefore never has to be listed itself, unlike every other base-language.
4420
+ GeneralUtilities.assert_condition(base_language in languages, f"The languages-list contains the culture '{language}' but not its base-language '{base_language}'.")
4288
4421
  language_files_list=[os.path.join(folder, f"{prefix}.{language}.xlf") for language in languages]
4289
4422
  language_files_with_content:dict[str,ET.ElementTree]=dict()
4290
4423
  for language_file in language_files_list:
@@ -4293,8 +4426,10 @@ OCR-content:
4293
4426
  language_files_with_content[language_file]=ET.parse(language_file)
4294
4427
 
4295
4428
  #sync existing files
4296
- self.__sync_xlf2_files(base_file_xml, language_files_with_content)
4297
-
4429
+ statistics = self.__sync_xlf2_files(base_file_xml, language_files_with_content)
4430
+
4431
+ #english and cultures with a country-code (e.g. "de-AT") are not contained in the result
4432
+ return {language: percentages for language, percentages in statistics.items() if language != "en" and "-" not in language}
4298
4433
 
4299
4434
  @GeneralUtilities.check_arguments
4300
4435
  def translate_xlf_files_in_folder(self, folder: str, base_language: str, libre_translate_api_server: str):
@@ -0,0 +1,243 @@
1
+ import os
2
+ import re
3
+ import glob
4
+ import platform
5
+ import shutil
6
+ from ...GeneralUtilities import GeneralUtilities
7
+ from ...SCLog import LogLevel
8
+ from ..TFCPS_CodeUnitSpecific_Base import TFCPS_CodeUnitSpecific_Base, TFCPS_CodeUnitSpecific_Base_CLI
9
+ from ..TFCPS_RemoteBuild import TFCPS_RemoteBuild, RunnerOperatingSystem
10
+
11
+
12
+ class TFCPS_CodeUnitSpecific_CPP_Functions(TFCPS_CodeUnitSpecific_Base):
13
+ """Implements the tasks of a codeunit which contains a native C/C++-project.
14
+
15
+ Unlike the other codeunit-kinds this class does not run one fixed build-tool: there is no single, universal
16
+ C/C++-build-tool the way cargo is for Rust or flutter is for Dart, and a codeunit of this kind can even vendor
17
+ a foreign upstream which brings its own, unrelated build-system per target-platform. Which command builds
18
+ which target-platform is therefore configured by the codeunit itself via the public attributes below, before
19
+ build() is called; what this class standardizes is the plumbing around that (locating the sourcecode,
20
+ verifying the result, publishing it as an artifact, and - for the linux-target - the option to build inside a
21
+ docker-container so that target is reproducible independent of the host-operating-system)."""
22
+
23
+ # Architectures which are built for every target-platform, for example ["x64"] or ["x64", "arm64"].
24
+ architectures: list[str]
25
+
26
+ # Build-configuration which is passed to the build-tool, for example "Release" or "Debug".
27
+ configuration: str
28
+
29
+ # Windows: path (relative to the sourcecode-folder) of the Visual-Studio-solution which is built with MSBuild.
30
+ # Must be set by the codeunit before build(["windows"]) is called.
31
+ windows_solution_file: str | None
32
+
33
+ # Windows: folder (relative to the sourcecode-folder) MSBuild writes its output into, for example
34
+ # "bin/{architecture}/{configuration}". "{architecture}" and "{configuration}" are replaced with the values of
35
+ # the attributes above.
36
+ windows_output_folder_pattern: str
37
+
38
+ # Linux/macOS: shell-commands which are run (in this order, in the sourcecode-folder) to build the project.
39
+ linux_build_commands: list[str]
40
+ macos_build_commands: list[str]
41
+
42
+ # Linux/macOS: glob-patterns (relative to the sourcecode-folder) which select the files published as the
43
+ # build-artifact.
44
+ linux_output_file_patterns: list[str]
45
+ macos_output_file_patterns: list[str]
46
+
47
+ # Linux: whether the build runs inside a docker-container. Recommended (and the default): this makes the
48
+ # linux-target reproducible on every host-operating-system instead of depending on whatever happens to be
49
+ # installed on the machine which runs the build.
50
+ linux_use_docker: bool
51
+
52
+ # Linux: the name of the docker-image the build runs in (only used if linux_use_docker is True), as defined
53
+ # in this repository's ".ScriptCollection/OCIImages/ImageDefinition.csv" (for example "Debian") - not a raw
54
+ # image-reference. It is resolved the same way every other codeunit resolves an image it depends on (see
55
+ # OCIImageManager.get_registry_address_for_image_with_default_tag), so a custom-registry-override defined for
56
+ # this machine (see OCIImageManager.get_global_docker_image_registries_file) also applies here.
57
+ linux_docker_image: str
58
+
59
+ # Linux: shell-commands which are run once inside the container before linux_build_commands, for example to
60
+ # install build-dependencies (for example "apt-get update", "apt-get install -y ...").
61
+ linux_docker_setup_commands: list[str]
62
+
63
+ def __init__(self, current_file: str, verbosity: LogLevel, targetenvironmenttype: str, use_cache: bool, is_pre_merge: bool):
64
+ super().__init__(current_file, verbosity, targetenvironmenttype, use_cache, is_pre_merge)
65
+ self.architectures = ["x64"]
66
+ self.configuration = "Release"
67
+ self.windows_solution_file = None
68
+ self.windows_output_folder_pattern = "bin/{architecture}/{configuration}"
69
+ self.linux_build_commands = ["./configure", "make"]
70
+ self.macos_build_commands = ["./configure", "make"]
71
+ self.linux_output_file_patterns = []
72
+ self.macos_output_file_patterns = []
73
+ self.linux_use_docker = True
74
+ self.linux_docker_image = "Debian"
75
+ self.linux_docker_setup_commands = []
76
+
77
+ @GeneralUtilities.check_arguments
78
+ def build(self, target_platforms: list[str]) -> None:
79
+ for target_platform in target_platforms:
80
+ if target_platform == "windows":
81
+ self.__build_windows()
82
+ elif target_platform == "linux":
83
+ self.__build_linux()
84
+ elif target_platform == "macos":
85
+ self.__build_macos()
86
+ else:
87
+ raise ValueError(f"Not supported target-platform: {target_platform}")
88
+
89
+ @GeneralUtilities.check_arguments
90
+ def __get_source_folder(self) -> str:
91
+ source_folder = os.path.join(self.get_codeunit_folder(), "src")
92
+ GeneralUtilities.assert_condition(os.path.isdir(source_folder), f"The sourcecode-folder \"{source_folder}\" does not exist. Run CommonTasks.py first.")
93
+ return source_folder
94
+
95
+ @GeneralUtilities.check_arguments
96
+ def __build_windows(self) -> None:
97
+ GeneralUtilities.assert_condition(GeneralUtilities.string_has_content(self.windows_solution_file), "windows_solution_file must be set before building the windows-target of a C/C++-codeunit.")
98
+ source_folder = self.__get_source_folder()
99
+ solution_file = os.path.join(source_folder, self.windows_solution_file)
100
+ GeneralUtilities.assert_condition(os.path.isfile(solution_file), f"The solution-file \"{solution_file}\" does not exist.")
101
+ msbuild_path = self.__find_msbuild_path()
102
+ # A vcxproj commonly pins a fixed WindowsTargetPlatformVersion, which only happens to build if that exact
103
+ # Windows-SDK-version is installed. Passing it here as a global MSBuild-property overrides that pin (a
104
+ # project can not override a property given on the command line) with whatever Windows-SDK is actually
105
+ # installed on this machine, without having to patch the project.
106
+ windows_sdk_version = self.__detect_latest_windows_sdk_version()
107
+ for architecture in self.architectures:
108
+ self._protected_sc.log.log(f"Build windows-target for architecture \"{architecture}\" ({self.configuration})...")
109
+ msbuild_arguments = [solution_file, "/t:Rebuild", f"/p:Platform={architecture}", f"/p:Configuration={self.configuration}", "/m", "/nologo"]
110
+ if windows_sdk_version is not None:
111
+ msbuild_arguments.append(f"/p:WindowsTargetPlatformVersion={windows_sdk_version}")
112
+ self._protected_sc.run_program_argsasarray(msbuild_path, msbuild_arguments, source_folder, print_live_output=self.get_verbosity() == LogLevel.Debug)
113
+ output_folder = os.path.join(source_folder, self.windows_output_folder_pattern.format(architecture=architecture, configuration=self.configuration))
114
+ GeneralUtilities.assert_condition(os.path.isdir(output_folder), f"The build did not produce the expected output-folder \"{output_folder}\".")
115
+ target_folder = os.path.join(self.get_artifacts_folder(), f"BuildResult_Windows_{architecture}")
116
+ GeneralUtilities.ensure_directory_does_not_exist(target_folder)
117
+ GeneralUtilities.ensure_directory_exists(target_folder)
118
+ GeneralUtilities.copy_content_of_folder(output_folder, target_folder)
119
+
120
+ @GeneralUtilities.check_arguments
121
+ def __find_msbuild_path(self) -> str:
122
+ program_files_x86 = os.environ.get("ProgramFiles(x86)", r"C:\Program Files (x86)")
123
+ vswhere_path = os.path.join(program_files_x86, "Microsoft Visual Studio", "Installer", "vswhere.exe")
124
+ GeneralUtilities.assert_condition(os.path.isfile(vswhere_path), f"\"{vswhere_path}\" was not found. Visual Studio (with the \"Desktop development with C++\"-workload) must be installed to "
125
+ "build the windows-target of a C/C++-codeunit.")
126
+ result = self._protected_sc.run_program_argsasarray(vswhere_path, ["-latest", "-products", "*", "-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64", "-property", "installationPath"],
127
+ GeneralUtilities.get_temp_folder())
128
+ installation_path = result[1].strip()
129
+ GeneralUtilities.assert_condition(GeneralUtilities.string_has_content(installation_path), "No Visual-Studio-installation with the \"Microsoft.VisualStudio.Component.VC.Tools.x86.x64\"-component was found.")
130
+ msbuild_path = os.path.join(installation_path, "MSBuild", "Current", "Bin", "amd64", "MSBuild.exe")
131
+ GeneralUtilities.assert_condition(os.path.isfile(msbuild_path), f"\"{msbuild_path}\" does not exist.")
132
+ return msbuild_path
133
+
134
+ @GeneralUtilities.check_arguments
135
+ def __detect_latest_windows_sdk_version(self) -> str | None:
136
+ program_files_x86 = os.environ.get("ProgramFiles(x86)", r"C:\Program Files (x86)")
137
+ include_folder = os.path.join(program_files_x86, "Windows Kits", "10", "Include")
138
+ if not os.path.isdir(include_folder):
139
+ return None
140
+ versions = [name for name in os.listdir(include_folder) if re.match(r"^\d+\.\d+\.\d+\.\d+$", name) and os.path.isdir(os.path.join(include_folder, name))]
141
+ if len(versions) == 0:
142
+ return None
143
+ return sorted(versions, key=lambda version: [int(part) for part in version.split(".")])[-1]
144
+
145
+ @GeneralUtilities.check_arguments
146
+ def __build_linux(self) -> None:
147
+ GeneralUtilities.assert_condition(0 < len(self.linux_output_file_patterns), "linux_output_file_patterns must be set before building the linux-target of a C/C++-codeunit.")
148
+ source_folder = self.__get_source_folder()
149
+ self._protected_sc.log.log(f"Build linux-target ({self.configuration})...")
150
+ if self.linux_use_docker:
151
+ self.__run_commands_in_docker(self.linux_docker_image, self.linux_docker_setup_commands, self.linux_build_commands, source_folder)
152
+ else:
153
+ GeneralUtilities.assert_condition(platform.system() == "Linux", "linux_use_docker is False, so the linux-target of a C/C++-codeunit can only be built locally on a Linux-host.")
154
+ self.__run_commands_locally(self.linux_build_commands, source_folder)
155
+ self.__collect_output_files(source_folder, self.linux_output_file_patterns, "BuildResult_Linux")
156
+
157
+ @GeneralUtilities.check_arguments
158
+ def __build_macos(self) -> None:
159
+ GeneralUtilities.assert_condition(0 < len(self.macos_output_file_patterns), "macos_output_file_patterns must be set before building the macos-target of a C/C++-codeunit.")
160
+ source_folder = self.__get_source_folder()
161
+ self._protected_sc.log.log(f"Build macos-target ({self.configuration})...")
162
+ if platform.system() == "Darwin":
163
+ self.__run_commands_locally(self.macos_build_commands, source_folder)
164
+ else:
165
+ # macOS-binaries can only be produced on macOS, so this always delegates to a macOS-task-runner when not
166
+ # already running on macOS (see the remote-build-article in the reference).
167
+ self.run_program_on_remote_runner(RunnerOperatingSystem.MacOS, "/bin/sh", ["-c", " && ".join(self.macos_build_commands)], source_folder)
168
+ self.__collect_output_files(source_folder, self.macos_output_file_patterns, "BuildResult_MacOS")
169
+
170
+ @GeneralUtilities.check_arguments
171
+ def __run_commands_locally(self, commands: list[str], working_directory: str) -> None:
172
+ for command in commands:
173
+ self._protected_sc.run_program_argsasarray("/bin/sh", ["-c", command], working_directory, print_live_output=True)
174
+
175
+ @GeneralUtilities.check_arguments
176
+ def __run_commands_in_docker(self, image_name: str, setup_commands: list[str], build_commands: list[str], source_folder: str) -> None:
177
+ shell_script = " && ".join(list(setup_commands) + list(build_commands))
178
+ GeneralUtilities.assert_condition(GeneralUtilities.string_has_content(shell_script), "linux_build_commands must not be empty.")
179
+ # Resolved the same way every other codeunit resolves an image it depends on, so this also honors a
180
+ # custom-registry-override defined for the machine which runs the build.
181
+ image = self.tfcps_Tools_General.oci_image_manager.get_registry_address_for_image_with_default_tag(self.get_repository_folder(), image_name)
182
+ # The whole codeunit-folder is mounted (not only the sourcecode-folder), so a codeunit whose build depends
183
+ # on another one can also see what was placed at Other/Resources/DependentCodeUnits, exactly as it would
184
+ # see it building locally.
185
+ codeunit_folder = self.get_codeunit_folder()
186
+ working_directory_in_container = "/workspace/" + os.path.relpath(source_folder, codeunit_folder).replace("\\", "/")
187
+ self._protected_sc.run_program_argsasarray("docker", ["run", "--rm", "-v", f"{codeunit_folder}:/workspace", "-w", working_directory_in_container, image, "/bin/sh", "-c", shell_script],
188
+ source_folder, print_live_output=True)
189
+
190
+ @GeneralUtilities.check_arguments
191
+ def __collect_output_files(self, source_folder: str, patterns: list[str], artifact_name: str) -> None:
192
+ target_folder = os.path.join(self.get_artifacts_folder(), artifact_name)
193
+ GeneralUtilities.ensure_directory_does_not_exist(target_folder)
194
+ GeneralUtilities.ensure_directory_exists(target_folder)
195
+ found_any = False
196
+ for pattern in patterns:
197
+ for match in glob.glob(os.path.join(source_folder, pattern)):
198
+ if os.path.isfile(match):
199
+ shutil.copyfile(match, os.path.join(target_folder, os.path.basename(match)))
200
+ found_any = True
201
+ GeneralUtilities.assert_condition(found_any, f"The build did not produce any file matching {patterns} in \"{source_folder}\".")
202
+
203
+ @GeneralUtilities.check_arguments
204
+ def linting(self) -> None:
205
+ # There is no single, universal C/C++-linter (unlike e.g. clippy for Rust), and a codeunit of this kind can
206
+ # even vendor a foreign upstream whose sourcecode must not be changed here at all. What every codeunit of
207
+ # this kind owns regardless of that is its own scripts, so only those are normalized by default.
208
+ # TODO add real C/C++-linting (for example clang-format/clang-tidy) once a codeunit needs it for its own sourcecode.
209
+ self._protected_sc.normalize_invisible_characters_of_files_in_folder(os.path.join(self.get_codeunit_folder(), "Other"), ["py", "md", "xml"])
210
+
211
+ @GeneralUtilities.check_arguments
212
+ def do_common_tasks(self, current_codeunit_version: str) -> None:
213
+ self.do_common_tasks_base(current_codeunit_version)
214
+
215
+ @GeneralUtilities.check_arguments
216
+ def generate_reference(self) -> None:
217
+ self.generate_reference_using_docfx()
218
+
219
+ @GeneralUtilities.check_arguments
220
+ def run_testcases(self) -> None:
221
+ raise ValueError("Operation is not implemented.") # TODO
222
+
223
+ def get_dependencies(self) -> dict[str, set[str]]:
224
+ return dict[str, set[str]]() # TODO
225
+
226
+ @GeneralUtilities.check_arguments
227
+ def get_available_versions(self, dependencyname: str) -> list[str]:
228
+ return [] # TODO
229
+
230
+ def set_dependency_version(self, name: str, new_version: str) -> None:
231
+ raise ValueError("Operation is not implemented.")
232
+
233
+
234
+ class TFCPS_CodeUnitSpecific_CPP_CLI:
235
+
236
+ @staticmethod
237
+ @GeneralUtilities.check_arguments
238
+ def parse(file: str) -> TFCPS_CodeUnitSpecific_CPP_Functions:
239
+ parser = TFCPS_CodeUnitSpecific_Base_CLI.get_base_parser()
240
+ # add custom parameter if desired
241
+ args = parser.parse_args()
242
+ result: TFCPS_CodeUnitSpecific_CPP_Functions = TFCPS_CodeUnitSpecific_CPP_Functions(file, LogLevel(int(args.verbosity)), args.targetenvironmenttype, not args.nocache, args.ispremerge)
243
+ return result
File without changes