Skip to content
Browse files

Don't generate .pyc files ourself

It's good for cross-compilation, because in that case binaries produced
by CXX are not runnable.

(cherry picked from commit bfd1edc)
  • Loading branch information...
1 parent e391c4e commit b29e7d57b2b7e1fb70b007299f499ae96b062304 @DarthGandalf DarthGandalf committed
Showing with 3 additions and 66 deletions.
  1. +3 −12 modules/modpython/Makefile.inc
  2. +0 −54 modules/modpython/compiler.cpp
View
15 modules/modpython/Makefile.inc
@@ -19,8 +19,7 @@ PYDEPONMOD :=
endif
PYTHONHOOK := modpython_install
-CLEAN += modpython/_znc_core.$(PYCEXT_EXT) modpython/znc_core.pyc
-CLEAN += modpython/znc.pyc modpython/compiler *.pyc
+CLEAN += modpython/_znc_core.$(PYCEXT_EXT)
CLEAN += modpython/_znc_core.o modpython/compiler.o
ifneq "$(SWIG)" ""
# Only delete these files if we can regenerate them
@@ -40,16 +39,10 @@ endif
install: $(PYTHONHOOK)
-# This will run: modpython/compiler blah.py blah.pyc
-%.pyc: modpython/compiler %.py
- $(E) Compiling $@...
- $(Q)$^ $@
-
ifeq "$(PYTHON_ON)" "yes"
all: modpython_all
endif
-modpython_all: modpython/_znc_core.$(PYCEXT_EXT) modpython/znc.pyc modpython/znc_core.pyc
-modpython_all: $(addsuffix c, $(notdir $(wildcard $(srcdir)/*.py)))
+modpython_all: modpython/_znc_core.$(PYCEXT_EXT)
modpython/_znc_core.o: modpython/_znc_core.cpp Makefile
@mkdir -p modpython
@@ -77,15 +70,13 @@ modpython/compiler: modpython/compiler.o Makefile
$(Q)$(CXX) -o $@ $< $(PY_LDFLAGS)
modpython_install: install_datadir modpython_all
- -for i in *.pyc $(srcdir)/*.py; do \
+ -for i in $(srcdir)/*.py; do \
$(INSTALL_DATA) $$i $(DESTDIR)$(MODDIR); \
done
mkdir -p $(DESTDIR)$(MODDIR)/modpython
$(INSTALL_PROGRAM) modpython/_znc_core.$(PYCEXT_EXT) $(DESTDIR)$(MODDIR)/modpython
- $(INSTALL_DATA) modpython/znc_core.pyc $(DESTDIR)$(MODDIR)/modpython
if test -r modpython/znc_core.py;\
then $(INSTALL_DATA) modpython/znc_core.py $(DESTDIR)$(MODDIR)/modpython;\
else $(INSTALL_DATA) $(srcdir)/modpython/znc_core.py $(DESTDIR)$(MODDIR)/modpython;\
fi
- $(INSTALL_DATA) modpython/znc.pyc $(DESTDIR)$(MODDIR)/modpython
$(INSTALL_DATA) $(srcdir)/modpython/znc.py $(DESTDIR)$(MODDIR)/modpython
View
54 modules/modpython/compiler.cpp
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2004-2013 ZNC, see the NOTICE file for details.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <Python.h>
-#include <string>
-
-void fail(PyObject* py, int n) {
- // Doesn't clear any variables, but meh, finalize anyway...
- if (!py) {
- PyErr_Print();
- Py_Finalize();
- exit(n);
- }
-}
-
-int main(int argc, char** argv) {
- // Don't use this as an example: this has awful memory leaks.
- Py_Initialize();
-
- PyObject* pyModule = PyImport_ImportModule("py_compile");
- fail(pyModule, 1);
-
- PyObject* pyFunc = PyObject_GetAttrString(pyModule, "compile");
- fail(pyFunc, 2);
-
- std::string cfile = argv[2];
- if (cfile.find('/') == std::string::npos) {
- cfile = "./" + cfile;
- }
- PyObject* pyKW = Py_BuildValue("{sssN}", "cfile", cfile.c_str(), "doraise", Py_True);
- fail(pyKW, 3);
-
- PyObject* pyArg = Py_BuildValue("(s)", argv[1]);
- fail(pyArg, 4);
-
- PyObject* pyRes = PyObject_Call(pyFunc, pyArg, pyKW);
- fail(pyRes, 5);
-
- Py_Finalize();
- return 0;
-}

0 comments on commit b29e7d5

Please sign in to comment.
Something went wrong with that request. Please try again.