PSARC/2014/108 pycparser: complete C99 parser in pure Python
authorDanek Duvall <danek.duvall@oracle.com>
Tue, 22 Apr 2014 11:33:57 -0700
changeset 1845 caa6e0a2a2e4
parent 1844 5bd55496588c
child 1846 df40919e04fa
PSARC/2014/108 pycparser: complete C99 parser in pure Python 18468557 integrate pycparser
components/python/pycparser/Makefile
components/python/pycparser/patches/find-cpp.patch
components/python/pycparser/pycparser-PYVER.p5m
components/python/pycparser/resolve.deps
make-rules/setup.py.mk
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/components/python/pycparser/Makefile	Tue Apr 22 11:33:57 2014 -0700
@@ -0,0 +1,64 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+#
+
+include ../../../make-rules/shared-macros.mk
+
+COMPONENT_NAME=		pycparser
+COMPONENT_VERSION=	2.10
+COMPONENT_SRC=		$(COMPONENT_NAME)-$(COMPONENT_VERSION)
+COMPONENT_ARCHIVE=	$(COMPONENT_SRC).tar.gz
+COMPONENT_ARCHIVE_HASH=	\
+    sha256:957d98b661c0b64b580ab6f94b125e09b6714154ee51de40bca16d3f0076b86c
+COMPONENT_ARCHIVE_URL=	$(call pypi_url)
+COMPONENT_PROJECT_URL=	https://github.com/eliben/pycparser
+COMPONENT_BUGDB=	python-mod/pycparser
+
+include $(WS_TOP)/make-rules/prep.mk
+include $(WS_TOP)/make-rules/setup.py.mk
+include $(WS_TOP)/make-rules/ips.mk
+
+ASLR_MODE = $(ASLR_NOT_APPLICABLE)
+
+COMPONENT_TEST_DIR =	$(SOURCE_DIR)
+COMPONENT_TEST_CMD =	py.test-$(PYTHON_VERSION)
+COMPONENT_TEST_ARGS =	--resultlog $(@D)/testresults
+COMPONENT_TEST_ARGS +=	-p no:codechecker
+COMPONENT_TEST_ENV +=	PATH=$$PATH:$(BUILD_DIR)/bin
+
+$(SOURCE_DIR)/pycparser/ply/lex.py: $(SOURCE_DIR)/.patched
+
+$(BUILD_DIR)/license.ply: $(SOURCE_DIR)/pycparser/ply/lex.py
+	nawk '/^# Copyright / {p=1} /^# ---/ {p=0} p == 1 {print substr($$0, 3)}' $< > $@
+
+# common targets
+build:		$(BUILD_NO_ARCH)
+
+install:	$(INSTALL_NO_ARCH) $(BUILD_DIR)/license.ply
+
+test:		$(TEST_NO_ARCH)
+
+BUILD_PKG_DEPENDENCIES =	$(BUILD_TOOLS)
+
+include $(WS_TOP)/make-rules/depend.mk
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/components/python/pycparser/patches/find-cpp.patch	Tue Apr 22 11:33:57 2014 -0700
@@ -0,0 +1,75 @@
+Solaris doesn't deliver a /usr/bin/cpp.  We have our own cpp in
+/usr/lib/cpp, and we deliver GNU cpp in /usr/bin/gcpp, but we might not
+find those simply by looking in $PATH.  So if we fail, try extra hard to
+execute another cpp.  We try GNU's first, since it's more likely what folks
+using pycparser will expect (for instance, it handles C++-style comments).
+
+--- pycparser-2.10/pycparser/__init__.py	Sat Aug  3 06:05:22 2013
++++ pycparser-2.10/pycparser/__init__.py	Fri Apr 11 14:58:36 2014
+@@ -10,6 +10,7 @@
+ __all__ = ['c_lexer', 'c_parser', 'c_ast']
+ __version__ = '2.10'
+ 
++import errno
+ from subprocess import Popen, PIPE
+ from .c_parser import CParser
+ 
+@@ -28,29 +29,41 @@
+         When successful, returns the preprocessed file's contents.
+         Errors from cpp will be printed out.
+     """
+-    path_list = [cpp_path]
+-    if isinstance(cpp_args, list):
+-        path_list += cpp_args
+-    elif cpp_args != '':
+-        path_list += [cpp_args]
+-    path_list += [filename]
++    cpp_list = [cpp_path, "/usr/bin/gcpp", "/usr/lib/cpp"]
+ 
+-    try:
+-        # Note the use of universal_newlines to treat all newlines
+-        # as \n for Python's purpose
+-        #
+-        pipe = Popen(   path_list,
+-                        stdout=PIPE,
+-                        universal_newlines=True)
+-        text = pipe.communicate()[0]
+-    except OSError as e:
++    for cpp_path in cpp_list:
++        path_list = [cpp_path]
++        if isinstance(cpp_args, list):
++            path_list += cpp_args
++        elif cpp_args != '':
++            path_list += [cpp_args]
++        path_list += [filename]
++
++        try:
++            # Note the use of universal_newlines to treat all newlines
++            # as \n for Python's purpose
++            #
++            pipe = Popen(   path_list,
++                            stdout=PIPE,
++                            universal_newlines=True)
++            text = pipe.communicate()[0]
++        except OSError as e:
++            # If cpp couldn't be found, just try the next one.
++            if e.errno == errno.ENOENT:
++                continue
++            # If we ran into some other error, raise a RuntimeError.
++            raise RuntimeError("Unable to invoke 'cpp'.\n" +
++                ('Original error: %s' % e))
++
++        return text
++
++    else:
++        # If we couldn't find a cpp, then raise a RuntimeError.
+         raise RuntimeError("Unable to invoke 'cpp'.  " +
+             'Make sure its path was passed correctly\n' +
+             ('Original error: %s' % e))
+ 
+-    return text
+ 
+-
+ def parse_file(filename, use_cpp=False, cpp_path='cpp', cpp_args='',
+                parser=None):
+     """ Parse a C file using pycparser.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/components/python/pycparser/pycparser-PYVER.p5m	Tue Apr 22 11:33:57 2014 -0700
@@ -0,0 +1,70 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+#
+
+set name=pkg.fmri \
+    value=pkg:/library/python/pycparser-$(PYV)@$(IPS_COMPONENT_VERSION),$(BUILD_VERSION)
+set name=pkg.summary value="Complete C99 parser in pure Python"
+set name=pkg.description \
+    value="pycparser is a parser for the C language, written in pure Python. It is a module designed to be easily integrated into applications that need to parse C source code."
+set name=com.oracle.info.description value="the pycparser Python module"
+set name=com.oracle.info.tpno value=16938
+set name=info.classification \
+    value=org.opensolaris.category.2008:Development/Python \
+    value=org.opensolaris.category.2008:Development/C
+set name=info.source-url value=$(COMPONENT_ARCHIVE_URL)
+set name=info.upstream value="Eli Bendersky <[email protected]>"
+set name=info.upstream-url value=$(COMPONENT_PROJECT_URL)
+set name=org.opensolaris.arc-caseid value=PSARC/2014/108
+set name=org.opensolaris.consolidation value=$(CONSOLIDATION)
+#
+file path=usr/lib/python$(PYVER)/vendor-packages/pycparser-$(COMPONENT_VERSION)-py$(PYVER).egg-info
+file path=usr/lib/python$(PYVER)/vendor-packages/pycparser/__init__.py
+file path=usr/lib/python$(PYVER)/vendor-packages/pycparser/_ast_gen.py
+file path=usr/lib/python$(PYVER)/vendor-packages/pycparser/_build_tables.py
+file path=usr/lib/python$(PYVER)/vendor-packages/pycparser/_c_ast.cfg
+file path=usr/lib/python$(PYVER)/vendor-packages/pycparser/ast_transforms.py
+file path=usr/lib/python$(PYVER)/vendor-packages/pycparser/c_ast.py
+file path=usr/lib/python$(PYVER)/vendor-packages/pycparser/c_generator.py
+file path=usr/lib/python$(PYVER)/vendor-packages/pycparser/c_lexer.py
+file path=usr/lib/python$(PYVER)/vendor-packages/pycparser/c_parser.py
+file path=usr/lib/python$(PYVER)/vendor-packages/pycparser/lextab.py
+file path=usr/lib/python$(PYVER)/vendor-packages/pycparser/ply/__init__.py
+file path=usr/lib/python$(PYVER)/vendor-packages/pycparser/ply/cpp.py
+file path=usr/lib/python$(PYVER)/vendor-packages/pycparser/ply/ctokens.py
+file path=usr/lib/python$(PYVER)/vendor-packages/pycparser/ply/lex.py
+file path=usr/lib/python$(PYVER)/vendor-packages/pycparser/ply/yacc.py
+file path=usr/lib/python$(PYVER)/vendor-packages/pycparser/plyparser.py
+file path=usr/lib/python$(PYVER)/vendor-packages/pycparser/yacctab.py
+#
+license LICENSE license=BSD
+license license.ply license=BSD.ply
+#
+# force a dependency on the Python runtime
+depend type=require fmri=__TBD pkg.debug.depend.file=python$(PYVER) \
+    pkg.debug.depend.path=usr/bin
+
+# force a dependency on the pycparser package
+depend type=require \
+    fmri=library/python/pycparser@$(IPS_COMPONENT_VERSION),$(BUILD_VERSION)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/components/python/pycparser/resolve.deps	Tue Apr 22 11:33:57 2014 -0700
@@ -0,0 +1,2 @@
+runtime/python-26
+runtime/python-27
--- a/make-rules/setup.py.mk	Mon Apr 21 21:34:38 2014 -0700
+++ b/make-rules/setup.py.mk	Tue Apr 22 11:33:57 2014 -0700
@@ -18,7 +18,7 @@
 #
 # CDDL HEADER END
 #
-# Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
 #
 
 $(BUILD_DIR)/%-2.6/.built:		PYTHON_VERSION=2.6
@@ -31,6 +31,11 @@
 $(BUILD_DIR)/$(MACH32)-%/.installed:	BITS=32
 $(BUILD_DIR)/$(MACH64)-%/.installed:	BITS=64
 
+$(BUILD_DIR)/%-2.6/.tested:		PYTHON_VERSION=2.6
+$(BUILD_DIR)/%-2.7/.tested:		PYTHON_VERSION=2.7
+$(BUILD_DIR)/$(MACH32)-%/.tested:	BITS=32
+$(BUILD_DIR)/$(MACH64)-%/.tested:	BITS=64
+
 BUILD_32 = $(PYTHON_VERSIONS:%=$(BUILD_DIR)/$(MACH32)-%/.built)
 BUILD_64 = $(PYTHON_VERSIONS:%=$(BUILD_DIR)/$(MACH64)-%/.built)
 BUILD_NO_ARCH = $(PYTHON_VERSIONS:%=$(BUILD_DIR)/$(MACH)-%/.built)