ccbrown / needy

A C++ library dependency helper.
https://ccbrown.github.io/needy/
MIT License
55 stars 4 forks source link

Add jinja functions to run shell commands #98

Open vmrob opened 8 years ago

vmrob commented 8 years ago

It's often useful to run shell commands to query environment conditions prior to the rendering a needs file:

{% if platform == 'ios' %}
{% set xcrun_platform = 'iphoneos' %}
{% elif platform == 'iossimulator' %}
{% set xcrun_platform = 'iphonesimulator' %}
{% elif platform == 'tvos' %}
{% set xcrun_platform = 'appletvos' %}
{% elif platform == 'tvossimulator' %}
{% set xcrun_platform = 'appletvsimulator' %}
{% endif %}
libraries:
    openssl:
        repository: git@github.com:openssl/openssl.git
        commit: OpenSSL_1_0_1p
        project:
            build-steps:
                {% set openssl_flags = ' --prefix={build_directory}' %}
                {% if platform in ['ios', 'iossimulator', 'tvos', 'tvossimulator'] %}
                  - sh ./Configure iphoneos-cross {{openssl_flags}}
                {% set cross_args = 'CROSS_TOP=$(xcrun --sdk ' + xcrun_platform + ' --show-sdk-platform-path)/Developer CROSS_SDK=$(basename $(xcrun --sdk ' + xcrun_platform + ' --show-sdk-path))' %}
                {% elif platform == host_platform %}
                - sh ./config {{openssl_flags}}
                {% endif %}
                - make depend
                - sh -c 'make install {{cross_args}}'

However, the cacheability of this could be greatly improved if the output of those xcrun commands could be factored into the configuration hash. My proposal is to provide a jinja rule that executes an arbitrary shell command and includes the rendered output.

ccbrown commented 8 years ago

Sounds good, but considering ongoing Windows support, we'd probably need to also add some platform inspection:

shell('echo %FOO%') if sys_platform == 'win32' else foo