-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathazure-cli.spec
90 lines (73 loc) · 3.5 KB
/
azure-cli.spec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# RPM spec file for Azure CLI
# Definition of macros used - https://fedoraproject.org/wiki/Packaging:RPMMacros?rd=Packaging/RPMMacros
%global __python %{__python3}
# Turn off python byte compilation
%global __os_install_post %(echo '%{__os_install_post}' | sed -e 's!/usr/lib[^[:space:]]*/brp-python-bytecompile[[:space:]].*$!!g')
# .el7.centos -> .el7
%if 0%{?rhel}
%define dist .el%{?rhel}
%endif
%define python_cmd python3
%define name azure-cli
%define release 1%{?dist}
%define version %{getenv:CLI_VERSION}
%define repo_path %{getenv:REPO_PATH}
%define cli_lib_dir %{_libdir}/az
Summary: Azure CLI
License: MIT
Name: %{name}
Version: %{version}
Release: %{release}
Url: https://docs.microsoft.com/cli/azure/install-azure-cli
BuildArch: x86_64
Requires: %{python_cmd}
Prefix: /usr
Prefix: /etc
BuildRequires: gcc, libffi-devel, openssl-devel, perl
BuildRequires: %{python_cmd}-devel
%global _python_bytecompile_errors_terminate_build 0
%description
A great cloud needs great tools; we're excited to introduce Azure CLI,
our next generation multi-platform command line experience for Azure.
%prep
%install
# Create a fully instantiated virtual environment, ready to use the CLI.
%{python_cmd} -m venv %{buildroot}%{cli_lib_dir}
source %{buildroot}%{cli_lib_dir}/bin/activate
%{python_cmd} -m pip install --upgrade pip
source %{repo_path}/scripts/install_full.sh
# cffi 1.15.0 doesn't work with RPM: https://foss.heptapod.net/pypy/cffi/-/issues/513
%{python_cmd} -m pip install cffi==1.14.6
deactivate
# Fix up %{buildroot} appearing in some files...
for d in %{buildroot}%{cli_lib_dir}/bin/*; do perl -p -i -e "s#%{buildroot}##g" $d; done;
# Create executable (entry script)
# For PYTHONPATH:
# - We can't use %{_libdir} (expands to absolute path '/usr/lib64'), because we need to support customized
# installation location: https://github.com/Azure/azure-cli/pull/17491
# - We also can't use %{_lib}, because %{_lib} expands to different values on difference OSes:
# https://github.com/Azure/azure-cli/pull/20061
# - Fedora/CentOS/RedHat: relative path 'lib64'
# - Mariner: abolute path '/usr/lib'
# The only solution left is to hard-code 'lib64' as we only release 64-bit RPM packages.
mkdir -p %{buildroot}%{_bindir}
python_version=$(ls %{buildroot}%{cli_lib_dir}/lib/ | head -n 1)
printf "#!/usr/bin/env bash
bin_dir=\`cd \"\$(dirname \"\$BASH_SOURCE[0]\")\"; pwd\`
python_cmd=%{python_cmd}
if command -v ${python_version} &>/dev/null; then python_cmd=${python_version}; fi
AZ_INSTALLER=RPM PYTHONPATH=\"\$bin_dir/../lib64/az/lib/${python_version}/site-packages\" \$python_cmd -sm azure.cli \"\$@\"
" > %{buildroot}%{_bindir}/az
rm %{buildroot}%{cli_lib_dir}/bin/python* %{buildroot}%{cli_lib_dir}/bin/pip*
# Remove unused Network SDK API versions
pushd %{buildroot}%{cli_lib_dir}/lib/${python_version}/site-packages/azure/mgmt/network/ > /dev/null
rm -rf v2016_09_01 v2016_12_01 v2017_03_01 v2017_06_01 v2017_08_01 v2017_09_01 v2017_11_01 v2018_02_01 v2018_04_01 v2018_06_01 v2018_10_01 v2018_12_01 v2019_04_01 v2019_08_01 v2019_09_01 v2019_11_01 v2019_12_01 v2020_03_01
popd > /dev/null
# Set up tab completion
mkdir -p %{buildroot}%{_sysconfdir}/bash_completion.d/
cat %{repo_path}/az.completion > %{buildroot}%{_sysconfdir}/bash_completion.d/azure-cli
%files
%exclude %{cli_lib_dir}/bin/
%attr(-,root,root) %{cli_lib_dir}
%config(noreplace) %{_sysconfdir}/bash_completion.d/azure-cli
%attr(0755,root,root) %{_bindir}/az