mmcloughlin / ec3

Elliptic Curve Cryptography Compiler: an incomplete experiment in code-generation for elliptic curves in Go
BSD 3-Clause "New" or "Revised" License
54 stars 6 forks source link

addchain: consider breaking out as separate package #111

Closed mmcloughlin closed 4 years ago

mmcloughlin commented 4 years ago

Some people have expressed interest in the addition chains results, so it may be worth breaking this out as a separate project.

mmcloughlin commented 4 years ago
$ go list -f '{{range .Deps}}{{printf "%s\n" .}}{{end}}' ./cmd/addchain/
bytes
container/heap
context
encoding/binary
errors
flag
fmt
github.com/google/subcommands
github.com/mmcloughlin/ec3/addchain
github.com/mmcloughlin/ec3/addchain/acc
github.com/mmcloughlin/ec3/addchain/acc/ast
github.com/mmcloughlin/ec3/addchain/acc/ir
github.com/mmcloughlin/ec3/addchain/acc/parse
github.com/mmcloughlin/ec3/addchain/acc/parse/internal/parser
github.com/mmcloughlin/ec3/addchain/acc/pass
github.com/mmcloughlin/ec3/addchain/acc/printer
github.com/mmcloughlin/ec3/internal/bigint
github.com/mmcloughlin/ec3/internal/bigints
github.com/mmcloughlin/ec3/internal/bigvector
github.com/mmcloughlin/ec3/internal/calc
github.com/mmcloughlin/ec3/internal/cli
github.com/mmcloughlin/ec3/internal/container/heap
github.com/mmcloughlin/ec3/internal/errutil
github.com/mmcloughlin/ec3/internal/ints
github.com/mmcloughlin/ec3/internal/print
golang.org/x/xerrors
golang.org/x/xerrors/internal
internal/bytealg
internal/cpu
internal/fmtsort
internal/oserror
internal/poll
internal/race
internal/reflectlite
internal/syscall/unix
internal/testlog
io
io/ioutil
log
math
math/big
math/bits
math/rand
os
path
path/filepath
reflect
runtime
runtime/internal/atomic
runtime/internal/math
runtime/internal/sys
sort
strconv
strings
sync
sync/atomic
syscall
text/tabwriter
time
unicode
unicode/utf8
unsafe
mmcloughlin commented 4 years ago

This monstrosity will do it:

#!/bin/bash -ex

workdir=$(mktemp -d)
cd ${workdir}

#-----------------------------------------------------------------------------

git clone git@github.com:mmcloughlin/ec3.git
cd ec3
repodir=${workdir}/ec3

#-----------------------------------------------------------------------------

git remote remove origin
git filter-branch \
    --tree-filter '
#-----------------------------------------------------------------------------

# todo:
# include the LICENSE
# - commit filter

# clean up dot files
find . -type f -name ".*" -delete
rm -rf .circleci .github

# move everything to a temp dir
tmp=$(mktemp -d)
mv * ${tmp}

# copy back in the ones we want
for dir in prime cmd/addchain polynomial internal/{assert,bigint,bigints,bigvector,calc,cli,container/heap,errutil,ints,print,test}; do
    src="${tmp}/${dir}"
    mkdir -p ${dir}
    if [ -d ${src} ]; then
        mv $src/* ${dir};
    fi
done

# move addchain to top level
if [ -d ${tmp}/addchain ]; then
    mv ${tmp}/addchain/* .
fi

# replace import paths
find . -name "*.go" | xargs sed -i.bak "s|github.com/mmcloughlin/ec3/addchain|github.com/mmcloughlin/addchain|g"
find . -name "*.go" | xargs sed -i.bak "s|github.com/mmcloughlin/ec3|github.com/mmcloughlin/addchain|g"
find . -name "*.bak" -delete

# include LICENSE
mv ${tmp}/LICENSE .

# clean up
rm -rf ${tmp}

#-----------------------------------------------------------------------------
' \
    --msg-filter '
        sed -E "s|#([0-9]+)|mmcloughlin/ec3#\1|g" &&
            echo &&
            echo "Extracted-from: mmcloughlin/ec3@${GIT_COMMIT}"
    ' \
    --prune-empty \
    -- \
    master

#-----------------------------------------------------------------------------

# init module
go mod init github.com/mmcloughlin/addchain

go build ./...
go test -short ./...

git add go.mod go.sum

git commit -m 'init go module'

#-----------------------------------------------------------------------------

tree ${repodir}

echo "workdir: ${workdir}"
echo "repo: ${repodir}"
mmcloughlin commented 4 years ago

Extracted as https://github.com/mmcloughlin/addchain