ceedling 1.2.2 → 1.2.3

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.
Files changed (390) hide show
  1. checksums.yaml +4 -4
  2. data/GIT_COMMIT_SHA +1 -1
  3. data/README.md +1 -1
  4. data/assets/fixtures/tests_with_partials_coverage/src/private_macro.c +7 -0
  5. data/assets/fixtures/tests_with_partials_coverage/src/private_macro.h +5 -0
  6. data/assets/fixtures/tests_with_partials_coverage/src/tally.c +13 -0
  7. data/assets/fixtures/tests_with_partials_coverage/src/tally.h +4 -0
  8. data/assets/fixtures/tests_with_partials_coverage/test/test_private_macro.c +10 -0
  9. data/assets/fixtures/tests_with_partials_coverage/test/test_tally.c +9 -0
  10. data/docs/BreakingChanges.md +16 -0
  11. data/docs/Changelog.md +71 -0
  12. data/docs/KnownIssues.md +91 -4
  13. data/examples/wondrous_forest/README.md +29 -1
  14. data/examples/wondrous_forest/src/ForestUnits.h +23 -0
  15. data/examples/wondrous_forest/src/RainGauge.c +59 -0
  16. data/examples/wondrous_forest/src/RainGauge.h +39 -0
  17. data/examples/wondrous_forest/src/RainTipIsr.c +17 -0
  18. data/examples/wondrous_forest/src/RainTipIsr.h +14 -0
  19. data/examples/wondrous_forest/test/TestRainGauge.c +126 -0
  20. data/lib/ceedling/c_extractor/README.md +15 -7
  21. data/lib/ceedling/c_extractor/c_extractor.rb +25 -14
  22. data/lib/ceedling/c_extractor/c_extractor_code_text.rb +84 -54
  23. data/lib/ceedling/c_extractor/c_extractor_constants.rb +18 -7
  24. data/lib/ceedling/c_extractor/c_extractor_declarations.rb +319 -283
  25. data/lib/ceedling/c_extractor/c_extractor_declarator.rb +285 -0
  26. data/lib/ceedling/c_extractor/c_extractor_defined_type.rb +111 -0
  27. data/lib/ceedling/c_extractor/c_extractor_definitions.rb +174 -121
  28. data/lib/ceedling/c_extractor/c_extractor_functions.rb +191 -162
  29. data/lib/ceedling/c_extractor/c_extractor_preprocessing.rb +46 -55
  30. data/lib/ceedling/c_extractor/c_extractor_statement.rb +30 -0
  31. data/lib/ceedling/c_extractor/c_extractor_types.rb +63 -41
  32. data/lib/ceedling/c_extractor/c_module_edits.rb +48 -0
  33. data/lib/ceedling/c_identifier.rb +21 -0
  34. data/lib/ceedling/ceedling.h +8 -0
  35. data/lib/ceedling/config/configurator.rb +4 -3
  36. data/lib/ceedling/config/configurator_builder.rb +17 -0
  37. data/lib/ceedling/config/configurator_setup.rb +29 -5
  38. data/lib/ceedling/constants.rb +5 -1
  39. data/lib/ceedling/defaults.rb +31 -1
  40. data/lib/ceedling/dependencies/CACHE_SCHEMA.md +118 -0
  41. data/lib/ceedling/dependencies/README.md +1 -1
  42. data/lib/ceedling/dependencies/dependency_cache_store.rb +30 -25
  43. data/lib/ceedling/dependencies/dependency_tracker.rb +9 -3
  44. data/lib/ceedling/dependencies/dependinator.rb +13 -1
  45. data/lib/ceedling/diagnostics/DOCTOR.md +142 -0
  46. data/lib/ceedling/diagnostics/README.md +5 -0
  47. data/lib/ceedling/diagnostics/build_step_doctor.rb +110 -0
  48. data/lib/ceedling/diagnostics/duplicate_symbol_specialist.rb +108 -0
  49. data/lib/ceedling/diagnostics/guidance_phrases.rb +30 -0
  50. data/lib/ceedling/diagnostics/header_collision_guidance.rb +56 -0
  51. data/lib/ceedling/diagnostics/header_collision_specialist.rb +152 -0
  52. data/lib/ceedling/diagnostics/include_depth_specialist.rb +132 -0
  53. data/lib/ceedling/diagnostics/missing_symbol_specialist.rb +111 -0
  54. data/lib/ceedling/diagnostics/partial_name_specialist.rb +134 -0
  55. data/lib/ceedling/diagnostics/toolchain_output.rb +44 -0
  56. data/lib/ceedling/filesystem/PATH_HANDLING.md +83 -27
  57. data/lib/ceedling/filesystem/README.md +6 -1
  58. data/lib/ceedling/filesystem/build_roots.rb +105 -0
  59. data/lib/ceedling/filesystem/build_subpath.rb +110 -25
  60. data/lib/ceedling/filesystem/file_finder.rb +76 -110
  61. data/lib/ceedling/filesystem/file_finder_helper.rb +33 -11
  62. data/lib/ceedling/filesystem/file_path_utils.rb +113 -91
  63. data/lib/ceedling/filesystem/file_wrapper.rb +105 -28
  64. data/lib/ceedling/filesystem/path_matcher.rb +21 -0
  65. data/lib/ceedling/filesystem/test_build_layout.rb +114 -0
  66. data/lib/ceedling/filesystem/win_long_paths.rb +153 -0
  67. data/lib/ceedling/filesystem/win_path_limit.rb +83 -0
  68. data/lib/ceedling/filesystem/win_path_prober.rb +52 -0
  69. data/lib/ceedling/generators/generator.rb +27 -64
  70. data/lib/ceedling/generators/generator_helper.rb +0 -44
  71. data/lib/ceedling/generators/generator_mocks.rb +5 -0
  72. data/lib/ceedling/generators/generator_partials.rb +305 -243
  73. data/lib/ceedling/generators/generator_test_runner.rb +5 -8
  74. data/lib/ceedling/generators/partial_header_writer.rb +95 -0
  75. data/lib/ceedling/generators/partial_source_writer.rb +137 -0
  76. data/lib/ceedling/includes/header_search.rb +225 -0
  77. data/lib/ceedling/includes/include_factory.rb +9 -12
  78. data/lib/ceedling/includes/include_pathinator.rb +53 -31
  79. data/lib/ceedling/includes/includes.rb +149 -37
  80. data/lib/ceedling/objects.yml +89 -4
  81. data/lib/ceedling/partials/README.md +110 -16
  82. data/lib/ceedling/partials/carry_plan.rb +71 -0
  83. data/lib/ceedling/partials/definition_head.rb +74 -0
  84. data/lib/ceedling/partials/include_groups.rb +37 -0
  85. data/lib/ceedling/partials/interface_extras.rb +25 -0
  86. data/lib/ceedling/partials/partializer.rb +599 -120
  87. data/lib/ceedling/partials/partializer_config.rb +5 -0
  88. data/lib/ceedling/partials/partializer_helper.rb +851 -145
  89. data/lib/ceedling/partials/partializer_reconciler.rb +174 -0
  90. data/lib/ceedling/partials/partializer_utils.rb +89 -109
  91. data/lib/ceedling/partials/partials.rb +153 -10
  92. data/lib/ceedling/partials/type_macros.rb +126 -0
  93. data/lib/ceedling/preprocess/README.md +43 -33
  94. data/lib/ceedling/preprocess/preprocessinator.rb +100 -186
  95. data/lib/ceedling/preprocess/preprocessinator_code_finder.rb +65 -72
  96. data/lib/ceedling/preprocess/preprocessinator_file_assembler.rb +31 -75
  97. data/lib/ceedling/preprocess/preprocessinator_reconstructor.rb +51 -14
  98. data/lib/ceedling/setupinator.rb +16 -3
  99. data/lib/ceedling/test_invoker/HEADER_COLLISIONS.md +21 -7
  100. data/lib/ceedling/test_invoker/PIPELINE.md +57 -16
  101. data/lib/ceedling/test_invoker/README.md +1 -1
  102. data/lib/ceedling/test_invoker/derived_search_path_notices.rb +45 -0
  103. data/lib/ceedling/test_invoker/mock_locator.rb +116 -9
  104. data/lib/ceedling/test_invoker/partial_files_preprocessinator.rb +181 -0
  105. data/lib/ceedling/test_invoker/partials_manager.rb +265 -308
  106. data/lib/ceedling/test_invoker/standin_headerinator.rb +8 -15
  107. data/lib/ceedling/test_invoker/test_bare_includes_extractinator.rb +26 -3
  108. data/lib/ceedling/test_invoker/test_build_executor.rb +338 -198
  109. data/lib/ceedling/test_invoker/test_build_planner.rb +13 -19
  110. data/lib/ceedling/test_invoker/test_build_setup.rb +26 -6
  111. data/lib/ceedling/test_invoker/test_build_validations.rb +23 -20
  112. data/lib/ceedling/test_invoker/test_derived_search_paths.rb +189 -0
  113. data/lib/ceedling/test_invoker/test_file_preprocessinator.rb +1 -2
  114. data/lib/ceedling/test_invoker/test_includes_reconcilinator.rb +1 -1
  115. data/lib/ceedling/test_invoker/test_invoker_types.rb +28 -20
  116. data/lib/ceedling/test_invoker/test_pipeline_helpers.rb +5 -3
  117. data/lib/ceedling/test_invoker/test_pipeline_manager.rb +25 -8
  118. data/lib/ceedling/test_invoker/test_runner_generatinator.rb +31 -3
  119. data/lib/ceedling/test_invoker/test_search_paths.rb +30 -8
  120. data/lib/ceedling/test_invoker/test_substitutions.rb +72 -0
  121. data/lib/ceedling/tools/shell_quoting.rb +45 -0
  122. data/lib/ceedling/tools/tool_quoting.rb +79 -0
  123. data/lib/ceedling/{tool_validator.rb → tools/tool_validator.rb} +18 -7
  124. data/lib/version.rb +1 -1
  125. data/plugins/bullseye/bullseye.rake +1 -3
  126. data/plugins/bullseye/lib/bullseye.rb +15 -2
  127. data/plugins/command_hooks/lib/command_hooks.rb +1 -1
  128. data/plugins/fff/lib/fff.rb +42 -15
  129. data/plugins/fff/lib/fff_mock_generator.rb +12 -9
  130. data/plugins/fff/spec/fff_cmock_wrapper_spec.rb +134 -0
  131. data/plugins/fff/spec/fff_mock_header_generator_spec.rb +9 -0
  132. data/plugins/fff/spec/fff_mock_source_generator_spec.rb +20 -0
  133. data/plugins/gcov/lib/console_reportinator.rb +25 -19
  134. data/plugins/gcov/lib/reportgenerator_reportinator.rb +2 -1
  135. data/site-local/404.html +2 -2
  136. data/site-local/assets/javascripts/{bundle.c21346df.min.js → bundle.a5f9d56c.min.js} +1 -1
  137. data/site-local/assets/javascripts/{bundle.c21346df.min.js.map → bundle.a5f9d56c.min.js.map} +2 -2
  138. data/site-local/configuration/environment-vars.html +2 -2
  139. data/site-local/configuration/global-collections.html +3 -3
  140. data/site-local/configuration/index.html +2 -2
  141. data/site-local/configuration/loading.html +2 -2
  142. data/site-local/configuration/mixins.html +2 -2
  143. data/site-local/configuration/parallel-builds.html +2 -2
  144. data/site-local/configuration/project-file.html +2 -2
  145. data/site-local/configuration/reference/cexception.html +2 -2
  146. data/site-local/configuration/reference/cmock.html +5 -2
  147. data/site-local/configuration/reference/defines.html +2 -2
  148. data/site-local/configuration/reference/environment.html +2 -2
  149. data/site-local/configuration/reference/extension.html +2 -2
  150. data/site-local/configuration/reference/files.html +56 -9
  151. data/site-local/configuration/reference/flags.html +2 -2
  152. data/site-local/configuration/reference/index.html +2 -2
  153. data/site-local/configuration/reference/libraries.html +2 -2
  154. data/site-local/configuration/reference/mixins.html +2 -2
  155. data/site-local/configuration/reference/partials.html +84 -2
  156. data/site-local/configuration/reference/paths.html +7 -2
  157. data/site-local/configuration/reference/plugins.html +2 -2
  158. data/site-local/configuration/reference/project.html +247 -5
  159. data/site-local/configuration/reference/release-build.html +2 -2
  160. data/site-local/configuration/reference/test-build.html +2 -2
  161. data/site-local/configuration/reference/test-runner.html +2 -2
  162. data/site-local/configuration/reference/tools.html +49 -4
  163. data/site-local/configuration/reference/unity.html +2 -2
  164. data/site-local/configuration/which-ceedling.html +2 -2
  165. data/site-local/development/index.html +2 -2
  166. data/site-local/development/plugins/configuration.html +2 -2
  167. data/site-local/development/plugins/index.html +2 -2
  168. data/site-local/development/plugins/plugin-subclass.html +5 -4
  169. data/site-local/development/plugins/rake-tasks.html +2 -2
  170. data/site-local/development/releases.html +2 -2
  171. data/site-local/development/workflow.html +2 -2
  172. data/site-local/getting-started/builds.html +2 -2
  173. data/site-local/getting-started/command-line.html +2 -2
  174. data/site-local/getting-started/example-projects/cipher-quest.html +2 -2
  175. data/site-local/getting-started/example-projects/index.html +2 -2
  176. data/site-local/getting-started/example-projects/temp-sensor.html +2 -2
  177. data/site-local/getting-started/example-projects/wondrous-forest.html +10 -2
  178. data/site-local/getting-started/index.html +2 -2
  179. data/site-local/getting-started/installation.html +2 -2
  180. data/site-local/getting-started/quick-start.html +2 -2
  181. data/site-local/help.html +2 -2
  182. data/site-local/index.html +2 -2
  183. data/site-local/overview/build-system.html +2 -2
  184. data/site-local/overview/index.html +2 -2
  185. data/site-local/overview/test-environments.html +2 -2
  186. data/site-local/overview/tools-and-frameworks.html +2 -2
  187. data/site-local/plugins/beep.html +2 -2
  188. data/site-local/plugins/bullseye/index.html +45 -38
  189. data/site-local/plugins/bullseye/licensing.html +2 -2
  190. data/site-local/plugins/command-hooks.html +4 -4
  191. data/site-local/plugins/compile-commands-json-db.html +2 -2
  192. data/site-local/plugins/cppcheck.html +2 -2
  193. data/site-local/plugins/dependencies.html +2 -2
  194. data/site-local/plugins/fff.html +16 -2
  195. data/site-local/plugins/gcov/examples.html +2 -2
  196. data/site-local/plugins/gcov/gcovr.html +8 -2
  197. data/site-local/plugins/gcov/index.html +2 -2
  198. data/site-local/plugins/gcov/overview.html +2 -2
  199. data/site-local/plugins/gcov/reportgenerator.html +18 -14
  200. data/site-local/plugins/gcov/reporting.html +2 -2
  201. data/site-local/plugins/gcov/setup.html +2 -2
  202. data/site-local/plugins/gcov/tool-versions.html +2 -2
  203. data/site-local/plugins/gcov/troubleshooting.html +2 -2
  204. data/site-local/plugins/index.html +2 -2
  205. data/site-local/plugins/module-generator.html +2 -2
  206. data/site-local/plugins/report-build-warnings-log.html +2 -2
  207. data/site-local/plugins/report-tests-gtestlike-stdout.html +2 -2
  208. data/site-local/plugins/report-tests-ide-stdout.html +2 -2
  209. data/site-local/plugins/report-tests-log-factory.html +2 -2
  210. data/site-local/plugins/report-tests-pretty-stdout.html +2 -2
  211. data/site-local/plugins/report-tests-raw-output-log.html +2 -2
  212. data/site-local/plugins/report-tests-teamcity-stdout.html +2 -2
  213. data/site-local/plugins/sanitize.html +2 -2
  214. data/site-local/plugins/valgrind.html +2 -2
  215. data/site-local/project/index.html +2 -2
  216. data/site-local/project/release-history.html +2 -2
  217. data/site-local/project/sbom.html +2 -2
  218. data/site-local/project/upgrade.html +2 -2
  219. data/site-local/reference/build-directives.html +2 -2
  220. data/site-local/reference/command-line.html +2 -2
  221. data/site-local/reference/environment-vars.html +2 -2
  222. data/site-local/reference/gcov-plugin.html +2 -2
  223. data/site-local/reference/global-collections.html +12 -12
  224. data/site-local/reference/index.html +2 -2
  225. data/site-local/reference/partials-macros.html +47 -2
  226. data/site-local/reference/project-configuration.html +2 -2
  227. data/site-local/sitemap.xml.gz +0 -0
  228. data/site-local/snapshot/examples/cipher_quest/index.html +2 -2
  229. data/site-local/snapshot/examples/temp_sensor/index.html +2 -2
  230. data/site-local/snapshot/examples/wondrous_forest/index.html +72 -15
  231. data/site-local/testing-guide/build-directives.html +2 -2
  232. data/site-local/testing-guide/conventions.html +67 -22
  233. data/site-local/testing-guide/frameworks.html +2 -2
  234. data/site-local/testing-guide/index.html +2 -2
  235. data/site-local/testing-guide/partials/configuration.html +31 -4
  236. data/site-local/testing-guide/partials/conventions.html +509 -8
  237. data/site-local/testing-guide/partials/directives.html +4 -3
  238. data/site-local/testing-guide/partials/example.html +2 -2
  239. data/site-local/testing-guide/partials/index.html +2 -2
  240. data/site-local/testing-guide/partials/overview.html +30 -12
  241. data/site-local/testing-guide/partials/variables.html +169 -4
  242. data/site-local/testing-guide/test-cases.html +2 -2
  243. data/site-local/testing-guide/test-sample.html +2 -2
  244. data/site-local/testing-guide/test-suite-anatomy.html +2 -2
  245. data/spec/integration/build_step_doctor_spec.rb +270 -0
  246. data/spec/integration/c_extractor_composition_spec.rb +254 -4
  247. data/spec/integration/includes_extraction_spec.rb +27 -14
  248. data/spec/integration/nested_test_artifacts_spec.rb +1 -1
  249. data/spec/integration/partial_files_preprocessing_spec.rb +128 -0
  250. data/spec/integration/partials_carry_spec.rb +520 -0
  251. data/spec/integration/partials_declarations_spec.rb +655 -0
  252. data/spec/integration/partials_fallback_preprocessing_spec.rb +65 -0
  253. data/spec/integration/partials_function_pointers_spec.rb +277 -0
  254. data/spec/integration/partials_header_composition_spec.rb +268 -35
  255. data/spec/integration/partials_macro_decorators_spec.rb +267 -0
  256. data/spec/integration/partials_module_resolution_spec.rb +26 -19
  257. data/spec/integration/partials_symbol_linkage_spec.rb +13 -0
  258. data/spec/integration/path_length_reporting_spec.rb +64 -0
  259. data/spec/integration/path_scenarios_spec.rb +80 -3
  260. data/spec/integration/quote_include_isolator_spec.rb +56 -0
  261. data/spec/integration/test_build_parallel_barrier_spec.rb +1 -1
  262. data/spec/integration/test_includes_extractinator_spec.rb +70 -5
  263. data/spec/integration/test_naming_spec.rb +6 -3
  264. data/spec/integration/test_source_file_checks_spec.rb +5 -3
  265. data/spec/integration/tool_executor_spec.rb +1 -1
  266. data/spec/integration/tool_validator_spec.rb +2 -2
  267. data/spec/integration/win_long_paths_probe_spec.rb +46 -0
  268. data/spec/integration/win_path_limit_spec.rb +53 -0
  269. data/spec/integration/windows_registry_query_tool_spec.rb +41 -0
  270. data/spec/support/integration/configurator_integration_helper.rb +8 -3
  271. data/spec/support/integration/partial_files_harness.rb +181 -0
  272. data/spec/support/integration/partials_generation_integration_helper.rb +237 -141
  273. data/spec/support/integration/path_scenario_harness.rb +4 -2
  274. data/spec/support/integration/spec_integration_helper.rb +8 -3
  275. data/spec/support/integration/test_includes_harness.rb +56 -35
  276. data/spec/support/integration/tool_executor_integration_helper.rb +14 -2
  277. data/spec/system/bullseye_deployment_spec.rb +2 -0
  278. data/spec/system/delta_builds_spec.rb +26 -12
  279. data/spec/system/encoding_stress_spec.rb +4 -4
  280. data/spec/system/example_wondrous_forest_spec.rb +2 -2
  281. data/spec/system/gcov_deployment_spec.rb +2 -0
  282. data/spec/system/header_include_path_validation_spec.rb +4 -4
  283. data/spec/system/header_search_paths_spec.rb +1083 -0
  284. data/spec/system/mock_include_folders_spec.rb +121 -0
  285. data/spec/system/mockable_header_reassembly_spec.rb +184 -0
  286. data/spec/system/partials_carry_spec.rb +581 -0
  287. data/spec/system/partials_delta_builds_spec.rb +280 -0
  288. data/spec/system/partials_function_pointers_spec.rb +106 -0
  289. data/spec/system/partials_macro_decorators_spec.rb +127 -0
  290. data/spec/system/partials_module_disambiguation_spec.rb +125 -0
  291. data/spec/system/path_handling_probes_spec.rb +16 -12
  292. data/spec/system/pinned_thread_count_spec.rb +4 -4
  293. data/spec/system/preprocessing_fallback_conditionals_spec.rb +1 -1
  294. data/spec/system/short_build_paths_spec.rb +87 -0
  295. data/spec/system/sibling_header_collision_spec.rb +30 -6
  296. data/spec/system/support/bullseye_common_test_cases.rb +42 -0
  297. data/spec/system/support/common_test_cases.rb +2 -2
  298. data/spec/system/support/gcov_partials_test_cases.rb +48 -0
  299. data/spec/system/test_build_layout_spec.rb +209 -0
  300. data/spec/system/test_source_file_directive_spec.rb +35 -5
  301. data/spec/units/c_extractor/c_extractor_code_text_spec.rb +67 -10
  302. data/spec/units/c_extractor/c_extractor_declarations_spec.rb +501 -4
  303. data/spec/units/c_extractor/c_extractor_declarator_spec.rb +245 -0
  304. data/spec/units/c_extractor/c_extractor_defined_type_spec.rb +45 -0
  305. data/spec/units/c_extractor/c_extractor_definitions_spec.rb +163 -3
  306. data/spec/units/c_extractor/c_extractor_functions_spec.rb +462 -21
  307. data/spec/units/c_extractor/c_extractor_preprocessing_spec.rb +39 -0
  308. data/spec/units/c_extractor/c_extractor_spec.rb +4 -4
  309. data/spec/units/c_extractor/c_extractor_types_spec.rb +163 -0
  310. data/spec/units/c_identifier_spec.rb +35 -0
  311. data/spec/units/config/configurator_builder_spec.rb +24 -0
  312. data/spec/units/config/configurator_setup_spec.rb +72 -4
  313. data/spec/units/config/configurator_spec.rb +27 -1
  314. data/spec/units/dependencies/dependency_cache_store_spec.rb +68 -3
  315. data/spec/units/dependencies/dependency_tracker_spec.rb +25 -0
  316. data/spec/units/dependencies/dependinator_spec.rb +17 -2
  317. data/spec/units/diagnostics/build_step_doctor_spec.rb +170 -0
  318. data/spec/units/diagnostics/duplicate_symbol_specialist_spec.rb +117 -0
  319. data/spec/units/diagnostics/header_collision_specialist_spec.rb +267 -0
  320. data/spec/units/diagnostics/include_depth_specialist_spec.rb +137 -0
  321. data/spec/units/diagnostics/missing_symbol_specialist_spec.rb +154 -0
  322. data/spec/units/diagnostics/partial_name_specialist_spec.rb +129 -0
  323. data/spec/units/diagnostics/toolchain_output_spec.rb +86 -0
  324. data/spec/units/encodinator_spec.rb +3 -4
  325. data/spec/units/filesystem/build_roots_spec.rb +131 -0
  326. data/spec/units/filesystem/build_subpath_spec.rb +113 -0
  327. data/spec/units/filesystem/file_finder_helper_spec.rb +80 -0
  328. data/spec/units/filesystem/file_finder_spec.rb +242 -58
  329. data/spec/units/filesystem/file_path_utils_spec.rb +251 -118
  330. data/spec/units/filesystem/file_wrapper_spec.rb +191 -6
  331. data/spec/units/filesystem/path_matcher_spec.rb +36 -0
  332. data/spec/units/filesystem/test_build_layout_spec.rb +216 -0
  333. data/spec/units/filesystem/win_long_paths_spec.rb +204 -0
  334. data/spec/units/filesystem/win_path_prober_spec.rb +158 -0
  335. data/spec/units/generators/generator_helper_spec.rb +0 -60
  336. data/spec/units/generators/generator_mocks_spec.rb +13 -0
  337. data/spec/units/generators/generator_partials_spec.rb +656 -55
  338. data/spec/units/generators/generator_spec.rb +26 -0
  339. data/spec/units/generators/generator_test_runner_spec.rb +9 -5
  340. data/spec/units/generators/partial_source_writer_spec.rb +129 -0
  341. data/spec/units/includes/header_search_spec.rb +406 -0
  342. data/spec/units/includes/include_factory_spec.rb +22 -5
  343. data/spec/units/includes/include_pathinator_spec.rb +77 -13
  344. data/spec/units/includes/include_spec.rb +14 -0
  345. data/spec/units/includes/includes_spec.rb +176 -19
  346. data/spec/units/loginator_spec.rb +31 -0
  347. data/spec/units/mock_locator_spec.rb +199 -5
  348. data/spec/units/partials/include_groups_spec.rb +42 -0
  349. data/spec/units/partials/partializer_config_spec.rb +25 -0
  350. data/spec/units/partials/partializer_helper_carry_spec.rb +661 -0
  351. data/spec/units/partials/partializer_helper_interface_extras_spec.rb +396 -0
  352. data/spec/units/partials/partializer_helper_spec.rb +529 -277
  353. data/spec/units/partials/partializer_reconciler_spec.rb +661 -0
  354. data/spec/units/partials/partializer_spec.rb +1578 -270
  355. data/spec/units/partials/partializer_utils_spec.rb +269 -232
  356. data/spec/units/partials/partials_rename_spec.rb +160 -0
  357. data/spec/units/partials_manager_spec.rb +554 -261
  358. data/spec/units/plugins/bullseye_spec.rb +34 -0
  359. data/spec/units/plugins/console_reportinator_spec.rb +58 -9
  360. data/spec/units/plugins/report_tests_teamcity_stdout_spec.rb +1 -1
  361. data/spec/units/plugins/reportgenerator_reportinator_spec.rb +51 -3
  362. data/spec/units/preprocess/preprocessinator_code_finder_spec.rb +73 -10
  363. data/spec/units/preprocess/preprocessinator_file_assembler_spec.rb +125 -37
  364. data/spec/units/preprocess/preprocessinator_includes_handler_spec.rb +15 -0
  365. data/spec/units/preprocess/preprocessinator_reconstructor_spec.rb +197 -0
  366. data/spec/units/preprocess/preprocessinator_spec.rb +153 -95
  367. data/spec/units/setupinator_spec.rb +51 -0
  368. data/spec/units/standin_headerinator_spec.rb +27 -11
  369. data/spec/units/test_build_executor_spec.rb +780 -166
  370. data/spec/units/test_build_planner_spec.rb +116 -28
  371. data/spec/units/test_build_setup_spec.rb +83 -18
  372. data/spec/units/test_context_extractor_spec.rb +11 -2
  373. data/spec/units/test_derived_search_paths_spec.rb +259 -0
  374. data/spec/units/test_includes_extractinator_spec.rb +56 -8
  375. data/spec/units/test_invoker/objects_wiring_spec.rb +20 -3
  376. data/spec/units/test_invoker/partial_files_preprocessinator_spec.rb +264 -0
  377. data/spec/units/test_invoker/test_substitutions_spec.rb +122 -0
  378. data/spec/units/test_invoker_types_spec.rb +8 -7
  379. data/spec/units/test_pipeline_manager_spec.rb +54 -13
  380. data/spec/units/test_runner_generatinator_spec.rb +93 -1
  381. data/spec/units/test_search_paths_spec.rb +73 -5
  382. data/spec/units/{default_tools_quoting_spec.rb → tools/default_tools_quoting_spec.rb} +39 -5
  383. data/spec/units/tools/shell_quoting_spec.rb +76 -0
  384. data/spec/units/{tool_executor_helper_spec.rb → tools/tool_executor_helper_spec.rb} +1 -1
  385. data/spec/units/{tool_executor_spec.rb → tools/tool_executor_spec.rb} +1 -1
  386. data/spec/units/{tool_validator_spec.rb → tools/tool_validator_spec.rb} +110 -1
  387. data/spec/units/windows_registry_query_tool_spec.rb +53 -0
  388. metadata +161 -16
  389. /data/lib/ceedling/{tool_executor.rb → tools/tool_executor.rb} +0 -0
  390. /data/lib/ceedling/{tool_executor_helper.rb → tools/tool_executor_helper.rb} +0 -0
@@ -0,0 +1,174 @@
1
+ # =========================================================================
2
+ # Ceedling - Test-Centered Build System for C
3
+ # ThrowTheSwitch.org
4
+ # Copyright (c) 2010-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
5
+ # SPDX-License-Identifier: MIT
6
+ # =========================================================================
7
+
8
+ require 'set'
9
+ require 'ceedling/constants'
10
+ require 'ceedling/partials/type_macros'
11
+
12
+ # Pairs what a Partial extracts from a file's written text with its twin in the file's full
13
+ # expansion, where no macro hides anything.
14
+ #
15
+ # Extraction reads the directives-only copy, so a Partial writes code as its user spelled
16
+ # it. That copy keeps every macro, so a macro can hide a storage class, an inline specifier
17
+ # or a call. The full expansion shows them. A function or a declaration takes from its twin
18
+ # what a macro can hide, and keeps its code as written, so line mapping still holds. A
19
+ # variable whose storage class a macro supplies takes its whole declaration from its twin. A
20
+ # type regains a macro written after its closing brace. The written text reads that macro as a
21
+ # variable, or as the start of the variables' type.
22
+ #
23
+ # Definitions pair by name. Declarations and file-scope variables pair by name and then by
24
+ # order, since a name may be declared more than once.
25
+ class PartializerReconciler
26
+
27
+ # A variable takes these from its twin when a macro supplies its storage class
28
+ VARIABLE_FIELDS = %i[decorators type array_suffix text declarator asm_label].freeze
29
+
30
+ STORAGE_CLASSES = %w[static extern].freeze
31
+
32
+ constructor :c_extractor, :loginator
33
+
34
+ # Reconciles one file's extracted module with that file's expanded code, in place
35
+ #
36
+ # @param c_module [CExtractorTypes::CModule] One file's module, as extracted from its written text
37
+ # @param expansion_filepath [String] The file's own lines from its full expansion, written by
38
+ # Preprocessinator#generate_partial_expansion
39
+ # @param name [String] Test name, used in log messages
40
+ # @param module_name [String] Partial module name, used in log messages
41
+ # @param file_type [String] "source" or "header", used in log messages
42
+ def reconcile(c_module:, expansion_filepath:, name:, module_name:, file_type:)
43
+ expanded = @c_extractor.from_file( expansion_filepath )
44
+ entries = Partials::TypeMacros.rejoin_trailing( c_module, expanded ) +
45
+ _reconcile_definitions( c_module.function_definitions, expanded ) +
46
+ _reconcile_declarations( c_module.function_declarations, expanded ) +
47
+ _reconcile_variables( c_module, expanded )
48
+
49
+ @loginator.log_list(
50
+ entries,
51
+ "Reconciled with full expansion for Partial #{name}::#{module_name} #{file_type}:",
52
+ Verbosity::DEBUG
53
+ ) unless entries.empty?
54
+ end
55
+
56
+ private
57
+
58
+ # Updates each definition from the expanded definition of the same name. Returns log entries
59
+ # for those it found.
60
+ def _reconcile_definitions(funcs, expanded_module)
61
+ expanded_by_name = expanded_module.function_definitions.each_with_object({}) { |f, h| h[f.name] = f }
62
+
63
+ return funcs.filter_map do |func|
64
+ expanded = expanded_by_name[func.name]
65
+ next unless expanded
66
+
67
+ _take_expanded( func, expanded )
68
+ "`#{func.name}`"
69
+ end
70
+ end
71
+
72
+ # Everything about a definition that a macro can hide. Its code block stays as written, so
73
+ # line mapping still holds. The decorators its written head doesn't spell are noted, since
74
+ # that head can't be stripped of them.
75
+ def _take_expanded(func, expanded)
76
+ func.hidden_decorators = expanded.decorators - func.decorators
77
+ func.signature = expanded.signature
78
+ func.decorators = expanded.decorators
79
+ func.signature_stripped = expanded.signature_stripped
80
+ func.expanded_body = expanded.body
81
+ end
82
+
83
+ # Matches each declaration to the expanded declaration of the same name, in order. Returns log
84
+ # entries for those whose decorators changed.
85
+ def _reconcile_declarations(decls, expanded_module)
86
+ expanded_by_name = expanded_module.function_declarations.group_by( &:name )
87
+
88
+ return decls.group_by( &:name ).flat_map do |decl_name, same_name|
89
+ same_name.zip( expanded_by_name.fetch( decl_name, [] ) ).filter_map { |decl, expanded| _reconcile_declaration( decl, expanded ) }
90
+ end
91
+ end
92
+
93
+ # Updates one declaration from its expanded counterpart. Its written signature stays as the
94
+ # user spelled it, since a carried prototype is written word for word. Returns a log entry
95
+ # when its decorators changed.
96
+ def _reconcile_declaration(decl, expanded)
97
+ return nil if expanded.nil?
98
+
99
+ changed = decl.decorators != expanded.decorators
100
+ decl.decorators = expanded.decorators
101
+ decl.signature_stripped = expanded.signature_stripped
102
+ return changed ? "`#{decl.name}` (declaration)" : nil
103
+ end
104
+
105
+ # Pairs each file-scope variable with its twin by name, then order. A name pairs only where it
106
+ # appears as often in both copies, since fallback can keep both branches of a conditional. A
107
+ # variable with no name it can be read by never pairs. Returns log entries for the types given
108
+ # a macro and the variables reconciled.
109
+ def _reconcile_variables(c_module, expanded_module)
110
+ ended = Set.new.compare_by_identity
111
+ _record_unpaired( c_module, expanded_module )
112
+ return _variable_pairs( c_module, expanded_module ).flat_map { |var, twin| _reconcile_pair( c_module, var, twin, ended ) }.compact
113
+ end
114
+
115
+ # Fallback keeps both sides of a conditional, so a name can be written more often than the
116
+ # expansion holds it, and none of its copies pairs. Each records every twin's text, so what an
117
+ # initializer names stays visible.
118
+ def _record_unpaired(c_module, expanded_module)
119
+ expanded_by_name = expanded_module.variable_declarations.group_by( &:name )
120
+
121
+ c_module.variable_declarations.group_by( &:name ).each do |var_name, same_name|
122
+ twins = expanded_by_name.fetch( var_name, [] )
123
+ next unless _unpaired?( var_name, same_name, twins )
124
+
125
+ same_name.each { |var| var.expanded_text = twins.map( &:text ).join( "\n" ) }
126
+ end
127
+ end
128
+
129
+ def _unpaired?(var_name, same_name, twins)
130
+ return !(var_name.nil? or twins.empty? or twins.size == same_name.size)
131
+ end
132
+
133
+ # Each written variable with its twin, for the names both copies hold equally often
134
+ def _variable_pairs(c_module, expanded_module)
135
+ expanded_by_name = expanded_module.variable_declarations.group_by( &:name )
136
+
137
+ return c_module.variable_declarations.group_by( &:name ).flat_map do |var_name, same_name|
138
+ twins = expanded_by_name.fetch( var_name, [] )
139
+ (var_name.nil? or twins.size != same_name.size) ? [] : same_name.zip( twins )
140
+ end
141
+ end
142
+
143
+ # A variable keeps its expanded text, which shows what its initializer names. Its type takes
144
+ # back a macro after its closing brace, then the variable takes what a macro hid. `ended`
145
+ # holds the types already given their macro. Returns a log entry or nil for the type, then
146
+ # for the variable.
147
+ def _reconcile_pair(c_module, var, twin, ended)
148
+ var.expanded_text = twin.text
149
+ rejoined = Partials::TypeMacros.rejoin_leading( var, twin, ended )
150
+ return [rejoined, _reconcile_variable( c_module, var, twin )]
151
+ end
152
+
153
+ # A variable whose storage class a macro supplies takes every parsed field from its twin. Its
154
+ # fields depend on each other, so a mix of written and expanded ones could read `extern static`.
155
+ # A macro that supplies only a qualifier, as `#define ROM const`, compiles as written.
156
+ def _reconcile_variable(c_module, var, twin)
157
+ return nil if (var.decorators & STORAGE_CLASSES) == (twin.decorators & STORAGE_CLASSES)
158
+
159
+ VARIABLE_FIELDS.each { |field| var[field] = twin[field] }
160
+ _adopt_defined_type( c_module, var, twin )
161
+ return "`#{var.name}` (variable)"
162
+ end
163
+
164
+ # Places ahead of the variable the type its twin defines, which a macro ahead of it hid from
165
+ # the written declaration. Once per type, however many variables share it.
166
+ def _adopt_defined_type(c_module, var, twin)
167
+ type = twin.defined_type
168
+ return if type.nil? or var.defined_type
169
+
170
+ c_module.insert_before!( var, [type] ) unless c_module.aggregate_definitions.any? { |held| held.equal?( type ) }
171
+ var.defined_type = type
172
+ end
173
+
174
+ end
@@ -6,11 +6,16 @@
6
6
  # =========================================================================
