Bytecompilation: Compile Python files in parallel, according to %_smp_mflags
This commit is contained in:
		
							parent
							
								
									13c1c0c519
								
							
						
					
					
						commit
						a3ea23bd5e
					
				| @ -11,6 +11,8 @@ if [ 0$extra -eq 1 ]; then | ||||
|     exit 1 | ||||
| fi | ||||
| 
 | ||||
| compileall_flags="$4" | ||||
| 
 | ||||
| # If using normal root, avoid changing anything. | ||||
| if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" ]; then | ||||
| 	exit 0 | ||||
| @ -36,6 +38,7 @@ function python_bytecompile() | ||||
|     local python_binary=$2 | ||||
|     local exclude=$3 | ||||
|     local python_libdir="$4" | ||||
|     local compileall_flags="$5" | ||||
| 
 | ||||
|     python_version=$($python_binary -c "import sys; sys.stdout.write('{0.major}{0.minor}'.format(sys.version_info))") | ||||
| 
 | ||||
| @ -77,7 +80,7 @@ function python_bytecompile() | ||||
|         # -x and -e together implements the same functionality as the Filter class below | ||||
|         # -s strips $RPM_BUILD_ROOT from the path | ||||
|         # -p prepends the leading slash to the path to make it absolute | ||||
|         PYTHONPATH=/usr/lib/rpm/redhat/ $python_binary -B -m $compileall_module -o 0 -o 1 -q -f $exclude -s "$RPM_BUILD_ROOT" -p / --hardlink-dupes $invalidation_option -e "$RPM_BUILD_ROOT" "$python_libdir" | ||||
|         PYTHONPATH=/usr/lib/rpm/redhat/ $python_binary -B -m $compileall_module $compileall_flags -o 0 -o 1 -q -f $exclude -s "$RPM_BUILD_ROOT" -p / --hardlink-dupes $invalidation_option -e "$RPM_BUILD_ROOT" "$python_libdir" | ||||
| 
 | ||||
|     else | ||||
| # | ||||
| @ -133,12 +136,12 @@ do | ||||
| 	echo "Bytecompiling .py files below $python_libdir using $python_binary" | ||||
| 
 | ||||
| 	# Generate normal (.pyc) byte-compiled files. | ||||
| 	python_clamp_source_mtime "" "$python_binary" "" "$python_libdir" | ||||
| 	python_clamp_source_mtime "" "$python_binary" "" "$python_libdir" "" | ||||
| 	if [ $? -ne 0 -a 0$errors_terminate -ne 0 ]; then | ||||
| 		# One or more of the files had inaccessible mtime | ||||
| 		exit 1 | ||||
| 	fi | ||||
| 	python_bytecompile "" "$python_binary" "" "$python_libdir" | ||||
| 	python_bytecompile "" "$python_binary" "" "$python_libdir" "$compileall_flags" | ||||
| 	if [ $? -ne 0 -a 0$errors_terminate -ne 0 ]; then | ||||
| 		# One or more of the files had a syntax error | ||||
| 		exit 1 | ||||
| @ -146,7 +149,7 @@ do | ||||
| 
 | ||||
| 	# Generate optimized (.pyo) byte-compiled files. | ||||
| 	# N.B. For Python 3.4+, this call does nothing | ||||
| 	python_bytecompile "-O" "$python_binary" "" "$python_libdir" | ||||
| 	python_bytecompile "-O" "$python_binary" "" "$python_libdir" "$compileall_flags" | ||||
| 	if [ $? -ne 0 -a 0$errors_terminate -ne 0 ]; then | ||||
| 		# One or more of the files had a syntax error | ||||
| 		exit 1 | ||||
|  | ||||
| @ -35,18 +35,18 @@ py2_byte_compile () {\ | ||||
| py34_byte_compile () {\ | ||||
|     python_binary="%{__env_unset_source_date_epoch_if_not_clamp_mtime} PYTHONHASHSEED=0 %1"\ | ||||
|     bytecode_compilation_path="%2"\ | ||||
|     PYTHONPATH="%{_rpmconfigdir}/redhat" $python_binary -s -B -m compileall2 -o 0 -o 1 -s $RPM_BUILD_ROOT -p / --hardlink-dupes $bytecode_compilation_path \ | ||||
|     PYTHONPATH="%{_rpmconfigdir}/redhat" $python_binary -s -B -m compileall2 %{?_smp_mflags} -o 0 -o 1 -s $RPM_BUILD_ROOT -p / --hardlink-dupes $bytecode_compilation_path \ | ||||
| }\ | ||||
| py37_byte_compile () {\ | ||||
|     python_binary="%{__env_unset_source_date_epoch_if_not_clamp_mtime} PYTHONHASHSEED=0 %1"\ | ||||
|     bytecode_compilation_path="%2"\ | ||||
|     PYTHONPATH="%{_rpmconfigdir}/redhat" $python_binary -s -B -m compileall2 -o 0 -o 1 -s $RPM_BUILD_ROOT -p / --hardlink-dupes --invalidation-mode=timestamp $bytecode_compilation_path \ | ||||
|     PYTHONPATH="%{_rpmconfigdir}/redhat" $python_binary -s -B -m compileall2 %{?_smp_mflags} -o 0 -o 1 -s $RPM_BUILD_ROOT -p / --hardlink-dupes --invalidation-mode=timestamp $bytecode_compilation_path \ | ||||
| }\ | ||||
| \ | ||||
| py39_byte_compile () {\ | ||||
|     python_binary="%{__env_unset_source_date_epoch_if_not_clamp_mtime} PYTHONHASHSEED=0 %1"\ | ||||
|     bytecode_compilation_path="%2"\ | ||||
|     $python_binary -s -B -m compileall -o 0 -o 1 -s $RPM_BUILD_ROOT -p / --hardlink-dupes --invalidation-mode=timestamp $bytecode_compilation_path \ | ||||
|     $python_binary -s -B -m compileall %{?_smp_mflags} -o 0 -o 1 -s $RPM_BUILD_ROOT -p / --hardlink-dupes --invalidation-mode=timestamp $bytecode_compilation_path \ | ||||
| }\ | ||||
| \ | ||||
| # Path to intepreter should not contain any arguments \ | ||||
|  | ||||
| @ -78,7 +78,7 @@ | ||||
| %__env_unset_source_date_epoch_if_not_clamp_mtime %[0%{?clamp_mtime_to_source_date_epoch} == 0 ? "env -u SOURCE_DATE_EPOCH" : "env"] | ||||
| 
 | ||||
| ## The individual BRP scripts | ||||
| %__brp_python_bytecompile %{__env_unset_source_date_epoch_if_not_clamp_mtime} %{_rpmconfigdir}/redhat/brp-python-bytecompile "" "%{?_python_bytecompile_errors_terminate_build}" "%{?_python_bytecompile_extra}" | ||||
| %__brp_python_bytecompile %{__env_unset_source_date_epoch_if_not_clamp_mtime} %{_rpmconfigdir}/redhat/brp-python-bytecompile "" "%{?_python_bytecompile_errors_terminate_build}" "%{?_python_bytecompile_extra}" "%{?_smp_mflags}" | ||||
| %__brp_fix_pyc_reproducibility %{_rpmconfigdir}/redhat/brp-fix-pyc-reproducibility | ||||
| %__brp_python_hardlink %{_rpmconfigdir}/redhat/brp-python-hardlink | ||||
| 
 | ||||
|  | ||||
| @ -167,6 +167,7 @@ grep -E '^#[^%%]*%%[^%%]' %{buildroot}%{rpmmacrodir}/macros.* && exit 1 || true | ||||
| - Bytecompilation: Unset $SOURCE_DATE_EPOCH when %%clamp_mtime_to_source_date_epoch is not set | ||||
| - Bytecompilation: Pass --invalidation-mode=timestamp to compileall (on Python 3.7+) | ||||
| - Bytecompilation: Clamp source mtime: https://fedoraproject.org/wiki/Changes/ReproducibleBuildsClampMtimes | ||||
| - Bytecompilation: Compile Python files in parallel, according to %%_smp_mflags | ||||
| 
 | ||||
| * Sun Nov 13 2022 Miro Hrončok <mhroncok@redhat.com> - 3.11-6 | ||||
| - Set PYTEST_XDIST_AUTO_NUM_WORKERS=%%{_smp_build_ncpus} from %%pytest | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user