Skip to content

Commit f97d2ce

Browse files
committed
Publish Multiple Configs
1 parent ebbdbde commit f97d2ce

File tree

1 file changed

+47
-26
lines changed

1 file changed

+47
-26
lines changed

cppython/plugins/conan/plugin.py

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,11 @@ async def download_tooling(cls, directory: Path) -> None:
283283
pass
284284

285285
def publish(self) -> None:
286-
"""Publishes the package using conan create workflow."""
286+
"""Publishes the package using conan create workflow.
287+
288+
Creates packages for all configured build types (e.g., Release, Debug)
289+
to support both single-config and multi-config generators.
290+
"""
287291
project_root = self.core_data.project_data.project_root
288292
conanfile_path = project_root / 'conanfile.py'
289293
logger = getLogger('cppython.conan')
@@ -292,32 +296,13 @@ def publish(self) -> None:
292296
raise FileNotFoundError(f'conanfile.py not found at {conanfile_path}')
293297

294298
try:
295-
# Build conan create command arguments
296-
command_args = ['create', str(conanfile_path)]
297-
298-
# Add build mode (build everything for publishing)
299-
command_args.extend(['--build', 'missing'])
300-
301-
# Skip test dependencies during publishing
302-
command_args.extend(['-c', 'tools.graph:skip_test=True'])
303-
command_args.extend(['-c', 'tools.build:skip_test=True'])
304-
305-
# Add cmake binary configuration if specified
306-
if self._cmake_binary:
307-
# Quote the path if it contains spaces
308-
cmake_path = f'"{self._cmake_binary}"' if ' ' in self._cmake_binary else self._cmake_binary
309-
command_args.extend(['-c', f'tools.cmake:cmake_program={cmake_path}'])
310-
311-
# Run conan create using reusable Conan API instance
312-
# Change to project directory since Conan API might not handle cwd like subprocess
313-
original_cwd = os.getcwd()
314-
try:
315-
os.chdir(str(project_root))
316-
self._conan_api.command.run(command_args)
317-
finally:
318-
os.chdir(original_cwd)
299+
# Create packages for each configured build type
300+
build_types = self.data.build_types
301+
for build_type in build_types:
302+
logger.info('Creating package for build type: %s', build_type)
303+
self._run_conan_create(conanfile_path, build_type, logger)
319304

320-
# Upload if not skipped
305+
# Upload once after all configurations are built
321306
if not self.data.skip_upload:
322307
self._upload_package(logger)
323308

@@ -326,6 +311,42 @@ def publish(self) -> None:
326311
logger.error('Conan create failed: %s', error_msg, exc_info=True)
327312
raise ProviderInstallationError('conan', error_msg, e) from e
328313

314+
def _run_conan_create(self, conanfile_path: Path, build_type: str, logger: Logger) -> None:
315+
"""Run conan create command for a specific build type.
316+
317+
Args:
318+
conanfile_path: Path to the conanfile.py
319+
build_type: Build type (Release, Debug, etc.)
320+
logger: Logger instance
321+
"""
322+
# Build conan create command arguments
323+
command_args = ['create', str(conanfile_path)]
324+
325+
# Add build mode (build everything for publishing)
326+
command_args.extend(['--build', 'missing'])
327+
328+
# Skip test dependencies during publishing
329+
command_args.extend(['-c', 'tools.graph:skip_test=True'])
330+
command_args.extend(['-c', 'tools.build:skip_test=True'])
331+
332+
# Add build type setting
333+
command_args.extend(['-s', f'build_type={build_type}'])
334+
335+
# Add cmake binary configuration if specified
336+
if self._cmake_binary:
337+
# Quote the path if it contains spaces
338+
cmake_path = f'"{self._cmake_binary}"' if ' ' in self._cmake_binary else self._cmake_binary
339+
command_args.extend(['-c', f'tools.cmake:cmake_program={cmake_path}'])
340+
341+
# Run conan create using reusable Conan API instance
342+
# Change to project directory since Conan API might not handle cwd like subprocess
343+
original_cwd = os.getcwd()
344+
try:
345+
os.chdir(str(self.core_data.project_data.project_root))
346+
self._conan_api.command.run(command_args)
347+
finally:
348+
os.chdir(original_cwd)
349+
329350
def _upload_package(self, logger) -> None:
330351
"""Upload the package to configured remotes using Conan API."""
331352
# If no remotes configured, upload to all remotes

0 commit comments

Comments
 (0)