diff mbox series

libselinux: set CFLAGS for pip installation

Message ID 20230420162700.41974-1-cgzones@googlemail.com (mailing list archive)
State Accepted
Commit c9b3cbb654ca
Delegated to: Petr Lautrbach
Headers show
Series libselinux: set CFLAGS for pip installation | expand

Commit Message

Christian Göttsche April 20, 2023, 4:27 p.m. UTC
Explicitly set CFLAGS for the pip install command, similar to calling
setup.py, to ignore known compiler warnings treated as errors, e.g.:

    selinuxswig_python_wrap.c:3593:19: error: 'sidget' is deprecated [-Werror,-Wdeprecated-declarations]
                result = (int)sidget(arg1);
                              ^
    selinuxswig_python_wrap.c:15024:1: error: no previous prototype for function 'PyInit__selinux' [-Werror,-Wmissing-prototypes]
            SWIG_init(void) {
            ^

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
fixes GitHub CI, see https://github.com/SELinuxProject/selinux/pull/388
---
 libselinux/src/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Petr Lautrbach April 26, 2023, 3:01 p.m. UTC | #1
Christian Göttsche <cgzones@googlemail.com> writes:

> Explicitly set CFLAGS for the pip install command, similar to calling
> setup.py, to ignore known compiler warnings treated as errors, e.g.:
>
>     selinuxswig_python_wrap.c:3593:19: error: 'sidget' is deprecated [-Werror,-Wdeprecated-declarations]
>                 result = (int)sidget(arg1);
>                               ^
>     selinuxswig_python_wrap.c:15024:1: error: no previous prototype for function 'PyInit__selinux' [-Werror,-Wmissing-prototypes]
>             SWIG_init(void) {
>             ^
>
> Signed-off-by: Christian Göttsche <cgzones@googlemail.com>


It looks like a problem in build system - selinuxswig_python_wrap.o is
built twice, first time by

pywrap: all selinuxswig_python_exception.i
	CFLAGS="$(CFLAGS) $(SWIG_CFLAGS)" $(PYTHON) setup.py build_ext


clang -fdeclspec -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -O2 -Werror -Wall -Wextra -Wfloat-equal -Wformat=2 -Winit-self -Wmissing-format-attribute -Wmissing-noreturn -Wmissing-prototypes -Wnull-dereference -Wpointer-arith -Wshadow -Wstrict-prototypes -Wundef -Wunused -Wwrite-strings -fno-common -I/tmp/destdir/usr/include -I../include -D_GNU_SOURCE -DNO_ANDROID_BACKEND -DUSE_PCRE2 -DPCRE2_CODE_UNIT_WIDTH=8 -Wno-error -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-parameter -Wno-shadow -Wno-uninitialized -Wno-missing-prototypes -Wno-missing-declarations -Wno-deprecated-declarations -fPIC -I../include -I/opt/hostedtoolcache/Python/3.9.16/x64/include/python3.9 -c selinuxswig_python_wrap.c -o build/temp.linux-x86_64-3.9/selinuxswig_python_wrap.o


and second time by

install-pywrap: pywrap
	$(PYTHON) -m pip install --prefix=$(PREFIX) `test -n "$(DESTDIR)" && echo --root $(DESTDIR) --ignore-installed --no-deps` $(PYTHON_SETUP_ARGS) .

clang -fdeclspec -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -O2 -Werror -Wall -Wextra -Wfloat-equal -Wformat=2 -Winit-self -Wmissing-format-attribute -Wmissing-noreturn -Wmissing-prototypes -Wnull-dereference -Wpointer-arith -Wshadow -Wstrict-prototypes -Wundef -Wunused -Wwrite-strings -fno-common -I/tmp/destdir/usr/include -I../include -D_GNU_SOURCE -DNO_ANDROID_BACKEND -DUSE_PCRE2 -DPCRE2_CODE_UNIT_WIDTH=8 -fPIC -I../include -I/opt/hostedtoolcache/Python/3.9.16/x64/include/python3.9 -c selinuxswig_python_wrap.c -o build/temp.linux-x86_64-cpython-39/selinuxswig_python_wrap.o


I'd expect that it's built only in pywrap target and install-pywrap
would just install it.

There's a difference in the output dir - build/temp.linux-x86_64-3.9 vs build/temp.linux-x86_64-cpython-39




> ---
> fixes GitHub CI, see https://github.com/SELinuxProject/selinux/pull/388
> ---
>  libselinux/src/Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
> index 36d57122..f9a1e5f5 100644
> --- a/libselinux/src/Makefile
> +++ b/libselinux/src/Makefile
> @@ -187,7 +187,7 @@ install: all
>  	ln -sf --relative $(DESTDIR)$(SHLIBDIR)/$(LIBSO) $(DESTDIR)$(LIBDIR)/$(TARGET)
>  
>  install-pywrap: pywrap
> -	$(PYTHON) -m pip install --prefix=$(PREFIX) `test -n "$(DESTDIR)" && echo --root $(DESTDIR) --ignore-installed --no-deps` $(PYTHON_SETUP_ARGS) .
> +	CFLAGS="$(CFLAGS) $(SWIG_CFLAGS)" $(PYTHON) -m pip install --prefix=$(PREFIX) `test -n "$(DESTDIR)" && echo --root $(DESTDIR) --ignore-installed --no-deps` $(PYTHON_SETUP_ARGS) .
>  	install -m 644 $(SWIGPYOUT) $(DESTDIR)$(PYTHONLIBDIR)/selinux/__init__.py
>  	ln -sf --relative $(DESTDIR)$(PYTHONLIBDIR)/selinux/_selinux$(PYCEXT) $(DESTDIR)$(PYTHONLIBDIR)/_selinux$(PYCEXT)
>  
> -- 
> 2.40.0
Petr Lautrbach April 26, 2023, 3:53 p.m. UTC | #2
Petr Lautrbach <plautrba@redhat.com> writes:

> Christian Göttsche <cgzones@googlemail.com> writes:
>
>> Explicitly set CFLAGS for the pip install command, similar to calling
>> setup.py, to ignore known compiler warnings treated as errors, e.g.:
>>
>>     selinuxswig_python_wrap.c:3593:19: error: 'sidget' is deprecated [-Werror,-Wdeprecated-declarations]
>>                 result = (int)sidget(arg1);
>>                               ^
>>     selinuxswig_python_wrap.c:15024:1: error: no previous prototype for function 'PyInit__selinux' [-Werror,-Wmissing-prototypes]
>>             SWIG_init(void) {
>>             ^
>>
>> Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
>
>
> It looks like a problem in build system - selinuxswig_python_wrap.o is
> built twice, first time by
>
> pywrap: all selinuxswig_python_exception.i
> 	CFLAGS="$(CFLAGS) $(SWIG_CFLAGS)" $(PYTHON) setup.py build_ext
>
>
> clang -fdeclspec -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -O2 -Werror -Wall -Wextra -Wfloat-equal -Wformat=2 -Winit-self -Wmissing-format-attribute -Wmissing-noreturn -Wmissing-prototypes -Wnull-dereference -Wpointer-arith -Wshadow -Wstrict-prototypes -Wundef -Wunused -Wwrite-strings -fno-common -I/tmp/destdir/usr/include -I../include -D_GNU_SOURCE -DNO_ANDROID_BACKEND -DUSE_PCRE2 -DPCRE2_CODE_UNIT_WIDTH=8 -Wno-error -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-parameter -Wno-shadow -Wno-uninitialized -Wno-missing-prototypes -Wno-missing-declarations -Wno-deprecated-declarations -fPIC -I../include -I/opt/hostedtoolcache/Python/3.9.16/x64/include/python3.9 -c selinuxswig_python_wrap.c -o build/temp.linux-x86_64-3.9/selinuxswig_python_wrap.o
>
>
> and second time by
>
> install-pywrap: pywrap
> 	$(PYTHON) -m pip install --prefix=$(PREFIX) `test -n "$(DESTDIR)" && echo --root $(DESTDIR) --ignore-installed --no-deps` $(PYTHON_SETUP_ARGS) .
>
> clang -fdeclspec -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -O2 -Werror -Wall -Wextra -Wfloat-equal -Wformat=2 -Winit-self -Wmissing-format-attribute -Wmissing-noreturn -Wmissing-prototypes -Wnull-dereference -Wpointer-arith -Wshadow -Wstrict-prototypes -Wundef -Wunused -Wwrite-strings -fno-common -I/tmp/destdir/usr/include -I../include -D_GNU_SOURCE -DNO_ANDROID_BACKEND -DUSE_PCRE2 -DPCRE2_CODE_UNIT_WIDTH=8 -fPIC -I../include -I/opt/hostedtoolcache/Python/3.9.16/x64/include/python3.9 -c selinuxswig_python_wrap.c -o build/temp.linux-x86_64-cpython-39/selinuxswig_python_wrap.o
>
>
> I'd expect that it's built only in pywrap target and install-pywrap
> would just install it.

So according to the internet, pip install does all setup.py operations
[build_ext, build, install, ...] on it's own and therefore pywrap target
with `setup.py build` seems to be useless.

But your change is necessary.

Acked-by: Petr Lautrbach <lautrbach@redhat.com>




>
>
>> ---
>> fixes GitHub CI, see https://github.com/SELinuxProject/selinux/pull/388
>> ---
>>  libselinux/src/Makefile | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
>> index 36d57122..f9a1e5f5 100644
>> --- a/libselinux/src/Makefile
>> +++ b/libselinux/src/Makefile
>> @@ -187,7 +187,7 @@ install: all
>>  	ln -sf --relative $(DESTDIR)$(SHLIBDIR)/$(LIBSO) $(DESTDIR)$(LIBDIR)/$(TARGET)
>>  
>>  install-pywrap: pywrap
>> -	$(PYTHON) -m pip install --prefix=$(PREFIX) `test -n "$(DESTDIR)" && echo --root $(DESTDIR) --ignore-installed --no-deps` $(PYTHON_SETUP_ARGS) .
>> +	CFLAGS="$(CFLAGS) $(SWIG_CFLAGS)" $(PYTHON) -m pip install --prefix=$(PREFIX) `test -n "$(DESTDIR)" && echo --root $(DESTDIR) --ignore-installed --no-deps` $(PYTHON_SETUP_ARGS) .
>>  	install -m 644 $(SWIGPYOUT) $(DESTDIR)$(PYTHONLIBDIR)/selinux/__init__.py
>>  	ln -sf --relative $(DESTDIR)$(PYTHONLIBDIR)/selinux/_selinux$(PYCEXT) $(DESTDIR)$(PYTHONLIBDIR)/_selinux$(PYCEXT)
>>  
>> -- 
>> 2.40.0
James Carter May 3, 2023, 4:24 p.m. UTC | #3
On Wed, Apr 26, 2023 at 12:06 PM Petr Lautrbach <plautrba@redhat.com> wrote:
>
> Petr Lautrbach <plautrba@redhat.com> writes:
>
> > Christian Göttsche <cgzones@googlemail.com> writes:
> >
> >> Explicitly set CFLAGS for the pip install command, similar to calling
> >> setup.py, to ignore known compiler warnings treated as errors, e.g.:
> >>
> >>     selinuxswig_python_wrap.c:3593:19: error: 'sidget' is deprecated [-Werror,-Wdeprecated-declarations]
> >>                 result = (int)sidget(arg1);
> >>                               ^
> >>     selinuxswig_python_wrap.c:15024:1: error: no previous prototype for function 'PyInit__selinux' [-Werror,-Wmissing-prototypes]
> >>             SWIG_init(void) {
> >>             ^
> >>
> >> Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
> >
> >
> > It looks like a problem in build system - selinuxswig_python_wrap.o is
> > built twice, first time by
> >
> > pywrap: all selinuxswig_python_exception.i
> >       CFLAGS="$(CFLAGS) $(SWIG_CFLAGS)" $(PYTHON) setup.py build_ext
> >
> >
> > clang -fdeclspec -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -O2 -Werror -Wall -Wextra -Wfloat-equal -Wformat=2 -Winit-self -Wmissing-format-attribute -Wmissing-noreturn -Wmissing-prototypes -Wnull-dereference -Wpointer-arith -Wshadow -Wstrict-prototypes -Wundef -Wunused -Wwrite-strings -fno-common -I/tmp/destdir/usr/include -I../include -D_GNU_SOURCE -DNO_ANDROID_BACKEND -DUSE_PCRE2 -DPCRE2_CODE_UNIT_WIDTH=8 -Wno-error -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-parameter -Wno-shadow -Wno-uninitialized -Wno-missing-prototypes -Wno-missing-declarations -Wno-deprecated-declarations -fPIC -I../include -I/opt/hostedtoolcache/Python/3.9.16/x64/include/python3.9 -c selinuxswig_python_wrap.c -o build/temp.linux-x86_64-3.9/selinuxswig_python_wrap.o
> >
> >
> > and second time by
> >
> > install-pywrap: pywrap
> >       $(PYTHON) -m pip install --prefix=$(PREFIX) `test -n "$(DESTDIR)" && echo --root $(DESTDIR) --ignore-installed --no-deps` $(PYTHON_SETUP_ARGS) .
> >
> > clang -fdeclspec -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -O2 -Werror -Wall -Wextra -Wfloat-equal -Wformat=2 -Winit-self -Wmissing-format-attribute -Wmissing-noreturn -Wmissing-prototypes -Wnull-dereference -Wpointer-arith -Wshadow -Wstrict-prototypes -Wundef -Wunused -Wwrite-strings -fno-common -I/tmp/destdir/usr/include -I../include -D_GNU_SOURCE -DNO_ANDROID_BACKEND -DUSE_PCRE2 -DPCRE2_CODE_UNIT_WIDTH=8 -fPIC -I../include -I/opt/hostedtoolcache/Python/3.9.16/x64/include/python3.9 -c selinuxswig_python_wrap.c -o build/temp.linux-x86_64-cpython-39/selinuxswig_python_wrap.o
> >
> >
> > I'd expect that it's built only in pywrap target and install-pywrap
> > would just install it.
>
> So according to the internet, pip install does all setup.py operations
> [build_ext, build, install, ...] on it's own and therefore pywrap target
> with `setup.py build` seems to be useless.
>
> But your change is necessary.
>
> Acked-by: Petr Lautrbach <lautrbach@redhat.com>
>

Merged.
Thanks,
Jim

>
>
>
> >
> >
> >> ---
> >> fixes GitHub CI, see https://github.com/SELinuxProject/selinux/pull/388
> >> ---
> >>  libselinux/src/Makefile | 2 +-
> >>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
> >> index 36d57122..f9a1e5f5 100644
> >> --- a/libselinux/src/Makefile
> >> +++ b/libselinux/src/Makefile
> >> @@ -187,7 +187,7 @@ install: all
> >>      ln -sf --relative $(DESTDIR)$(SHLIBDIR)/$(LIBSO) $(DESTDIR)$(LIBDIR)/$(TARGET)
> >>
> >>  install-pywrap: pywrap
> >> -    $(PYTHON) -m pip install --prefix=$(PREFIX) `test -n "$(DESTDIR)" && echo --root $(DESTDIR) --ignore-installed --no-deps` $(PYTHON_SETUP_ARGS) .
> >> +    CFLAGS="$(CFLAGS) $(SWIG_CFLAGS)" $(PYTHON) -m pip install --prefix=$(PREFIX) `test -n "$(DESTDIR)" && echo --root $(DESTDIR) --ignore-installed --no-deps` $(PYTHON_SETUP_ARGS) .
> >>      install -m 644 $(SWIGPYOUT) $(DESTDIR)$(PYTHONLIBDIR)/selinux/__init__.py
> >>      ln -sf --relative $(DESTDIR)$(PYTHONLIBDIR)/selinux/_selinux$(PYCEXT) $(DESTDIR)$(PYTHONLIBDIR)/_selinux$(PYCEXT)
> >>
> >> --
> >> 2.40.0
>
diff mbox series

Patch

diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
index 36d57122..f9a1e5f5 100644
--- a/libselinux/src/Makefile
+++ b/libselinux/src/Makefile
@@ -187,7 +187,7 @@  install: all
 	ln -sf --relative $(DESTDIR)$(SHLIBDIR)/$(LIBSO) $(DESTDIR)$(LIBDIR)/$(TARGET)
 
 install-pywrap: pywrap
-	$(PYTHON) -m pip install --prefix=$(PREFIX) `test -n "$(DESTDIR)" && echo --root $(DESTDIR) --ignore-installed --no-deps` $(PYTHON_SETUP_ARGS) .
+	CFLAGS="$(CFLAGS) $(SWIG_CFLAGS)" $(PYTHON) -m pip install --prefix=$(PREFIX) `test -n "$(DESTDIR)" && echo --root $(DESTDIR) --ignore-installed --no-deps` $(PYTHON_SETUP_ARGS) .
 	install -m 644 $(SWIGPYOUT) $(DESTDIR)$(PYTHONLIBDIR)/selinux/__init__.py
 	ln -sf --relative $(DESTDIR)$(PYTHONLIBDIR)/selinux/_selinux$(PYCEXT) $(DESTDIR)$(PYTHONLIBDIR)/_selinux$(PYCEXT)