Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating the cmake2meson.py tool #13230

Conversation

dreamer-coding-555
Copy link
Contributor

Enhanced Argument Parsing

The convert_args function was refined to better handle the different types of arguments encountered in CMake scripts. This function now accurately processes string, id, and varexp argument types, ensuring that these are correctly translated into their Meson equivalents. By enhancing this core functionality, the script now produces more accurate and reliable Meson build files, handling a wider variety of CMake argument structures.

Advanced Error Handling and Logging

Logging was integrated throughout the script to track the conversion process and capture any errors or warnings. A basic logging configuration was set up to log messages to a file named cmake_to_meson.log, making it easier to debug issues post-conversion. Logging statements were strategically placed to record errors during the conversion of statements and to warn about potential issues, thereby enhancing the script's robustness and providing users with valuable insights for troubleshooting.

Support for More CMake Commands

Support was extended to include several additional CMake commands, greatly expanding the script's functionality. This includes the conversion of find_package to Meson's dependency, find_library to Meson's find_library, and add_test to Meson's test functions. The script now also handles CMake's option commands, converting them to Meson options, and supports conditional statements (if, elseif, else, and endif), providing a more comprehensive conversion capability that can handle complex CMake scripts.

User Configurations

A new logging configuration was added to record the conversion process, making it easier for users to diagnose and address issues. This setup involves capturing detailed logs of conversion activities and errors, providing users with a clear view of what transpired during the conversion. This feature enhances user experience by offering insights into the process, helping identify where and why a conversion might have failed.

Dependency Handling

The script's handling of dependencies was significantly enhanced. It now correctly converts pkg_search_module and pkg_search_modules to Meson dependency formats and translates find_package commands to Meson dependency variables. Additionally, find_library commands are transformed to use Meson's library finding functions. These improvements ensure that dependencies are accurately represented in the Meson build system, maintaining the integrity of the build configuration.

Documentation and Comments

The script was enriched with inline comments and logging statements to explain conversion processes and decisions. Error comments are also written directly into the Meson output file whenever a conversion issue occurs. These additions make the script more transparent and easier to understand and maintain, providing clear documentation of its functionality and logic.

Specific Changes

The Lexer and Parser components were fine-tuned for better performance and reliability. The Lexer now has a simplified token specification with adjusted patterns for more accurate matching, and the Parser has improved handling of nested arguments and comments. Additionally, methods in the Converter class were restructured and enhanced. New methods like convert_add_library, add_option, convert_project, convert_if, and convert_elseif were introduced to handle specific CMake commands, each with added error handling and logging to ensure smooth and accurate conversions.

New Features

The script now includes a feature to write Meson options to a meson_options.txt file if CMake option commands are present. This ensures that build options specified in CMake are carried over to Meson, preserving configuration choices. Enhanced error reporting provides detailed messages for unsupported or failed conversions, helping users quickly identify and resolve issues.

Example Usage

While the script is not fully interactive, the added logging and error messages make it easier for users to manually resolve issues. The main execution block now includes argument parsing for command-line interface usage, initiating the conversion process with proper error handling and logging. This makes the script more user-friendly and accessible, allowing for a smoother conversion experience.

('ignore', re.compile(r'[ \t]')),
('string', re.compile(r'"([^\\]|(\\.))*?"', re.M)),
('varexp', re.compile(r'\${[-_0-9a-z/A-Z.]+}')),
('id', re.compile('''[,-><${}=+_0-9a-z/A-Z|@.*]+''')),
('id', re.compile(r'''[,-><${}=+_0-9a-z/A-Z|@.*]+''')),

Check warning

Code scanning / CodeQL

Overly permissive regular expression range Medium

Suspicious character range that overlaps with 0-9 in the same character class, and is equivalent to \[,\-.\/0-9:;<=>\].
@dreamer-coding-555 dreamer-coding-555 closed this by deleting the head repository May 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant