~andyc/oil

7cb34ab887e4b008733ee8f42c023109d248f294 — Andy Chu a month ago 0318c6b
[mycpp build] examples/modules now translates, compiles, and runs tests and benchmarks

- examples/strings builds and runs benchmarks.

Unrelated:

- release: Update release note template
4 files changed, 56 insertions(+), 35 deletions(-)

M devtools/release-note.sh
M mycpp/build-steps.sh
M mycpp/build_graph.py
M mycpp/examples/named_args.py
M devtools/release-note.sh => devtools/release-note.sh +7 -5
@@ 14,7 14,7 @@ set -o errexit
source devtools/release-version.sh  # for escape-segements

readonly OIL_VERSION=$(head -n 1 oil-version.txt)
readonly PREV_VERSION='0.8.3'
readonly PREV_VERSION='0.8.7'

# adapted from release-version.sh
_git-changelog-body() {


@@ 59,7 59,8 @@ issues-table() {
}

write-template() {
  local out=../oilshell.org/blog/2020/11/_release-$OIL_VERSION.md
  local date=$(date +%Y/%m)
  local out=../oilshell.org/blog/$date/_release-$OIL_VERSION.md
  print-template > $out
  echo "Wrote $out"
}


@@ 71,6 72,7 @@ print-template() {
---
title: Release of Oil $OIL_VERSION
date: $(date +%Y/%m/%d)
css_file: blog-bundle-v4.css
tags: oil-release
comments_url: TODO
published: no


@@ 107,12 109,12 @@ This is the latest version of Oil, a Unix shell that's our upgrade path from
To build and run it, follow the instructions in [INSTALL.txt][].  The wiki has
tips on [How To Test OSH](\$wiki).

If you're new to the project, see [Why Create a New Shell?][why-oil] and the
[2019 FAQ](../../2019/06/17.html).
If you're new to the project, see [Why Create a New Shell?][why-oil] and posts
tagged #[FAQ](\$blog-tag).

[INSTALL.txt]: /release/$OIL_VERSION/doc/INSTALL.html
[github-bugs]: https://github.com/oilshell/oil/issues
[why-oil]: ../../2018/01/28.html
[why-oil]: ../../2021/01/why-a-new-shell.html
[release-index]: /release/$OIL_VERSION/

[oilshell.zulipchat.com]: http://oilshell.zulipchat.com/

M mycpp/build-steps.sh => mycpp/build-steps.sh +3 -3
@@ 59,10 59,10 @@ EOF
translate() {
  ### Translate Python/MyPy to C++.

  local in=$1
  local name=$1
  local out=$2
  shift 2  # rest of artgs are inputs

  local name=$(basename $in .py)
  local raw=_ninja/gen/${name}_raw.cc

  export GC=1  # mycpp_main.py reads this


@@ 71,7 71,7 @@ translate() {
  # PYTHONPATH.
  ( source _tmp/mycpp-venv/bin/activate
    # flags may be empty
    time PYTHONPATH=$MYPY_REPO ./mycpp_main.py $in > $raw
    time PYTHONPATH=$MYPY_REPO ./mycpp_main.py "$@" > $raw
  )

  cpp-skeleton $name $raw > $out

M mycpp/build_graph.py => mycpp/build_graph.py +43 -24
@@ 72,13 72,16 @@ def log(msg, *args):
# - lexer_main, alloc_main -- these use Oil code
# - pgen2_demo -- uses pgen2

def ShouldSkip(name):
  if name in ['pgen2_demo', 'alloc_main', 'lexer_main', 'named_args',
      'varargs']:
    return True

  # '%5d' doesn't work yet.  TODO: fix this.
  if name == 'strings':
def ShouldSkipBuild(name):
  if name in [
      # these 3 use Oil code, and don't type check or compile
      'pgen2_demo',
      'alloc_main',  
      'lexer_main', 

      'named_args',  # I think this never worked
      'varargs',  # e_die() missing.  DID work with compile-with-asdl
      ]:
    return True

  # TODO. expr.asdl when GC=1


@@ 86,23 89,27 @@ def ShouldSkip(name):
  if name == 'parse':
    return True

  # TODO: Call custom function in examples.sh!
  if name == 'modules':
    return True

  return False


def ExamplesToTest():
def ExamplesToBuild():

  filenames = os.listdir('examples')
  py = [name[:-3] for name in filenames if name.endswith('.py')]

  to_test = [name for name in py if not ShouldSkip(name)]
  to_test = [name for name in py if not ShouldSkipBuild(name)]

  return to_test


def ShouldSkipTest(name):
  # '%5d' doesn't work yet.  TODO: fix this.
  if name == 'strings':
    return True

  return False


def ShouldSkipBenchmark(name):
  if name.startswith('test_'):
    return True


@@ 122,11 129,6 @@ def ShouldSkipBenchmark(name):
  return False


def ExamplesToBenchmark():
  to_test = ExamplesToTest()
  return [name for name in to_test if not ShouldSkipBenchmark(name)]


RUNTIME = ['my_runtime.cc', 'mylib2.cc', 'gc_heap.cc']

UNIT_TESTS = {


@@ 140,6 142,10 @@ UNIT_TESTS = {
    'target_lang': ['../cpp/dumb_alloc.cc', 'gc_heap.cc'],
}

MORE_FILES = {
    'modules': ['testpkg/module1.py', 'testpkg/module2.py'],
}

def main(argv):
  n = ninja_syntax.Writer(open('build.ninja', 'w'))



@@ 148,8 154,8 @@ def main(argv):
  n.newline()

  n.rule('translate',
         command='./build-steps.sh translate $in $out',
         description='translate $in $out')
         command='./build-steps.sh translate $name $out $in',
         description='translate $name $out $in')
  n.newline()
  n.rule('compile',
         # note: $in can be MULTIPLE files, shell-quoted


@@ 184,9 190,7 @@ def main(argv):
         description='benchmark-table $out $in')
  n.newline()

  to_benchmark = ExamplesToBenchmark()

  examples = ExamplesToTest()
  examples = ExamplesToBuild()
  #examples = ['cgi', 'containers', 'fib_iter']
  #examples = ['cgi']



@@ 268,13 272,23 @@ def main(argv):
          continue
        benchmark_tasks.append(task_out)

      elif mode == 'test':
        if ShouldSkipTest(ex):
          log('Skipping test of %s', ex)
          continue

      log_out = '%s.log.txt' % prefix
      n.build([task_out, log_out], 'example-task', 'examples/%s.py' % ex,
              variables=[('name', ex), ('impl', 'Python')])
      n.newline()

    # Translate to C++
    n.build('_ninja/gen/%s.cc' % ex, 'translate', 'examples/%s.py' % ex)
    n.build(
        '_ninja/gen/%s.cc' % ex, 'translate',
        MORE_FILES.get(ex, []) + ['examples/%s.py' % ex] ,
        variables=[('name', ex)],
    )

    n.newline()

    # Compile C++. TODO: Can also parameterize by CXX: Clang or GCC.


@@ 307,6 321,11 @@ def main(argv):
          continue
        benchmark_tasks.append(task_out)

      elif mode == 'test':
        if ShouldSkipTest(ex):
          log('Skipping test of %s', ex)
          continue

      log_out = '_ninja/tasks/%s/%s.%s.log.txt' % (mode, ex, variant)
      py_log_out = '_ninja/tasks/%s/%s.py.log.txt' % (mode, ex)


M mycpp/examples/named_args.py => mycpp/examples/named_args.py +3 -3
@@ 21,9 21,9 @@ def run_tests():

  # 6 7 8

  log("%s", add(1))
  log("%s", add(1, y=3))
  log("%s", add(1, z=5))
  log("%d", add(1))
  log("%d", add(1, y=3))
  log("%d", add(1, z=5))

  # Hm the CallableType doesn't have default args, because two functions could
  # have the same type siganature, but different args, and you don't know which