MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / BuildContext

Class BuildContext

tools/ng/core.py:21–144  ·  view source on GitHub ↗

Central build context that manages all build-related state. This class replaces the global variables in building.py with a proper object-oriented design while maintaining compatibility.

Source from the content-addressed store, hash-verified

19
20
21class BuildContext:
22 """
23 Central build context that manages all build-related state.
24
25 This class replaces the global variables in building.py with a proper
26 object-oriented design while maintaining compatibility.
27 """
28
29 # Class variable to store the current context (for backward compatibility)
30 _current_context: Optional['BuildContext'] = None
31
32 def __init__(self, root_directory: str):
33 """
34 Initialize build context.
35
36 Args:
37 root_directory: RT-Thread root directory path
38 """
39 self.root_directory = os.path.abspath(root_directory)
40 self.bsp_directory = os.getcwd()
41
42 # Initialize managers
43 self.config_manager = ConfigManager()
44 self.project_registry = ProjectRegistry()
45 self.toolchain_manager = ToolchainManager()
46 self.generator_registry = GeneratorRegistry()
47 self.path_service = PathService(self.bsp_directory)
48
49 # Build environment
50 self.environment = None
51 self.build_options = {}
52
53 # Logging
54 self.logger = self._setup_logger()
55
56 # Set as current context
57 BuildContext._current_context = self
58
59 @classmethod
60 def get_current(cls) -> Optional['BuildContext']:
61 """Get the current build context."""
62 return cls._current_context
63
64 @classmethod
65 def set_current(cls, context: Optional['BuildContext']) -> None:
66 """Set the current build context."""
67 cls._current_context = context
68
69 def _setup_logger(self) -> logging.Logger:
70 """Setup logger for build system."""
71 logger = logging.getLogger('rtthread.build')
72 if not logger.handlers:
73 handler = logging.StreamHandler()
74 formatter = logging.Formatter('[%(levelname)s] %(message)s')
75 handler.setFormatter(formatter)
76 logger.addHandler(handler)
77 logger.setLevel(logging.INFO)
78 return logger

Callers 1

init_build_contextFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected