%global __cargo_skip_build 0
%global _debugsource_packages 1
%global _debuginfo_subpackages 1
%define _unpackaged_files_terminate_build 0
%global sysmaster_install_source target/release
%global sysmaster_install_target %{buildroot}/usr/lib/sysmaster
%global unit_install_source units
%global conf_install_source config/conf
%global __cargo_common_opts %{?__cargo_common_opts} --all
%global _cargo_build /usr/bin/env CARGO_HOME=.cargo RUSTC_BOOTSTRAP=1 %{_bindir}/cargo build %__cargo_common_opts

Name:           sysmaster 
Version:        0.2.4
Release:        5
Summary:        redesign and reimplement process1.

License:        Mulan PSL v2
URL:            https://gitee.com/openeuler/sysmaster
Source0:        %{name}-%{version}.tar.gz

Patch0001:      backport-fix-make-test_cgroup-really-work.patch
Patch0002:      backport-fix-several-socket-fixes.patch
Patch0003:      backport-fix-libbasic-create-relative-symlink-in-right-way.patch
Patch0004:      backport-feature-libbasic-add-path_simplify.patch
Patch0005:      backport-feature-libbasic-add-remove_dir_until.patch
Patch0006:      backport-feature-libbasic-add-opendirat.patch
Patch0007:      backport-feature-libbasic-add-more-error-information.patch
Patch0008:      backport-fix-libbasic-create-symlink-atomically.patch
Patch0009:      backport-fix-init-uses-SIGABRT-to-reexec-sysmaster-increase-s.patch
Patch0010:      backport-feature-support-hostname-setup.patch
Patch0011:      backport-fix-libbasic-try-to-follow-the-fd-path-to-make-the-u.patch
Patch0012:      backport-fix-modify-units-for-sctl-enable.patch
Patch0013:      backport-fix-devmaster-deal-with-fd-leak.patch
Patch0014:      backport-feature-add-LogFileSize-and-LogFileNumber.patch
Patch0015:      backport-feature-use-LogFileSize-and-LogFileNumber-to-rotate-.patch
Patch0016:      backport-fix-rename-create_unit_obj_with_um-to-create_subunit.patch
Patch0017:      backport-fix-remove-unit_obj_create_default-we-never-use-it.patch
Patch0018:      backport-typo-fix-some-debugging-messages-and-typoes.patch
Patch0019:      backport-feature-use-our-own-file-logger.patch
Patch0020:      backport-typo-fix-some-clippy.patch
Patch0021:      backport-refactor-move-UmIf-functions-no-functional-change.patch
Patch0022:      backport-fix-several-fixes-on-logger.patch
Patch0023:      backport-typo-declure-declare.patch
Patch0024:      backport-fix-add-default-system.toml.patch
Patch0025:      backport-typo-fix-clippies.patch
Patch0026:      backport-fix-use-var-log-sysmaster-sysmaster.log-to-save-log-.patch
Patch0027:      backport-fix-use-localtime-instead-of-UTC.patch
Patch0028:      backport-refactor-mv-system.toml-to-config-conf.patch
Patch0029:      backport-fix-ignore-auto-generated-toml-file-in-tests-test_un.patch
Patch0030:      backport-fix-version-0.3.10-may-fail-to-build-when-use-tuna-s.patch
Patch0031:      backport-fix-we-shouldn-t-lookup-build-directory-if-we-are-no.patch
Patch0032:      backport-fix-avoid-calling-init_lookup_paths-in-testcase.patch
Patch0033:      backport-typo-fix-some-typoes.patch
Patch0034:      backport-fix-use-UnixStream-to-test-send_and_recv.patch
Patch0035:      backport-fix-make-config.service.toml-same-as-config.service.patch
Patch0036:      backport-fix-init-does-not-enter-the-freeze-during-normal-run.patch
Patch0037:      backport-refactor-don-t-copy-unit-file-to-.toml-file-when-loa.patch
Patch0038:      backport-fix-rename-config.service.toml-to-config.service.patch
Patch0039:      backport-fix-rename-system.toml-to-system.conf.patch
Patch0040:      backport-feature-devmaster-support-update-device-database-and.patch
Patch0041:      backport-build-update-version-to-0.2.4.patch
Patch0042:      backport-build-To-adjust-the-directory-structure.patch
Patch0043:      backport-fix-log-message-before-and-after-reaping-zombie-proc.patch
Patch0044:      backport-fix-log-message-when-creating-symlink.patch
Patch0045:      backport-fix-add-two-helper-macroes-to-help-us-log-message-ou.patch
Patch0046:      backport-fix-log-message-out-when-we-create-delete-a-file-or-.patch
Patch0047:      backport-fix-call-clear_last_frame-before-early-return.patch
Patch0048:      backport-fix-init-recyle-zombie-process-normally-corrects-doc.patch
Patch0049:      backport-fix-adjust-the-mode-of-internal-generated-files.patch
Patch0050:      backport-fix-simply-code-a-bit-delete-an-annoying-log-and-don.patch
Patch0051:      backport-test-support-yum-install-sysmaster.patch
Patch0052:      backport-fix-set-the-notify-socket-receive-buffer-to-8M.patch
Patch0053:      backport-fix-make-the-help-information-clearer.patch
Patch0054:      backport-test-add-UT-testcase-for-command-dispatch.patch
Patch0055:      backport-fix-isolate-debugging-code-through-configuration-pre.patch
Patch0056:      backport-fix-integer-overflow.patch
Patch0057:      backport-test-condition-add-unit-test-for-condition.patch
Patch0058:      backport-fix-check-if-the-words-is-empty-before-using-it.patch
Patch0059:      backport-fix-check-if-the-message-is-truncated.patch
Patch0060:      backport-fix-fix-the-type-error-of-test_get_service_type.patch
Patch0061:      backport-fix-specify-the-version-of-tempfile.patch
Patch0062:      backport-fix-add-two-helper-function-to-check-if-the-path-nam.patch
Patch0063:      backport-fix-downgrade-the-time-crate-from-0.3.x-to-0.1.45.patch