7
7
 
8
8
  require 'ceedling/partials/partials'
9
+ require 'ceedling/partials/definition_head'
9
10
  require 'ceedling/partials/partializer_runtime'
10
11
  require 'ceedling/c_extractor/c_extractor_constants'
12
+ require 'ceedling/c_extractor/c_extractor_functions'
11
13
 
12
14
  class PartializerUtils
13
15
 
16
+ # The C11 specifier and the GNU and C23 attributes that each say a function never returns
17
+ NORETURN_MARKINGS = /(?<!\w)_Noreturn(?!\w)|__attribute__\s*\(\(\s*(?:__noreturn__|noreturn)\s*\)\)|\[\[\s*(?:_Noreturn|noreturn)\s*\]\]/ unless const_defined?(:NORETURN_MARKINGS, false)
18
+
14
19
  include Partials
15
20
 
16
21
  constructor :preprocessinator_code_finder, :loginator
@@ -35,93 +40,45 @@ class PartializerUtils
35
40
  # Transform function to appropriate output format `FunctionDefinition` or `FunctionDeclaration`
36
41
  def transform_function(func, signature, output_type)
37
42
  case output_type
38
- when :impl
39
- # Strip decorators from the front of code_block and count how many newlines were removed.
40
- # Adjust line_num upward so that emitted #line directives remain accurate.
41
- new_code_block, stripped_newlines = extract_code_block(func.code_block, func.decorators)
42
- Partials.manufacture_function_definition(
43
- name: func.name,
44
- signature: signature,
45
- source_filepath: func.source_filepath,
46
- line_num: adjust_line_num(func.line_num, stripped_newlines),
47
- code_block: new_code_block
48
- )
49
- when :interface
50
- # A signature sourced from a CFunctionDefinition never carries a trailing semicolon
51
- # (it's followed by a body, not one), but a signature sourced from a
52
- # CFunctionDeclaration always does (it's a bare prototype). Strip it here so
53
- # callers can render "#{signature};" uniformly regardless of which kind of
54
- # function this interface entry came from.
55
- Partials.manufacture_function_declaration(
56
- name: func.name,
57
- signature: signature.sub(/;\s*\z/, '')
58
- )
59
- else
60
- PartializerRuntime.raise_on_option(output_type)
43
+ when :impl then return testable_definition( func, signature )
44
+ when :interface then return mockable_declaration( func, signature )
61
45
  end
