Permalink
Browse files

Modify app_deps.py to print a .py-only manifest too.

Runs on bin/oil.py and bin/opy_.py.
  • Loading branch information...
Andy Chu
Andy Chu committed Feb 25, 2018
1 parent 58f6ce1 commit 829429b2138535c31b0bf1e717a31ec2375f38a7
Showing with 75 additions and 21 deletions.
  1. +2 −1 bin/opy_.py
  2. +11 −1 build/actions.sh
  3. +42 −18 build/app_deps.py
  4. +18 −0 opy/build.sh
  5. +2 −1 opy/opy_main.py
View
@@ -11,4 +11,5 @@
from opy import opy_main
opy_main.main(sys.argv)
if __name__ == '__main__':
opy_main.main(sys.argv)
View
@@ -65,7 +65,17 @@ app-deps() {
ln -s -f $PWD/build/app_deps.py _tmp
PYTHONPATH=$pythonpath \
$PREPARE_DIR/python -S _tmp/app_deps.py $main_module $prefix
$PREPARE_DIR/python -S _tmp/app_deps.py both $main_module $prefix
}
# .py files to compile
py-to-compile() {
local app_name=${1:-hello}
local pythonpath=${2:-build/testdata}
local main_module=${3:-hello}
PYTHONPATH=$pythonpath \
$PREPARE_DIR/python -S build/app_deps.py py $main_module
}
files-manifest() {
View
@@ -61,8 +61,12 @@ def ImportMain(main_module, old_modules):
yield name, full_path
def PrintManifest(modules, py_out, c_out):
"""Print Python and C modules."""
PY_MODULE = 0
C_MODULE = 1
def FilterModules(modules):
"""Look at __file__ of each module, and classify them as Python or C."""
for module, full_path in modules:
#print 'OLD', module, full_path
@@ -77,17 +81,15 @@ def PrintManifest(modules, py_out, c_out):
#print i, full_path[i+1:]
rel_path = full_path[i + 1:]
# Depending on whether it's cached, we get '.py' or '.pyc'.
# Depending on whether it's cached, the __file__ attribute on the module
# ends with '.py' or '.pyc'.
if full_path.endswith('.py'):
print >>py_out, full_path, rel_path
print >>py_out, full_path + 'c', rel_path + 'c'
yield PY_MODULE, full_path, rel_path
elif full_path.endswith('.pyc'):
# .pyc file
print >>py_out, full_path, rel_path
print >>py_out, full_path[:-1], rel_path[:-1]
yield PY_MODULE, full_path[:-1], rel_path[:-1]
else:
# .so file
print >>c_out, module, full_path
yield C_MODULE, module, full_path
# TODO: Get rid of this?
@@ -106,22 +108,44 @@ def main(argv):
# Set an environment variable so dependencies in debug mode can be excluded.
os.environ['_OVM_DEPS'] = '1'
main_module = argv[0]
prefix = argv[1]
action = argv[1]
main_module = argv[2]
log('Before importing: %d modules', len(OLD_MODULES))
py_out_path = prefix + '-py.txt'
c_out_path = prefix + '-c.txt'
if action == 'both': # Write files for both .py and .so dependencies
prefix = argv[3]
py_out_path = prefix + '-py.txt'
c_out_path = prefix + '-c.txt'
modules = ImportMain(main_module, OLD_MODULES)
with open(py_out_path, 'w') as py_out, open(c_out_path, 'w') as c_out:
for mod_type, x, y in FilterModules(modules):
if mod_type == PY_MODULE:
print >>py_out, x, y
print >>py_out, x + 'c', y + 'c' # .pyc goes in bytecode.zip too
elif mod_type == C_MODULE:
print >>c_out, x, y # mod_name, full_path
else:
raise AssertionError(mod_type)
modules = ImportMain(main_module, OLD_MODULES)
elif action == 'py': # Just .py files
modules = ImportMain(main_module, OLD_MODULES)
for mod_type, full_path, rel_path in FilterModules(modules):
if mod_type == PY_MODULE:
opy_input = full_path
opy_output = rel_path + 'c' # output is .pyc
print opy_input, opy_output
with open(py_out_path, 'w') as py_out, open(c_out_path, 'w') as c_out:
PrintManifest(modules, py_out, c_out)
else:
raise AssertionError('Invalid action %r' % action)
if __name__ == '__main__':
try:
sys.exit(main(sys.argv[1:]))
sys.exit(main(sys.argv))
except Error, e:
print >> sys.stderr, 'py-deps:', e.args[0]
print >>sys.stderr, 'py-deps:', e.args[0]
sys.exit(1)
View
@@ -139,4 +139,22 @@ oil-repo() {
#_compile-tree $src _tmp/osh-stdlib/ stdlib "${files[@]}"
}
oil-bin() {
# This gets us the absolute path of all the .py files we put in bytecode.zip.
#awk '$1 ~ /\.py$/ { print $1 }' ../_build/oil/app-deps-py.txt
# We actually need a mode for app-deps that prints python deps with relative
# paths only.
pushd ..
build/actions.sh py-to-compile oil '.' 'bin.oil'
popd
}
opy-bin() {
pushd ..
build/actions.sh py-to-compile opy_ '.' 'bin.opy_'
popd
}
"$@"
View
@@ -25,7 +25,8 @@
from .compiler2 import pycodegen
from .compiler2 import opcode
from .byterun import execfile
# Disabled for now because byterun imports 'six', and that breaks the build.
#from .byterun import execfile
from .util_opy import log

0 comments on commit 829429b

Please sign in to comment.