Patch9001:      plugin.conf-delete-Socket-and-Mount.patch

ExclusiveArch:  x86_64 aarch64

BuildRequires:  rust
BuildRequires:  cargo
BuildRequires:  rust-packaging
BuildRequires:  gcc clang util-linux-devel

%description
redesign and reimplement process1.

Summary:        %{summary}


%prep
%autosetup -p1

%cargo_prep

%cargo_generate_buildrequires

%build
sed -i '/\[source.crates-io\]/{n;d}' ./.cargo/config
sed -i '/\[source.local-registry\]/{n;d}' ./.cargo/config
sed -i '/\[source.local-registry\]/a directory = "vendor"' ./.cargo/config
sed -i '/\[build\]/arustflags = \["-C", "target-feature=-crt-static", "-C", "link-arg=-fstack-protector-all", "-C", "link-arg=-fpie", "-C", "link-arg=-DFORTIFY=2 -O2"\]' ./.cargo/config

%{_cargo_build} --profile release

%install
# For binary files and .so files, the permission 750 in the install phase to prevent objcopy errors.
# In the files phase, the permission is set back to 550.
install -Dm0750 -t %{buildroot}/usr/bin %{sysmaster_install_source}/sctl
install -Dm0750 -t %{sysmaster_install_target} %{sysmaster_install_source}/init
install -Dm0750 -t %{sysmaster_install_target} %{sysmaster_install_source}/sysmaster

install -Dm0640 -t %{sysmaster_install_target}/system %{unit_install_source}/*

install -Dm0750 -t %{sysmaster_install_target}/plugin %{sysmaster_install_source}/libservice.so
install -Dm0750 -t %{sysmaster_install_target}/plugin %{sysmaster_install_source}/libtarget.so
install -Dm0640 -t %{sysmaster_install_target}/plugin %{conf_install_source}/plugin.conf
install -Dm0640 -t %{buildroot}/etc/sysmaster %{conf_install_source}/system.conf

%files
%attr(0550,-,-) /usr/bin/sctl
%dir %attr(0550,-,-) /usr/lib/sysmaster
%dir %attr(0750,-,-) /usr/lib/sysmaster/system
/usr/lib/sysmaster/system/basic.target
%attr(0550,-,-) /usr/lib/sysmaster/init
/usr/lib/sysmaster/system/multi-user.target
%dir %attr(0550,-,-) /usr/lib/sysmaster/plugin
%attr(0550,-,-) /usr/lib/sysmaster/plugin/*.so
/usr/lib/sysmaster/plugin/plugin.conf
/usr/lib/sysmaster/system/shutdown.target
/usr/lib/sysmaster/system/sshd-keygen.target
/usr/lib/sysmaster/system/sshd-keygen@ecdsa.service
/usr/lib/sysmaster/system/sshd-keygen@ed25519.service
/usr/lib/sysmaster/system/sshd-keygen@rsa.service
/usr/lib/sysmaster/system/sshd.service
/usr/lib/sysmaster/system/sysinit.target
%attr(0550,-,-) /usr/lib/sysmaster/sysmaster
%dir %attr(0750,-,-) /etc/sysmaster
/etc/sysmaster/system.conf

%changelog
* Thu Jul 27 2023 huyubiao<huyubiao@huawei.com> - 0.2.4-5
- sync patches from upstream,
  change the path of the unit,
  modify permissions for some directories and files

* Wed Jul 19 2023 shenyangyang<shenyangyang4@huawei.com> - 0.2.4-4
- add compile option

* Thu Jul 06 2023 xujing<xujing125@huawei.com> - 0.2.4-3
- fix objcopy permission denied when rpmbuild

* Tue Jun 27 2023 shenyangyang<shenyangyang4@huawei.com> - 0.2.4-2
- modify the sshd units

* Tue Jun 20 2023 shenyangyang<shenyangyang4@huawei.com> - 0.2.4-1
- update version to 0.2.4 for docker use

* Fri Jun 16 2023 licunlong<licunlong1@huawei.com> - 0.2.3-3
- sync patches from upstream

* Tue May 30 2023 shenyangyang<shenyangyang4@huawei.com> - 0.2.3-2
- Support compatible compile with rust 1.60

* Sat May 6 2023 shenyangyang<shenyangyang4@huawei.com> - 0.2.3-1
- update version to 0.2.3

* Tue Sep 20 2022 licunlong<licunlong1@huawei.com> - 0.2.1-2
- rename process1 to sysmaster, and remove pctrl to /usr/bin

* Tue Sep 13 2022 licunlong<licunlong1@huawei.com> - 0.2.1-1
- sync patches from upstream

* Mon Aug 22 2022 He Xiaowen <hexiaowen@huawei.com> - 0.2.0-2
- strip the libraries

* Mon Aug 22 2022 He Xiaowen <hexiaowen@huawei.com> - 0.2.0-1
- initial package

