{% set version = "2.13.8" %}

package:
  name: libxml2
  version: {{ version }}

source:
  url: https://gitlab.gnome.org/GNOME/libxml2/-/archive/v{{ version }}/libxml2-v{{ version }}.tar.gz
  sha256: df8d4148cc3473d18e07b72f501aac0dcb7c055c8f537da21c0a985be948fc16
  patches:
    - 0002-Make-and-install-a-pkg-config-file-on-Windows.patch

build:
  number: 0
  run_exports:
    # remove symbols at minor versions according to
    #    https://abi-laboratory.pro/tracker/timeline/libxml2/
    # but the analysis is incorrect. abi-laboratory has a hard
    # time with shared libraries with versioned objects.
    - libxml2 >={{ version }},<2.14.0a0

requirements:
  build:
    - libtool  # [unix]
    - {{ compiler('c') }}
    - {{ stdlib("c") }}
    - autoconf  # [not win]
    - automake  # [not win]
    - libtool  # [not win]
    - pkg-config  # [not win]
    - make  # [not win]
    - m2-patch  # [win]
    - libiconv  # [not win]
  host:
    - libiconv
    - icu  # [with_icu == "yes"]
    - liblzma-devel  # [not win]
    - zlib
  run_constrained:
    - icu <0.0a0  # [with_icu != "yes" and not win]

test:
  requires:
    - ripgrep
  files:
    - test.xml
    - test_catalog.xml
  commands:
    - echo on
    - xmllint test.xml
    # ensure (de)activation scripts for bash-on-win do not contain crlf line endings;
    # ripgrep will return exit code 1 if no match is found, which is what we want after
    # filtering to the carriage-return character that shouldn't be there.
    {% for task in ["activate", "deactivate"] %}
    - rg \r %CONDA_PREFIX%\etc\conda\{{ task }}.d\libxml2_{{ task }}.sh & if %ERRORLEVEL% NEQ 1 (exit 0) else (exit 1)  # [win]
    {% endfor %}

    - mkdir -p "${PREFIX}/etc/xml"  # [not win]
    - mkdir     "%PREFIX%\etc\xml"  # [win]
    - cp   test_catalog.xml "${PREFIX}/etc/xml/catalog"  # [not win]
    - copy test_catalog.xml  "%PREFIX%\etc\xml\catalog"  # [win]

    - xmlcatalog "" "http://www.w3.org/2001/xml.xsd" | grep -x -F -e "file://test-uri-override"   # [not win]
    - xmlcatalog "" "http://www.w3.org/2001/xml.xsd" | findstr /X "/C:file://test-uri-override"   # [win]
    # If fallback to system catalog is desired, test below with xml-common added to yum_requirements.txt.
    # - xmlcatalog "" "http://www.w3.org/2009/01/xml.xsd" | grep -x -F -e "file:///usr/share/xml/xml.xsd"  # [linux]

    - rm  "${PREFIX}/etc/xml/catalog"  # [not win]
    - del  "%PREFIX%\etc\xml\catalog"  # [win]

    # If fallback to system catalog is desired, test below with xml-common added to yum_requirements.txt.
    # - xmlcatalog "" "http://www.w3.org/2001/xml.xsd" | grep -x -F -e "file:///usr/share/xml/xml.xsd"  # [linux]

    - xmlcatalog "" "test-id" | grep -x -F -e "No entry for URI test-id"  # [not win]
    - xmlcatalog "" "test-id" | findstr /X "/C:No entry for URI test-id"  # [win]
    - xmlcatalog "test_catalog.xml" "test-id" | grep -x -F -e "file://test-uri"  # [not win]
    - xmlcatalog "test_catalog.xml" "test-id" | findstr /X "/C:file://test-uri"  # [win]

    - export XML_CATALOG_FILES="file://$(pwd)/test_catalog.xml"  # [not win]
    - set  "XML_CATALOG_FILES=file://%CD:\=/%/test_catalog.xml"  # [win]
    - xmlcatalog "" "test-id" | grep -x -F -e "file://test-uri"  # [not win]
    - xmlcatalog "" "test-id" | findstr /X "/C:file://test-uri"  # [win]
    - xmlcatalog "" "http://www.w3.org/2009/01/xml.xsd" | grep -x -F -e "No entry for URI http://www.w3.org/2009/01/xml.xsd"  # [not win]
    - xmlcatalog "" "http://www.w3.org/2009/01/xml.xsd" | findstr /X "/C:No entry for URI http://www.w3.org/2009/01/xml.xsd"  # [win]

about:
  home: http://xmlsoft.org/
  license: MIT
  license_family: MIT
  license_file: Copyright
  summary: The XML C parser and toolkit of Gnome
  description: |
    Though libxml2 is written in C a variety of language
    bindings make it available in other environments.
  doc_url: http://xmlsoft.org/html/index.html
  doc_source_url: https://github.com/GNOME/libxml2/blob/master/doc/devhelp/index.html
  dev_url: https://git.gnome.org/browse/libxml2/

extra:
  recipe-maintainers:
    - isuruf
    - ocefpaf
    - jakirkham
    - gillins
    - jschueller
    - msarahan
    - scopatz