46
+
47
+ PartializerRuntime.raise_on_option(output_type)
62
48
  end
63
49
 
64
- # Replace a C variable declaration in a text block with a no-op expression.
65
- #
66
- # Substitutes the first occurrence of `original_decl` in `text` with:
67
- # (void)0; /* <placeholder> */
68
- # The caller supplies a unique `placeholder` token for the comment slot. This
69
- # allows subsequent rename operations (which use simple token-bounded substitution
70
- # with no comment awareness) to run without touching the comment. After all renames
71
- # are complete, the caller restores `original_decl` by replacing the placeholder.
72
- #
73
- # Block form of `sub` is used so that `\` and `&` in the declaration are not
74
- # interpreted as regex replacement backreferences.
75
- #
76
- # @param text [String] Code text to modify (e.g., a function code_block or body)
77
- # @param original_decl [String] Declaration text to replace (should be stripped of surrounding whitespace)
78
- # @param placeholder [String] Opaque token to embed in the comment (caller replaces it afterwards)
79
- # @return [String] Modified text with declaration replaced by a no-op expression
80
- def replace_declaration_with_noop(text, original_decl, placeholder)
81
- replace_compound_declaration_with_noops(text, original_decl, placeholder, 1)
50
+ # Strip decorators from the front of code_block and count how many newlines were removed.
51
+ # Adjust line_num upward so that emitted #line directives remain accurate. A head whose
52
+ # decorators a macro hides is written from the signature instead. The implementation header
53
+ # declares that same signature.
54
+ def testable_definition(func, signature)
55
+ new_code_block, stripped_newlines =
56
+ Partials::DefinitionHead.rewrite( func, signature ) || extract_code_block( func.code_block, func.decorators, func.name )
57
+
58
+ return Partials.manufacture_function_definition(
59
+ name: func.name,
60
+ signature: signature,
61
+ source_filepath: func.source_filepath,
62
+ line_num: adjust_line_num(func.line_num, stripped_newlines),
63
+ code_block: new_code_block
64
+ )
82
65
  end
