From db6306763713f99976c6c7d127646076d641f4e0 Mon Sep 17 00:00:00 2001
From: Major Hayden <mhayden@redhat.com>
Date: Wed, 31 Jan 2024 14:03:22 -0600
Subject: [PATCH] Initial package

Resolves: RHEL-12453

Signed-off-by: Major Hayden <mhayden@redhat.com>
---
 .gitignore                        |  1 +
 gating.yaml                       |  6 +++
 python-awscrt.spec                | 86 +++++++++++++++++++++++++++++++
 skip-test-requiring-network.patch | 12 +++++
 sources                           |  1 +
 5 files changed, 106 insertions(+)
 create mode 100644 gating.yaml
 create mode 100644 python-awscrt.spec
 create mode 100644 skip-test-requiring-network.patch
 create mode 100644 sources

diff --git a/.gitignore b/.gitignore
index e69de29..0ce1c25 100644
--- a/.gitignore
+++ b/.gitignore
@@ -0,0 +1 @@
+/awscrt-0.16.16.tar.gz
diff --git a/gating.yaml b/gating.yaml
new file mode 100644
index 0000000..648918d
--- /dev/null
+++ b/gating.yaml
@@ -0,0 +1,6 @@
+--- !Policy
+product_versions:
+  - rhel-9
+decision_context: osci_compose_gate
+rules:
+  - !PassingTestCaseRule {test_case_name: osci.brew-build.tier0.functional}
diff --git a/python-awscrt.spec b/python-awscrt.spec
new file mode 100644
index 0000000..d57806e
--- /dev/null
+++ b/python-awscrt.spec
@@ -0,0 +1,86 @@
+%global desc %{expand:
+Python bindings for the AWS Common Runtime}
+
+
+Name:           python-awscrt
+Version:        0.16.16
+Release:        1%{?dist}
+
+Summary:        Python bindings for the AWS Common Runtime
+# All files are licensed under Apache-2.0, except:
+# - crt/aws-c-common/include/aws/common/external/cJSON.h is MIT
+# - crt/aws-c-common/source/external/cJSON.c is MIT
+# - crt/s2n/pq-crypto/kyber_r3/KeccakP-brg_endian_avx2.h is BSD-3-Clause
+License:        Apache-2.0 AND MIT AND BSD-3-Clause
+URL:            https://github.com/awslabs/aws-crt-python
+
+Source0:        %{pypi_source awscrt}
+
+# one test requires internet connection, skip it
+Patch1:         skip-test-requiring-network.patch
+
+BuildRequires:  python%{python3_pkgversion}-devel
+
+BuildRequires:  gcc
+BuildRequires:  gcc-c++
+BuildRequires:  cmake
+BuildRequires:  openssl-devel
+
+BuildRequires:  python%{python3_pkgversion}-websockets
+
+# https://bugzilla.redhat.com/show_bug.cgi?id=2180988
+ExcludeArch:    s390x
+
+
+%description
+%{desc}
+
+
+%package -n python%{python3_pkgversion}-awscrt
+Summary:        %{summary}
+
+
+%description -n python%{python3_pkgversion}-awscrt
+%{desc}
+
+
+%prep
+%autosetup -p1 -n awscrt-%{version}
+
+
+%generate_buildrequires
+%pyproject_buildrequires
+
+
+%build
+%ifarch %{ix86}
+# disable SSE2 instructions to prevent a crash in aws-c-common thread handling
+# probably caused by a compiler bug
+export CFLAGS="%{optflags} -mno-sse2"
+%endif
+export AWS_CRT_BUILD_USE_SYSTEM_LIBCRYPTO=1
+%pyproject_wheel
+
+
+%install
+%pyproject_install
+%pyproject_save_files _awscrt awscrt
+
+
+%check
+PYTHONPATH="%{buildroot}%{python3_sitearch}:%{buildroot}%{python3_sitelib}" %{python3} -m unittest
+
+
+%files -n python%{python3_pkgversion}-awscrt -f %{pyproject_files}
+%doc README.md
+
+
+%changelog
+* Wed Apr 26 2023 Nikola Forró <nforro@redhat.com> - 0.16.16-1
+- New upstream release 0.16.16
+
+* Wed Mar 22 2023 Nikola Forró <nforro@redhat.com> - 0.16.13-2
+- Workaround a crash on %%ix86
+
+* Thu Mar 16 2023 Nikola Forró <nforro@redhat.com> - 0.16.13-1
+- Initial package
diff --git a/skip-test-requiring-network.patch b/skip-test-requiring-network.patch
new file mode 100644
index 0000000..1cd7b50
--- /dev/null
+++ b/skip-test-requiring-network.patch
@@ -0,0 +1,12 @@
+diff --git a/test/test_http_client.py b/test/test_http_client.py
+index 5af87b6..dd2631a 100644
+--- a/test/test_http_client.py
++++ b/test/test_http_client.py
+@@ -347,6 +347,7 @@ class TestClient(NativeResourceTest):
+                                                      tls_connection_options=tls_conn_opt)
+         return connection_future.result(self.timeout)
+ 
++    @unittest.skip("Requires network")
+     def test_h2_client(self):
+         url = urlparse("https://d1cz66xoahf9cl.cloudfront.net/http_test_doc.txt")
+         connection = self._new_h2_client_connection(url)
diff --git a/sources b/sources
new file mode 100644
index 0000000..d90d42b
--- /dev/null
+++ b/sources
@@ -0,0 +1 @@
+SHA512 (awscrt-0.16.16.tar.gz) = 5c94d6a33efc6000361283dc59d49a09bf7943c317fb5ef29bea3d7bc265420ae147510417fe7c0901fe71f3e5baf6235044b994a6cc03278a332c34df2b6e91