]> xenbits.xensource.com Git - unikraft/libs/python3.git/commitdiff
Makefile.uk: Improve generating the python rootfs
authorAndrei Tatar <andrei@unikraft.io>
Tue, 18 Jul 2023 20:31:37 +0000 (22:31 +0200)
committerUnikraft <monkey@unikraft.io>
Fri, 11 Aug 2023 16:00:37 +0000 (16:00 +0000)
This change reworks the make targets that generate the python rootfs:
- Do not use hardcoded python version
- Provide the option of generating .pyc files in the root or not
- Error out or warn the user if a python version mismatch might subtly
  break the resulting rootfs

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Maria Sfiraiala <maria.sfiraiala@gmail.com>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #15

Makefile.uk

index a170a475c29288f34f117a92f195576f477d0949..88e403fed17279a27c6b6b1429ff146dc441807f 100644 (file)
@@ -494,7 +494,11 @@ PYTHON_ROOTFS = $(APP_BASE)/$(path)
 
 # Create virtual environment
 $(PYTHON_ROOTFS)/.keep: $(LIBPYTHON3_BUILD)/.origin
-       python3 -m venv $(PYTHON_ROOTFS) && touch $@
+       @test $(LIBPYTHON3_VERSION) = `python -V | cut -d' ' -f2 | cut -d. -f1,2` || \
+               (echo -e "WARNING: creating virtualenv with wrong python version, pip might not work correctly\nPress return to continue" && read)
+       python3 -m venv $(PYTHON_ROOTFS)
+       find "$(PYTHON_ROOTFS)" -type d -name '__pycache__' | xargs rm -rf
+       touch $@
 
 # Configure origin
 $(PYTHON_ROOTFS)/.configured: $(PYTHON_ROOTFS)/.keep
@@ -504,8 +508,15 @@ $(PYTHON_ROOTFS)/.configured: $(PYTHON_ROOTFS)/.keep
 # Install Python standard library into virtual environment
 $(PYTHON_ROOTFS)/.done: $(PYTHON_ROOTFS)/.configured
        cd $(LIBPYTHON3_SRC) && make libinstall
-       cp $(LIBPYTHON3_BASE)/_sysconfigdata.py $(PYTHON_ROOTFS)/lib/python3.7/
+       cp $(LIBPYTHON3_BASE)/_sysconfigdata.py $(PYTHON_ROOTFS)/lib/python$(LIBPYTHON3_VERSION)/
+       touch $@
+
+$(PYTHON_ROOTFS)/.compiled: python-rootfs
+       test $(LIBPYTHON3_VERSION) = `python -V | cut -d' ' -f2 | cut -d. -f1,2` || \
+               (echo "ERROR: local Python version is not $(LIBPYTHON3_VERSION), cannot compile .py files" && false)
+       python3 -m compileall -x 'lib2to3/|test/bad' "$(PYTHON_ROOTFS)/lib"
        touch $@
 
 .PHONY: python-rootfs
 python-rootfs: $(PYTHON_ROOTFS)/.done
+python-rootfs-compiled: $(PYTHON_ROOTFS)/.compiled