83
66
 
84
- # Replace a C compound variable declaration with N no-op expressions and a single comment.
85
- #
86
- # Generates `count` `(void)0;` expressions where the final one carries a comment
87
- # containing `placeholder`. The result replaces the first occurrence of `original_decl`
88
- # in `text`. The caller supplies `count` = number of variables in the compound statement
89
- # and a single unique `placeholder` token. After all variable renames are complete, the
90
- # caller restores `original_decl` by replacing the placeholder with the original text.
91
- #
92
- # Block form of `sub` is used so that `\` and `&` in the declaration are not interpreted
93
- # as regex replacement backreferences.
94
- #
95
- # @param text [String] Code text to modify (e.g., a function code_block or body)
96
- # @param original_decl [String] Declaration text to replace (should be stripped of surrounding whitespace)
97
- # @param placeholder [String] Opaque token to embed in the single trailing comment
98
- # @param count [Integer] Number of no-op expressions to insert (one per variable)
99
- # @return [String] Modified text
100
- def replace_compound_declaration_with_noops(text, original_decl, placeholder, count)
101
- noops = "(void)0; " * (count - 1)
102
- comment = "(void)0; /* `#{placeholder}` replaced with no-op plus variable renamed & promoted to module-scope */"
103
- text.sub(original_decl) { noops + comment }
67
+ # A signature sourced from a CFunctionDefinition never carries a trailing semicolon (it's
68
+ # followed by a body, not one), but a signature sourced from a CFunctionDeclaration always does
69
+ # (it's a bare prototype). Strip it here so callers can render "#{signature};" uniformly
70
+ # regardless of which kind of function this interface entry came from. A mock always returns,
71
+ # so a mock declared never to return would contradict itself. Every noreturn marking stays behind.
72
+ def mockable_declaration(func, signature)
73
+ return Partials.manufacture_function_declaration(
74
+ name: func.name,
75
+ signature: without_noreturn( signature ).strip.sub(/;\s*\z/, '')
76
+ )
104
77
  end
