Permalink
Browse files

A basic OPy build works.

- Separate Makefile into build/{hello,oil,opy}.mk.
- Adjust the main() of bin/opy_.py.

Also:

- Updates to the line count script.
  • Loading branch information...
Andy Chu
Andy Chu committed Mar 4, 2018
1 parent 1eaa262 commit 5007894ecec561da37a6161bf504664745f95cf8
Showing with 204 additions and 158 deletions.
  1. +9 −6 Makefile
  2. +24 −1 bin/opy_.py
  3. +50 −0 build/hello.mk
  4. +64 −0 build/oil.mk
  5. +1 −0 build/opy-manifest.txt
  6. +38 −0 build/opy.mk
  7. +2 −2 opy/count.sh
  8. +6 −20 opy/opy_main.py
  9. +9 −128 portable-rules.mk
  10. +1 −1 scripts/count.sh
View
@@ -74,7 +74,7 @@
# handling directories but I don't know it.
# NOTE: _devbuild is made by build/dev.sh. That directory is NOT cleaned with
# 'make clean'.
$(shell mkdir -p _bin _release _tmp _build/hello _build/oil)
$(shell mkdir -p _bin _release _tmp _build/hello _build/oil _build/opy)
ACTIONS_SH := build/actions.sh
COMPILE_SH := build/compile.sh
@@ -113,12 +113,15 @@ install:
print-%:
@echo $*=$($*)
# This file is intentionally NOT included in the release tarball. This is so
# that we don't try to rebuild say _build/oil/bytecode-opy.zip, which is
# already pre-built and included in the release tarball. Portable rules can be
# done on the developer machine rather than on the end-user machine.
# These files is intentionally NOT included in release tarballs. For example,
# we don't want try to rebuild _build/oil/bytecode-opy.zip, which is already
# included in the release tarball. Portable rules can be run on the developer
# machine rather than on the end-user machine.
-include portable-rules.mk
-include portable-rules.mk # Must come first
-include build/hello.mk
-include build/oil.mk
-include build/opy.mk
#
# Native Builds
View
@@ -1,4 +1,5 @@
#!/usr/bin/env python
from __future__ import print_function
"""
opy_.py
"""
@@ -9,7 +10,29 @@
this_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
sys.path.append(os.path.join(this_dir, '..'))
from core import args
from opy.util_opy import log
from opy import opy_main
# TODO: move to quick ref?
_OPY_USAGE = 'Usage: opy_ MAIN [OPTION]... [ARG]...'
# TODO: Make this more consistent with bin/oil.py.
def main(argv):
try:
opy_main.OpyMain(argv[1:])
except args.UsageError as e:
print(_OPY_USAGE, file=sys.stderr)
print(str(e), file=sys.stderr)
sys.exit(2)
except RuntimeError as e:
log('FATAL: %s', e)
sys.exit(1)
if __name__ == '__main__':
opy_main.main(sys.argv)
main(sys.argv)
View
@@ -0,0 +1,50 @@
# hello.mk: For the demo hello app.
# C module dependencies
-include _build/hello/ovm.d
# What Python module to run.
_build/hello/main_name.c:
$(ACTIONS_SH) main-name hello hello.ovm > $@
# Dependencies calculated by importing main. The guard is because ovm.d
# depends on it. Is that correct? We'll skip it before 'make dirs'.
_build/hello/app-deps-%.txt: $(HELLO_SRCS) \
_build/detected-config.sh build/app_deps.py
test -d _build/hello && \
$(ACTIONS_SH) app-deps hello build/testdata hello
_build/hello/py-to-compile.txt: \
_build/detected-config.sh build/app_deps.py
test -d _build/hello && \
$(ACTIONS_SH) py-to-compile build/testdata hello > $@
# NOTE: We could use src/dest paths pattern instead of _build/app?
#
# TODO:
# - Deps need to be better. Depend on .pyc and .py. I guess
# app-deps hello will compile the .pyc files. Don't need a separate action.
# %.pyc : %py
HELLO_BYTECODE_DEPS := \
build/testdata/hello-version.txt \
_build/release-date.txt \
build/testdata/hello-manifest.txt
_build/hello/bytecode-cpython.zip: $(HELLO_SRCS) $(HELLO_BYTECODE_DEPS) \
_build/hello/app-deps-cpython.txt \
_build/runpy-deps-cpython.txt
{ echo 'build/testdata/hello-version.txt hello-version.txt'; \
echo '_build/release-date.txt release-date.txt'; \
cat build/testdata/hello-manifest.txt \
_build/hello/app-deps-cpython.txt \
_build/runpy-deps-cpython.txt; \
} | build/make_zip.py $@
_build/hello/bytecode-opy.zip: $(HELLO_SRCS) $(HELLO_BYTECODE_DEPS) \
_build/hello/opy-app-deps.txt
{ echo 'build/testdata/hello-version.txt hello-version.txt'; \
echo '_build/release-date.txt release-date.txt'; \
cat build/testdata/hello-manifest.txt \
_build/hello/opy-app-deps.txt; \
} | build/make_zip.py $@
View
@@ -0,0 +1,64 @@
# oil.mk: Build rules for oil.ovm.
# C module dependencies
-include _build/oil/ovm.d
_build/oil/main_name.c:
$(ACTIONS_SH) main-name bin.oil oil.ovm > $@
# Dependencies calculated by importing main.
# NOTE: The list of files is used both to compile and to make a tarball.
# - For compiling, we should respect _HAVE_READLINE in detected_config
# - For the tarball, we should ALWAYS include readline.
#
# BUG: Running 'make' the first time files because it can't find the '_build'
# package. build/doc.sh currently makes _build/__init__.py.
_build/oil/app-deps-%.txt: _build/detected-config.sh build/app_deps.py
test -d _build/oil && \
$(ACTIONS_SH) app-deps oil $(REPO_ROOT) bin.oil
_build/oil/py-to-compile.txt: _build/detected-config.sh build/app_deps.py
test -d _build/oil && \
$(ACTIONS_SH) py-to-compile $(REPO_ROOT) bin.oil > $@
_devbuild/gen/osh_help.py: doc/osh-quick-ref-pages.txt
build/doc.sh osh-quick-ref
# NOTE: I should really depend on every file in build/oil-manifest.txt!
OIL_BYTECODE_DEPS := \
_build/release-date.txt \
build/oil-manifest.txt \
_devbuild/gen/osh_help.py
# NOTES:
# - _devbuild/gen/osh_help.py is a minor hack to depend on the entire
# _devbuild/osh-quick-ref dir, since they both get generated by the same
# build action. (Hidden targets are known to cause problems with GNU Make.)
# - release-date.txt is in different location on purpose, so we don't show it
# in dev mode.
# - Do we need $(OIL_SRCS) as dependencies?
_build/oil/bytecode-cpython-manifest.txt: $(OIL_BYTECODE_DEPS) \
_build/oil/app-deps-cpython.txt \
_build/runpy-deps-cpython.txt
{ echo '_build/release-date.txt release-date.txt'; \
cat build/oil-manifest.txt \
_build/oil/app-deps-cpython.txt \
_build/runpy-deps-cpython.txt; \
$(ACTIONS_SH) quick-ref-manifest _devbuild/osh-quick-ref; \
$(ACTIONS_SH) pyc-version-manifest $@; \
} > $@
# NOTE: runpy deps are included in opy-app-deps.txt.
_build/oil/bytecode-opy-manifest.txt: $(OIL_BYTECODE_DEPS) \
_build/oil/opy-app-deps.txt
{ echo '_build/release-date.txt release-date.txt'; \
cat build/oil-manifest.txt \
_build/oil/opy-app-deps.txt; \
$(ACTIONS_SH) quick-ref-manifest _devbuild/osh-quick-ref; \
$(ACTIONS_SH) pyc-version-manifest $@; \
} > $@
_build/oil/bytecode-%.zip: _build/oil/bytecode-%-manifest.txt
build/make_zip.py $@ < $^
View
@@ -0,0 +1 @@
oil-version.txt oil-version.txt
View
@@ -0,0 +1,38 @@
# opy.mk: Portable build rulesf or OPy.
# TODO:
# - Grammar
# - We don't need a configure script?
# - build/oil.mk and build/hello.mk?
#
# Use release-date I guess?
-include _build/opy/ovm.d
_build/opy/main_name.c:
$(ACTIONS_SH) main-name bin.opy_ opy.ovm > $@
_build/opy/app-deps-%.txt: _build/detected-config.sh build/app_deps.py
test -d _build/opy && \
$(ACTIONS_SH) app-deps opy $(REPO_ROOT) bin.opy_
_build/opy/py-to-compile.txt: _build/detected-config.sh build/app_deps.py
test -d _build/opy && \
$(ACTIONS_SH) py-to-compile $(REPO_ROOT) bin.opy_ > $@
OPY_BYTECODE_DEPS := \
_build/release-date.txt \
build/opy-manifest.txt
# NOTE: runpy deps are included in opy-app-deps.txt.
_build/opy/bytecode-opy-manifest.txt: $(OPY_BYTECODE_DEPS) \
_build/opy/opy-app-deps.txt
{ echo '_build/release-date.txt release-date.txt'; \
cat build/opy-manifest.txt \
_build/opy/opy-app-deps.txt; \
$(ACTIONS_SH) pyc-version-manifest $@; \
} > $@
_build/opy/bytecode-%.zip: _build/opy/bytecode-%-manifest.txt
build/make_zip.py $@ < $^
View
@@ -18,8 +18,8 @@ all() {
echo opy_main.py util_opy.py | _count
echo
echo PARSER GENERATOR
echo pytree.py pgen2/*.py | _count
echo LEXER, PARSER GENERATOR, AND GRAMMR
echo pytree.py pgen2/*.py py27.grammar | _count
echo
# ast is generated
View
@@ -30,6 +30,8 @@
from .util_opy import log
from core import args
# From lib2to3/pygram.py. This takes the place of the 'symbol' module.
# compiler/transformer module needs this.
@@ -191,7 +193,10 @@ def py2st(gr, raw_node):
dr = driver.Driver(gr, convert=convert)
action = argv[0]
try:
action = argv[0]
except IndexError:
raise args.UsageError('opy: Missing required subcommand.')
if action == 'pgen2':
grammar_path = argv[1]
@@ -325,22 +330,3 @@ def py2st(gr, raw_node):
# yes.
# Node(prefix, children)
class UsageError(RuntimeError):
""" Exception for incorrect command line usage. """
_OPY_USAGE = 'Usage: opy_ MAIN [OPTION]... [ARG]...'
def main(argv):
try:
OpyMain(argv[1:])
except UsageError as e:
print(_OPY_USAGE, file=sys.stderr)
print(str(e), file=sys.stderr)
sys.exit(2)
except RuntimeError as e:
log('FATAL: %s', e)
sys.exit(1)
Oops, something went wrong.

0 comments on commit 5007894

Please sign in to comment.