#!/usr/bin/env bash # # Build actions used in the Makefile. # # Usage: # ./actions.sh set -o nounset set -o pipefail set -o errexit source build/common.sh proc write-release-date { mkdir -p _build # Makefile makes this, but scripts/release.sh needs it too # Write a readable, sortable date that is independent of time zone. date --utc --rfc-3339 seconds > _build/release-date.txt } proc main-name { local python_main=$(1:-hello) local ovm_bundle_prefix=$(2:-hello.ovm) cat << """ char* MAIN_NAME = "$python_main"; #if OVM_DEBUG char* OVM_BUNDLE_FILENAME = "$(ovm_bundle_prefix)-dbg"; #else char* OVM_BUNDLE_FILENAME = "$ovm_bundle_prefix"; #endif """ } proc c-module-toc { cd $PY27 ../build/c_module_toc.py } # Modules needed to 'import runpy'. proc runpy-deps { $PREPARE_DIR/python -S build/runpy_deps.py both @Argv } proc runpy-py-to-compile { $PREPARE_DIR/python -S build/runpy_deps.py py } # This version gets the paths out of the repo. But it requires that we # build all of Python! # # OK yeah so there are a few steps to building minimal app bundles. # 1. Build all of Python normally. Normal -D options. # ./run.sh build-clang-default # 2. Then run a special build that is based on that. # # Only need a debug build. # Run grep -F .so for the native dependencies. Have to add those # somewhere. proc app-deps { local app_name=$(1:-hello) local pythonpath=$(2:-build/testdata) local main_module=$(3:-hello) local prefix=_build/$app_name/app-deps # I need the right relative path for Oil ln -s -f $PWD/build/app_deps.py _tmp env PYTHONPATH=$pythonpath \ $PREPARE_DIR/python -S _tmp/app_deps.py both $main_module $prefix } # .py files to compile proc py-to-compile { local pythonpath=$(1:-build/testdata) local main_module=$(2:-hello) env PYTHONPATH=$pythonpath \ $PREPARE_DIR/python -S build/app_deps.py py $main_module } # For embedding in oil/bytecode.zip. proc quick-ref-manifest { local dir=$1 for path in [$dir/*] { echo "$path $path" # relative path is the same } } proc pyc-version-manifest { local manifest_path=$(1:-_build/oil/bytecode-opy-manifest.txt) # For example # Just show a string like "bytecode-opy.zip" for now. There is no OPy # version yet. local filename=$[basename $manifest_path] local user_str=$(filename%-manifest.txt).zip local dir=$[dirname $manifest_path] echo $user_str > $dir/pyc-version.txt # Put it at the root, like release-date and oil-version.txt. echo $dir/pyc-version.txt pyc-version.txt } # Make .d file proc make-dotd { local app_name=$(1:-hello) local app_deps_to_compile=$(2:-_tmp/hello/app-deps-to-compile.txt) # TODO: For each module, look it up in the manifest. # I guess make a Python file. echo "# TODO $app_deps_to_compile" # The dependencies we want. # X to prevent screwing things up. echo "X_build/$app_name/ovm:" echo "X_build/$app_name/ovm-dbg:" echo "X_build/$app_name/ovm-cov:" } # # C Code generation. The three functions below are adapted from # Modules/makesetup. # proc extdecls { for mod in [@Argv] { test $mod = readline && echo "#ifdef HAVE_READLINE" echo "extern void init$mod(void);" test $mod = readline && echo "#endif" } return 0 # because test can fail } proc initbits { for mod in [@Argv] { test $mod = readline && echo "#ifdef HAVE_READLINE" echo " {\"$mod\", init$mod}," test $mod = readline && echo "#endif" } return 0 # because test can fail } # Ported from sed to awk. Awk is MUCH nicer (no $NL ugliness, -v flag, etc.) proc gen-module-init { local extdecls setglobal extdecls = $[extdecls @Argv] local initbits setglobal initbits = $[initbits @Argv] local template=$PY27/Modules/config.c.in awk -v template=$template -v extdecls="$extdecls" -v initbits="$initbits" ' BEGIN { print "/* Generated automatically from " template " */" } /MARKER 1/ { print extdecls next } /MARKER 2/ { print initbits next } { print $0 } ' $template } # # C Modules # proc join-modules { local static=$(1:-static-c-modules.txt) local discovered=$(2:-_build/oil/all-deps-c.txt) # Filter out comments, print the first line. # # TODO: I don't want to depend on egrep and GNU flags on the target sytems? # Ship this file I guess. egrep --no-filename --only-matching '^[a-zA-Z0-9_\.]+' $static $discovered \ | sort | uniq } # # Misc # # To test building stdlib. proc clean-pyc { # skip _chroot, _tmp, etc. But delete __init__.pyc find . '(' -type d -a -name '_*' -a -prune ')' -o -name '*.pyc' -a -print | xargs --no-run-if-empty -- rm --verbose } # NOTE: Not deleting _devbuild, including cpython-full. Maybe we should, or # we should put it in a different directory? proc clean-repo { clean-source-tarball-build rm -r -f -v _build _release rm -f -v _bin/hello.* _bin/opy.* clean-pyc } # 'make clean'. # NOTE: # - There are no object files written now. # - We're not cleaning _build/detect-config.* ? proc clean-source-tarball-build { rm -f -v _bin/oil.* rm -f -v _build/oil/ovm _build/oil/ovm-dbg } @Argv