105
78
 
106
- # Rename a C identifier throughout a text block with token-bounded substitution.
107
- #
108
- # Replaces all occurrences of `old_name` that are bounded by C identifier boundaries
109
- # with `new_name`. Token boundaries use Ruby `\b` (word boundary between
110
- # `\w` = `[a-zA-Z0-9_]` and `\W`), which exactly matches C identifier boundaries.
111
- # For example, renaming `count`:
112
- # - Matches: `count = 0`, `(count)`, `count==5`, `*count`, `count[0]`
113
- # - No match: `count_down`, `up_count`, `recount`
114
- #
115
- # Note: This method has no comment-awareness. Callers that need comment content
116
- # preserved verbatim (e.g., no-op placeholders) should use `replace_declaration_with_noop`
117
- # with an opaque placeholder and restore the original text after renaming.
118
- #
119
- # @param text [String] Code text to process
120
- # @param old_name [String] Identifier to replace
121
- # @param new_name [String] Replacement identifier
122
- # @return [String] Modified text with all token-bounded occurrences renamed
123
- def rename_c_identifier(text, old_name, new_name)
124
- text.gsub(/\b#{Regexp.escape(old_name)}\b/, new_name)
79
+ def without_noreturn(signature)
80
+ stripped = signature.gsub( NORETURN_MARKINGS, '' )
81
+ return stripped == signature ? signature : stripped.squeeze( ' ' )
125
82
  end
126
83
 
127
84
  # Stamp the originating source filepath onto each function in a collection.
@@ -136,39 +93,55 @@ class PartializerUtils
136
93
  funcs.each { |func| func.source_filepath = filepath }
137
94
  end
138
95
 
139
- # Locate a function's line number by searching the original C source file.
96
+ # Locate each function's line number by searching the original C source file once.
140
97
  #
141
- # Used when the global fallback mode is active — i.e., preprocessed output is
142
- # unavailable for all functions in the current context. Delegates directly to
143
- # `code_finder.find_in_c_file`.
98
+ # Used for a file preprocessed in fallback, which has no raw directives-only copy to search.
144
99
  #
145
- # @param code_block [String] Function definition text to search for
100
+ # @param code_blocks [Array<String>] Function definition texts to search for
146
101
  # @param filepath [String] Path to the C source file to search
147
- # @return [Integer, nil] 1-indexed source line number, or nil if not found
148
- def locate_function_in_source(code_block:, filepath:)
149
- @code_finder.find_in_c_file(filepath, code_block)
102
+ # @return [Array<Integer, nil>] Each 1-indexed source line number, or nil where not found
103
+ def locate_functions_in_source(code_blocks:, filepath:)
104
+ return @code_finder.find_all_in_c_file( filepath, code_blocks )
150
105
  end
151
106
 
152
- # Locate a function's line number using preprocessed output with C source fallback.
107
+ # Locate each declaration's line number in the text of the file it came from.
108
+ #
109
+ # The original file holds only its own lines, so a match there can't belong to a header it
110
+ # includes. Preprocessed output can't promise that, since it carries every included header.
153
111
  #
154
- # Two-strategy lookup for a single function:
155
- # 1. Try the GCC-preprocessed directives-only file — exact match preserving line markers.
156
- # 2. If that yields nil, fall back to the original C source file.
112
+ # Comments are blanked first, newlines kept, so a commented-out copy of a declaration is
113
+ # never taken for it. Blanking passes over the whole file, so it happens once for them all.
157
114
  #
158
- # Returns line number or nil if neither approach succeeds.
115
+ # @param signatures [Array<String>] Declaration texts as extracted, each ending in its semicolon
116
+ # @param text [String] Full text of the original header or source file
117
+ # @return [Array<Integer, nil>] Each declaration's 1-indexed line number, or nil if not found
118
+ def locate_declarations_in_text(signatures:, text:)
119
+ code = _without_comments( text )
120
+ return signatures.map { |signature| @code_finder.find_in_c_string( code, signature ) }
121
+ end
122
+
123
+ # Locate each function's line number using preprocessed output with C source fallback.
159
124
  #
160
- # @param code_block [String] Function definition text to search for
125
+ # Two-strategy lookup, each file read once for all the functions it serves:
126
+ # 1. Search the GCC-preprocessed directives-only file, whose line markers give original lines.
127
+ # 2. Search the original C source file for each function step 1 didn't find.
128
+ #
129
+ # @param code_blocks [Array<String>] Function definition texts to search for
161
130
  # @param filepath [String] Path to the original C source file (fallback target)
162
131
  # @param preprocessed_filepath [String] Path to the preprocessed directives-only file
163
- # @return [Integer, nil] 1-indexed source line number, or nil if not found
164
- def locate_function_via_preprocessed(code_block:, filepath:, preprocessed_filepath:)
165
- line_num = @code_finder.find_in_preprocessed_file(preprocessed_filepath, code_block)
166
- return line_num unless line_num.nil?
132
+ # @return [Array<Integer, nil>] Each 1-indexed source line number, or nil where neither search finds it
133
+ def locate_functions_via_preprocessed(code_blocks:, filepath:, preprocessed_filepath:)
134
+ lines = @code_finder.find_all_in_preprocessed_file( preprocessed_filepath, code_blocks )
135
+ missing = lines.each_index.select { |index| lines[index].nil? }
136
+ return lines if missing.empty?
167
137
 
168
138
  msg = "Using fallback C function location search for #{filepath}"
169
- @loginator.log( msg, Verbosity::OBNOXIOUS, LogLabels::WARNING )
139
+ missing.each { @loginator.log( msg, Verbosity::OBNOXIOUS, LogLabels::WARNING ) }
140
+
141
+ found = @code_finder.find_all_in_c_file( filepath, missing.map { |index| code_blocks[index] } )
142
+ missing.zip( found ) { |index, line_num| lines[index] = line_num }
170
143
 
171
- return @code_finder.find_in_c_file(filepath, code_block)
144
+ return lines
172
145
  end
173
146
 
174
147
  # Format per-function line-number results as a list of human-readable strings.
@@ -187,6 +160,11 @@ class PartializerUtils
187
160
 
188
161
  private
189
162
 
163
+ # A literal stays, since a comment marker inside one starts no comment
164
+ def _without_comments(text)
165
+ return text.gsub( Partials::LITERAL_OR_COMMENT ) { |found| found.start_with?( '/' ) ? found.gsub( /[^\n]/, ' ' ) : found }
166
+ end
167
+
190
168
  # Does any decorator in a list matche any private keyword (case-insensitive)
191
169
  def is_function_private?(decorators)
192
170
  return decorators.any? do |decorator|
@@ -196,19 +174,21 @@ class PartializerUtils
196
174
 
197
175
  # Strip decorator keywords from the front of code_block and count leading newlines removed.
198
176
  #
199
- # Removes the first occurrence of each decorator string, then strips any leading whitespace
200
- # (including newlines). Returns the trimmed code block and a count of the newlines removed
201
- # from the leading portion — used by the caller to adjust line_num so that emitted #line
202
- # directives in generated source remain accurate.
177
+ # Decorators live only in the text before the function's name. Each is removed there as a
178
+ # whole token, so the same word inside the name, an attribute string or the body stays. Leading
179
+ # whitespace is then trimmed. Returns the trimmed code block and a count of the newlines
180
+ # removed from the leading portion. The caller adjusts line_num with that count so that
181
+ # emitted #line directives in generated source remain accurate.
203
182
  #
204
183
  # @param code_block [String] Raw function source text (decorators + signature + body)
205
184
  # @param decorators [Array<String>] Decorator keywords from CFunctionDefinition#decorators
185
+ # @param name [String] Function name, which ends the decorator region
206
186
  # @return [Array(String, Integer)] [trimmed_code_block, leading_newline_count]
207
- def extract_code_block(code_block, decorators)
208
- stripped = code_block.dup
209
- decorators.each { |d| stripped.sub!(d, '') }
210
- leading = stripped[/\A\s*/]
211
- stripped.lstrip!
187
+ def extract_code_block(code_block, decorators, name)
188
+ cut = CExtractorFunctions.name_position( code_block, name ) || 0
189
+ stripped = CExtractorFunctions.remove_tokens( code_block[0...cut], decorators ) + code_block[cut..]
190
+ leading = stripped[/\A\s*/]
191
+ stripped = stripped.lstrip
212
192
  return stripped, leading.count("\n")
213
193
  end
214
194
 
@@ -5,6 +5,16 @@
5
5
  # SPDX-License-Identifier: MIT
6
6
  # =========================================================================
7
7
 
8
+ require 'set'
9
+ require 'strscan'
10
+ require 'ceedling/constants'
11
+ require 'ceedling/c_identifier'
12
+ require 'ceedling/c_extractor/c_extractor_constants'
13
+ require 'ceedling/c_extractor/c_extractor_declarator'
14
+ require 'ceedling/partials/carry_plan'
15
+ require 'ceedling/partials/interface_extras'
16
+ require 'ceedling/partials/include_groups'
17
+
8
18
  module Partials
9
19
  # Constants
10
20
  PUBLIC = :public unless const_defined?(:PUBLIC)
@@ -17,19 +27,31 @@ module Partials
17
27
  MOCK_PUBLIC = :mock_public unless const_defined?(:MOCK_PUBLIC)
18
28
  MOCK_PRIVATE = :mock_private unless const_defined?(:MOCK_PRIVATE)
19
29
 
20
- # Data class representing a source or header file to be partialized
21
- ConfigFileInfo = Struct.new(:filepath, :directives_only_filepath, :full_expansion_filepath, :includes, keyword_init: true) do
22
- def initialize(filepath: nil, directives_only_filepath: nil, full_expansion_filepath: nil, includes: [])
23
- super
24
- end
25
- end unless const_defined?(:ConfigFileInfo, false)
30
+ # A string or character literal, or a comment. One pattern finds both, so whichever starts
31
+ # first wins, as it does for the compiler.
32
+ LITERAL_OR_COMMENT = %r{"(?:\\.|[^"\\\n])*"|'(?:\\.|[^'\\\n])*'|/\*.*?\*/|//[^\n]*}m unless const_defined?(:LITERAL_OR_COMMENT)
26
33
 
