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

Add -d tool_requires to conan new #13608

Merged
merged 2 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions conan/api/subapi/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,14 @@ def render(template_files, definitions):
result = {}
name = definitions.get("name", "Pkg")
definitions["conan_version"] = __version__
requires = definitions.get("requires") # Convert to list, and forget about it
if requires:
definitions["requires"] = [requires] if isinstance(requires, str) else requires

def ensure_list(key):
value = definitions.get(key) # Convert to list, and forget about it
if value:
definitions[key] = [value] if isinstance(value, str) else value

ensure_list("requires")
ensure_list("tool_requires")

def as_package_name(n):
return n.replace("-", "_").replace("+", "_").replace(".", "_")
Expand Down
2 changes: 1 addition & 1 deletion conan/cli/commands/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def get_template_vars():
template_vars.extend(meta.find_undeclared_variables(ast))

injected_vars = {"conan_version", "package_name", "as_name"}
optional_vars = {"requires"}
optional_vars = {"requires", "tool_requires"}
template_vars = list(set(template_vars) - injected_vars - optional_vars)
template_vars.sort()
return template_vars
Expand Down
15 changes: 15 additions & 0 deletions conan/internal/api/new/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ def requirements(self):
pass
{%- endif %}

# The build_requirements() method is functionally equivalent to the requirements() one,
# being executed just after it. It's a good place to define tool requirements,
# dependencies necessary at build time, not at application runtime
def build_requirements(self):
# Each call to self.tool_requires() will add the corresponding build requirement
{% if tool_requires is defined -%}
{% for require in tool_requires -%}
self.tool_requires("{{ require }}")
{% endfor %}
{% else -%}
# Uncommenting this line will add the cmake >=3.15 build dependency to your project
# self.requires("cmake/[>=3.15]")
pass
{%- endif %}

# The purpose of generate() is to prepare the build, generating the necessary files, such as
# Files containing information to locate the dependencies, environment activation scripts,
# and specific build system files among others
Expand Down
7 changes: 7 additions & 0 deletions conan/internal/api/new/cmake_exe.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ def requirements(self):
self.requires("{{ require }}")
{% endfor %}
{%- endif %}

{% if tool_requires is defined -%}
def build_requirements(self):
{% for require in tool_requires -%}
self.tool_requires("{{ require }}")
{% endfor %}
{%- endif %}
'''

cmake_exe_v2 = """cmake_minimum_required(VERSION 3.15)
Expand Down
8 changes: 8 additions & 0 deletions conan/internal/api/new/cmake_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ def requirements(self):
self.requires("{{ require }}")
{% endfor %}
{%- endif %}

{% if tool_requires is defined -%}
def build_requirements(self):
{% for require in tool_requires -%}
self.tool_requires("{{ require }}")
{% endfor %}
{%- endif %}

'''

cmake_v2 = """cmake_minimum_required(VERSION 3.15)
Expand Down