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

Method BuildPackage

tools/ng/environment.py:167–222  ·  view source on GitHub ↗

Build package from package.json. Args: env: SCons Environment package_path: Path to package.json. If None, looks for package.json in current directory. Returns: List of build objects

(env, package_path: str = None)

Source from the content-addressed store, hash-verified

165
166 @staticmethod
167 def BuildPackage(env, package_path: str = None) -> List:
168 """
169 Build package from package.json.
170
171 Args:
172 env: SCons Environment
173 package_path: Path to package.json. If None, looks for package.json in current directory.
174
175 Returns:
176 List of build objects
177 """
178 # Import the existing package module
179 import sys
180 import os
181
182 # Get the building module path
183 building_path = os.path.dirname(os.path.abspath(__file__))
184 tools_path = os.path.dirname(building_path)
185
186 # Add to path if not already there
187 if tools_path not in sys.path:
188 sys.path.insert(0, tools_path)
189
190 # Import and use the existing BuildPackage
191 try:
192 from package import BuildPackage as build_package_func
193
194 # BuildPackage uses global functions, so we need to set up the context
195 # Save current directory
196 current_dir = os.getcwd()
197
198 # Change to the directory where we want to build
199 if package_path is None:
200 work_dir = env.GetCurrentDir()
201 elif os.path.isdir(package_path):
202 work_dir = package_path
203 else:
204 work_dir = os.path.dirname(package_path)
205
206 os.chdir(work_dir)
207
208 try:
209 # Call the original BuildPackage
210 result = build_package_func(package_path)
211 finally:
212 # Restore directory
213 os.chdir(current_dir)
214
215 return result
216
217 except ImportError:
218 # Fallback if import fails
219 context = BuildContext.get_current()
220 if context:
221 context.logger.error("Failed to import package module")
222 return []
223
224 @staticmethod

Callers

nothing calls this directly

Calls 2

GetCurrentDirMethod · 0.80
get_currentMethod · 0.45

Tested by

no test coverage detected