27
- # Data class representing a C partial to be generated
28
- Config = Struct.new(:module, :types, :header, :source, keyword_init: true) do
29
- def initialize(module:, types: [], header: ConfigFileInfo.new, source: ConfigFileInfo.new)
34
+ # A header or source file to be partialized, and what stages 6 and 7 made of it. A
35
+ # preprocessed path is nil when that file wasn't written.
36
+ #
37
+ # - `raw_directives_only_filepath`: the -fdirectives-only output, line markers and every
38
+ # included header's macros intact. Nil in fallback.
39
+ # - `assembled_filepath`: the file's own content with its #includes restored, which
40
+ # extraction parses.
41
+ # - `raw_expansion_filepath`: the full expansion, line markers intact.
42
+ # - `expansion_filepath`: the full expansion's own lines, which reconciliation parses.
43
+ # - `fallback`: true when this file was preprocessed without -fdirectives-only.
44
+ ConfigFileInfo = Struct.new(
45
+ :filepath, :raw_directives_only_filepath, :assembled_filepath, :raw_expansion_filepath, :expansion_filepath,
46
+ :fallback, :includes, keyword_init: true
47
+ ) do
48
+ def initialize(
49
+ filepath: nil, raw_directives_only_filepath: nil, assembled_filepath: nil, raw_expansion_filepath: nil,
50
+ expansion_filepath: nil, fallback: false, includes: []
51
+ )
30
52
  super
31
53
  end
32
- end unless const_defined?(:Config, false)
54
+ end unless const_defined?(:ConfigFileInfo, false)
33
55
 
34
56
  # Data class representing a C function signature
35
57
  FunctionDeclaration = Struct.new(
@@ -61,6 +83,49 @@ module Partials
61
83
  end
62
84
  end unless const_defined?(:FunctionDefinition, false)
63
85
 
86
+ # The name a Partial gives a type a declaration defines, as `struct { int count; }` in
87
+ # `static struct { int count; } s_ctx;`. The parts name its variable: the variable alone at file
88
+ # scope, or a promoted static's function and variable. The module's name is folded as
89
+ # CIdentifier.fold does, and a directory a module is named by takes no part. ceedling.h's
90
+ # PARTIAL_TYPE and PARTIAL_LOCAL_TYPE build the same name.
91
+ # type_name( 'ticker', 's_ctx' ) --> ceedling_partial_ticker_s_ctx_t
92
+ # type_name( 'drivers/my-uart', 'tick', 'n' ) --> ceedling_partial_my_uart_tick_n_t
93
+ def self.type_name(module_name, *parts)
94
+ return "#{PARTIAL_FILENAME_PREFIX}#{CIdentifier.fold( File.basename( module_name ) )}_#{parts.join( '_' )}_t"
95
+ end
96
+
97
+ # Names each type a declaration defines after the first of its variables with a name. A type
98
+ # already named, as a promoted static's is, keeps its name.
99
+ def self.name_defined_types(c_module, module_name)
100
+ c_module.variable_declarations.each do |var|
101
+ type = var.defined_type
102
+ type.type_name ||= type_name( module_name, var.name ) if type and var.name
103
+ end
104
+ end
105
+
106
+ # The type a variable holds by value, less a keyword ahead of it that changes only how it's
107
+ # stored or accessed, as `_Thread_local` and `_Atomic` do
108
+ def self.named_type(var)
109
+ return var.type.to_s.sub( /\A(?:(?:_Thread_local|thread_local|__thread|_Atomic)\s+)+/, '' )
110
+ end
111
+
112
+ # A `static` function is private to its file
113
+ def self.static?(decorators)
114
+ return decorators.include?( 'static' )
115
+ end
116
+
117
+ # Any inline specifier. `static` only narrows linkage, so it doesn't count.
118
+ def self.inline?(decorators)
119
+ return decorators.any? { |d| d != 'static' and CExtractorConstants::PRIVATE_KEYWORDS.include?( d ) }
120
+ end
121
+
122
+ # A declaration of an inline function whose body another header holds. Under C99 a file
123
+ # declaring such a function `extern`, or without `inline`, holds its external definition.
124
+ # A declaration marked `inline` counts too, the body being nowhere else.
125
+ def self.foreign_inline?(decl)
126
+ return (inline?( decl.decorators ) or decl.inline_elsewhere) ? true : false
127
+ end
128
+
64
129
  def self.manufacture_function_declaration(line_num: nil, source_filepath: nil, name:, signature:)
65
130
  return FunctionDeclaration.new(
66
131
  name: name,
@@ -79,4 +144,82 @@ module Partials
79
144
  line_num: line_num
80
145
  )
81
146
  end
147
+ # How promotion renames a function's statics in C text. A rename reads the text one token at a
148
+ # time, so literals, comments, member access and tags keep their spelling.
149
+ module Rename
150
+
151
+ # A struct or union keyword and whatever follows it in the statement up to a '{', such as a
152
+ # tag, attributes, macros or comments. A function's head may match too, which only renames
153
+ # more. Nothing is read twice, so the match takes linear time.
154
+ BODY_HEAD = /(?<![\w$])(?:struct|union)(?![\w$])(?>[^;{}()"']+|(?<group>\((?>[^()]+|\g<group>)*\)))*+\{/ unless const_defined?(:BODY_HEAD)
155
+
156
+ # A member after '.' or '->', or a tag after struct, union or enum. Each lives apart from
157
+ # variables.
158
+ MEMBER_OR_TAG = /(?:\.|->)\s*[A-Za-z_$][\w$]*|(?<![\w$])(?:struct|union|enum)\s+[A-Za-z_$][\w$]*/ unless const_defined?(:MEMBER_OR_TAG)
159
+
160
+ # The start of a member or tag token
161
+ MEMBER_OR_TAG_START = /\A(?:(?:\.|->)\s*[A-Za-z_$]|(?:struct|union|enum)\s)/ unless const_defined?(:MEMBER_OR_TAG_START)
162
+
163
+ # A number, read whole, since a C23 digit separator, as in `1'000`, would otherwise open a
164
+ # character literal
165
+ NUMBER = /(?<![\w$])\.?\d(?:[\w$.]|[eEpP][+-]|'(?=[\w$]))*/ unless const_defined?(:NUMBER)
166
+
167
+ # How a rename reads text, one token at a time. Only an identifier is renamed, so first come
168
+ # the tokens that hold one without naming a variable.
169
+ TOKEN = Regexp.union( MEMBER_OR_TAG, NUMBER, LITERAL_OR_COMMENT, CExtractorConstants::IDENTIFIER ) unless const_defined?(:TOKEN)
170
+
171
+ # An asm template's reference to a named operand, as in `%[count]` or `%w[count]`. A string
172
+ # holding one is renamed wherever it sits, since a macro may open the template, as in
173
+ # `LOCK_PREFIX "incl %[count]"`.
174
+ ASM_OPERAND_REFERENCE = /%[A-Za-z]*\[\K[A-Za-z_$][\w$]*(?=\])/ unless const_defined?(:ASM_OPERAND_REFERENCE)
175
+
176
+ # The text with each identifier `renames` maps replaced, in one pass whatever the number of
177
+ # names. Literals and comments stay as written, and so do member access and tags. A name a
178
+ # local struct or union body holds is renamed in member access and tags too (see
179
+ # names_in_bodies). `shared` gives those names when the bodies sit elsewhere too, and `tags`
180
+ # renames tags by name. The exception is a string's asm operand references, which must follow
181
+ # the operand names they refer to.
182
+ def self.identifiers(text, renames, shared: nil, tags: {})
183
+ shared ||= names_in_bodies( text, renames )
184
+ return text.gsub( TOKEN ) do |token|
185
+ next _member_or_tag( token, renames, shared, tags ) if token.match?( MEMBER_OR_TAG_START )
186
+ next renames.fetch( token, token ) unless token.start_with?( '"' )
187
+
188
+ token.gsub( ASM_OPERAND_REFERENCE ) { |name| renames.fetch( name, name ) }
189
+ end
190
+ end
191
+
192
+ # A member access or tag token, renamed. A tag `tags` renames takes its new name. Otherwise a
193
+ # name a local body holds takes its variable's.
194
+ def self._member_or_tag(token, renames, shared, tags)
195
+ tag = token.match?( /\A(?:struct|union|enum)\s/ )
196
+ return token.sub( /[A-Za-z_$][\w$]*\z/ ) do |name|
197
+ next tags[name] if tag and tags.key?( name )
198
+
199
+ shared.include?( name ) ? renames[name] : name
200
+ end
201
+ end
202
+
203
+ # The names `renames` maps that a struct or union body in the text holds, as a member or in
204
+ # use. Such a body is local to the function, so its members and their uses take the new name
205
+ # alike, wherever they sit.
206
+ def self.names_in_bodies(text, renames)
207
+ names = Set.new
208
+ text.scan( BODY_HEAD ) do
209
+ body = _body_after( text, Regexp.last_match )
210
+ body&.gsub( LITERAL_OR_COMMENT, ' ' )&.scan( CExtractorConstants::IDENTIFIER ) { |name| names << name if renames.key?( name ) }
211
+ end
212
+ return names
213
+ end
214
+
215
+ # The body whose '{' ends the match, or nil when its braces don't balance
216
+ def self._body_after(text, match)
217
+ scanner = StringScanner.new( text )
218
+ scanner.pos = match.pre_match.bytesize + match[0].bytesize - 1
219
+ start = scanner.pos
220
+ return CExtractorDeclarator._skip_balanced( scanner ) ? text.byteslice( start, scanner.pos - start ) : nil
221
+ end
222
+
223
+ end
224
+
82
225
  end