Skip to content

Commit

Permalink
Add support for CMake 3.29
Browse files Browse the repository at this point in the history
  • Loading branch information
BlankSpruce committed Mar 4, 2024
1 parent f1a09c0 commit d41db4b
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 27 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

## [0.11.0] 2024-10-11
## [0.11.1] 2024-03-04
### Added
- support for new keywords in native commands and new commands available in CMake 3.29

## [0.11.0] 2024-01-11
### Added
- Number of workers spawned for formatting multiple files can be changed with `-w/--workers`. By default it will be number of CPUs available in the system but limited to 60 for Windows machines due to [this](https://github.com/python/cpython/issues/89240).

Expand Down
2 changes: 2 additions & 0 deletions gersemi/builtin_commands
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ cmake_find_frameworks

### CMakePackageConfigHelpers
configure_package_config_file
generate_apple_architecture_selection_file
generate_apple_platform_selection_file
write_basic_package_version_file

### CMakePrintHelpers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class IsolateUnaryTests(IsolateUnaryOperators):
"IS_SYMLINK",
"IS_ABSOLUTE",
"DEFINED",
"IS_READABLE",
"IS_WRITABLE",
"IS_EXECUTABLE",
]


Expand Down
2 changes: 2 additions & 0 deletions gersemi/command_invocation_dumpers/ctest_command_dumpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ class CTestTest(ArgumentAwareCommandInvocationDumper):
"STOP_TIME",
"RETURN_VALUE",
"CAPTURE_CMAKE_ERROR",
"INCLUDE_FROM_FILE",
"EXCLUDE_FROM_FILE",
]


Expand Down
31 changes: 31 additions & 0 deletions gersemi/command_invocation_dumpers/module_command_dumpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,35 @@ class FortranCInterfaceHeader(ArgumentAwareCommandInvocationDumper):
multi_value_keywords = ["SYMBOLS"]


class GenerateAppleArchitectureSelectionFile(ArgumentAwareCommandInvocationDumper):
front_positional_arguments = ["<filename>"]
one_value_keywords = [
"INSTALL_DESTINATION",
"INSTALL_PREFIX",
"SINGLE_ARCHITECTURES",
"SINGLE_ARCHITECTURE_INCLUDE_FILES",
"UNIVERSAL_ARCHITECTURES",
"UNIVERSAL_INCLUDE_FILE",
]


class GenerateApplePlatformSelectionFile(ArgumentAwareCommandInvocationDumper):
front_positional_arguments = ["<filename>"]
one_value_keywords = [
"INSTALL_DESTINATION",
"INSTALL_PREFIX",
"MACOS_INCLUDE_FILE",
"IOS_INCLUDE_FILE",
"IOS_SIMULATOR_INCLUDE_FILE",
"TVOS_INCLUDE_FILE",
"TVOS_SIMULATOR_INCLUDE_FILE",
"WATCHOS_INCLUDE_FILE",
"WATCHOS_SIMULATOR_INCLUDE_FILE",
"VISIONOS_INCLUDE_FILE",
"VISIONOS_SIMULATOR_INCLUDE_FILE",
]


class GenerateExportHeader(ArgumentAwareCommandInvocationDumper):
options = ["DEFINE_NO_DEPRECATED"]
one_value_keywords = [
Expand Down Expand Up @@ -824,6 +853,8 @@ class ExternalDataAddTarget(ArgumentAwareCommandInvocationDumper):
"find_package_handle_standard_args": FindPackageHandleStandardArgs,
"find_package_check_version": FindPackageCheckVersion,
"fortrancinterface_header": FortranCInterfaceHeader,
"generate_apple_architecture_selection_file": GenerateAppleArchitectureSelectionFile,
"generate_apple_platform_selection_file": GenerateApplePlatformSelectionFile,
"generate_export_header": GenerateExportHeader,
"gtest_add_tests": GTestAddTests,
"gtest_discover_tests": GTestDiscoverTests,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,39 @@
from .argument_aware_command_invocation_dumper import (
ArgumentAwareCommandInvocationDumper,
)
from .section_aware_command_invocation_dumper import Sections


def create_signature_patch(signature, old_class):
def get(key):
return signature.get(key, [])

class Impl(old_class):
front_positional_arguments = get("front_positional_arguments")
back_positional_arguments = get("back_positional_arguments")
options = get("options")
one_value_keywords = get("one_value_keywords")
multi_value_keywords = get("multi_value_keywords")
sections = get("sections")

return Impl


class MultipleSignatureCommandInvocationDumper(ArgumentAwareCommandInvocationDumper):
customized_signatures: Dict[Optional[str], Dict[str, Union[List, int]]] = {}
customized_signatures: Dict[Optional[str], Dict[str, Union[List, Sections]]] = {}

@contextmanager
def _update_signature_characteristics(self, signature):
if signature is None:
yield
return

old_class = type(self)
try:

def get(key):
return signature.get(key, [])

self.front_positional_arguments = get("front_positional_arguments")
self.back_positional_arguments = get("back_positional_arguments")
self.options = get("options")
self.one_value_keywords = get("one_value_keywords")
self.multi_value_keywords = get("multi_value_keywords")
self.__class__ = create_signature_patch(signature, old_class)
yield
finally:
delattr(self, "front_positional_arguments")
delattr(self, "back_positional_arguments")
delattr(self, "options")
delattr(self, "one_value_keywords")
delattr(self, "multi_value_keywords")
self.__class__ = old_class

def format_command(self, tree):
_, arguments = tree.children
Expand Down
30 changes: 27 additions & 3 deletions gersemi/command_invocation_dumpers/project_command_dumpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,35 @@ class DefineProperty(ArgumentAwareCommandInvocationDumper):
multi_value_keywords = ["BRIEF_DOCS", "FULL_DOCS"]


class Export(MultipleSignatureCommandInvocationDumper):
class Export(
SectionAwareCommandInvocationDumper, MultipleSignatureCommandInvocationDumper
):
customized_signatures = {
"EXPORT": dict(one_value_keywords=["EXPORT", "NAMESPACE", "FILE"]),
"EXPORT": dict(
options=["EXPORT_PACKAGE_DEPENDENCIES"],
one_value_keywords=["EXPORT", "NAMESPACE", "FILE"],
),
"TARGETS": dict(
options=["APPEND", "EXPORT_LINK_INTERFACE_LIBRARIES"],
one_value_keywords=["NAMESPACE", "FILE", "ANDROID_MK"],
multi_value_keywords=["TARGETS"],
),
"PACKAGE": dict(one_value_keywords=["PACKAGE"]),
"SETUP": dict(
one_value_keywords=["SETUP"],
multi_value_keywords=["PACKAGE_DEPENDENCY", "TARGET"],
sections=dict(
PACKAGE_DEPENDENCY=dict(
front_positional_arguments=["<dep>"],
one_value_keywords=["ENABLED"],
multi_value_keywords=["EXTRA_ARGS"],
),
TARGET=dict(
front_positional_arguments=["<target>"],
one_value_keywords=["XCFRAMEWORK_LOCATION"],
),
),
),
}


Expand Down Expand Up @@ -273,7 +293,11 @@ class Install(TwoWordKeywordIsolator, MultipleSignatureCommandInvocationDumper):
one_value_keywords=["CODE", "COMPONENT"],
),
"EXPORT": dict(
options=["EXPORT_LINK_INTERFACE_LIBRARIES", "EXCLUDE_FROM_ALL"],
options=[
"EXPORT_LINK_INTERFACE_LIBRARIES",
"EXCLUDE_FROM_ALL",
"EXPORT_PACKAGE_DEPENDENCIES",
],
one_value_keywords=[
"EXPORT",
"DESTINATION",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class CMakeLanguage(TwoWordKeywordIsolator, ArgumentAwareCommandInvocationDumper
"GET_CALL",
"SET_DEPENDENCY_PROVIDER",
"GET_MESSAGE_LOG_LEVEL",
"EXIT",
]
multi_value_keywords = [
"DEFER",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,32 @@
)


Sections = Dict[str, Dict[str, Iterable[str]]]


def create_section_patch(section, old_class):
def get(key):
return section.get(key, [])

class Impl(old_class):
options = get("options")
one_value_keywords = get("one_value_keywords")
multi_value_keywords = get("multi_value_keywords")

return Impl


class SectionAwareCommandInvocationDumper(ArgumentAwareCommandInvocationDumper):
sections: Dict[str, Dict[str, Iterable[str]]] = {}

@contextmanager
def _update_section_characteristics(self, keyword):
old_class = type(self)
try:
section = self.sections[keyword]
self.options = section.get("options", [])
self.one_value_keywords = section.get("one_value_keywords", [])
self.multi_value_keywords = section.get("multi_value_keywords", [])
self.__class__ = create_section_patch(self.sections[keyword], old_class)
yield
finally:
delattr(self, "options")
delattr(self, "one_value_keywords")
delattr(self, "multi_value_keywords")
self.__class__ = old_class

def _format_group(self, group) -> str:
result = self._try_to_format_into_single_line(group, separator=" ")
Expand Down
6 changes: 5 additions & 1 deletion tests/formatter/export_command.in.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ export(TARGETS FOO BAR BAZ ANDROID_MK FOO)

export(TARGETS long_arg____________________________________________________________ ANDROID_MK long_arg____________________________________________________________)

export(TARGETS long_arg____________________________________________________________ long_arg____________________________________________________________ long_arg____________________________________________________________ ANDROID_MK long_arg____________________________________________________________)
export(TARGETS long_arg____________________________________________________________ long_arg____________________________________________________________ long_arg____________________________________________________________ ANDROID_MK long_arg____________________________________________________________)

export(SETUP foo PACKAGE_DEPENDENCY bar ENABLED AUTO EXTRA_ARGS baz qux foo TARGET bar XCFRAMEWORK_LOCATION baz)

export(SETUP foo__________________________________________________ PACKAGE_DEPENDENCY bar__________________________________________________ ENABLED AUTO EXTRA_ARGS baz__________________________________________________ qux__________________________________________________ foo__________________________________________________ TARGET bar__________________________________________________ XCFRAMEWORK_LOCATION baz__________________________________________________)
21 changes: 21 additions & 0 deletions tests/formatter/export_command.out.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,24 @@ export(
ANDROID_MK
long_arg____________________________________________________________
)

export(
SETUP foo
PACKAGE_DEPENDENCY bar ENABLED AUTO EXTRA_ARGS baz qux foo
TARGET bar XCFRAMEWORK_LOCATION baz
)

export(
SETUP foo__________________________________________________
PACKAGE_DEPENDENCY
bar__________________________________________________
ENABLED AUTO
EXTRA_ARGS
baz__________________________________________________
qux__________________________________________________
foo__________________________________________________
TARGET
bar__________________________________________________
XCFRAMEWORK_LOCATION
baz__________________________________________________
)

0 comments on commit d41db4b

Please sign in to comment.