Page MenuHomePhabricator

Add a facility to extract libsecp256k1 from the repository
ClosedPublic

Authored by deadalnix on Jan 3 2020, 13:30.

Details

Summary

There is a need to have libsecp256k1 on its own for 3rd parties to use. This script can extract libsecp256k1 from a clone of the Bitcoin ABC repository.

Test Plan

Run the script and ensure the generated repository looks good.

Running the script takes a long time, so plan accordingly.

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Fix shebang and set locale

jasonbcox requested changes to this revision.Jan 3 2020, 17:30
jasonbcox added a subscriber: jasonbcox.
jasonbcox added inline comments.
contrib/extract-secp256k1.sh
4 ↗(On Diff #15133)

Rather than follow the linter's advice regarding pushd ... || exit, use something like set -euo pipefail instead. The set -eu is also good practice either way.

9 ↗(On Diff #15133)

use mktemp -d rather than a hardcoded workdir.

26 ↗(On Diff #15133)

Call this in an exit trap that is set right after the creation of the directory so that it cleans up if the script fails at any point.

This revision now requires changes to proceed.Jan 3 2020, 17:30

Use a trap and a temp folder.

Remove one more ref to workdir

Mengerian added inline comments.
contrib/extract-secp256k1.sh
8 ↗(On Diff #15150)

wokdir -> workdir

jasonbcox requested changes to this revision.Jan 6 2020, 17:19
jasonbcox added inline comments.
contrib/extract-secp256k1.sh
36 ↗(On Diff #15168)

This will fail if secp256k1 already exists. Since the script takes a long time to run, the beginning of the script should bail early if this output dir already exists.

This revision now requires changes to proceed.Jan 6 2020, 17:19

Add a check for the presence of secp256k1

Note that some cmake modules (from cmake/modules) are required to build secp256k1 with cmake.
This can be easily solved by copying the necessary files to new repo and setting the module path accordingly.
I can do it in a follow-up if desired.

Ok, I'll update the thing to keep the cmake folder around as well.

preserve cmake modules when extracting

Nit: I would prefer quoted echo statements, but this is probably best left to a linter.

This revision is now accepted and ready to land.Jan 8 2020, 03:56

This produces some lint advice (the only output right now if you run arc lint --everything)

>>> Lint for contrib/extract-secp256k1.sh:


   Advice  (SC1004) ShellCheck found an issue:
    This backslash+linefeed is literal. Break outside single quotes if you
    just want to break the line.

              26 
              27 pushd "${WORKDIR}"
              28 FILTER_BRANCH_SQUELCH_WARNING=1 git filter-branch \
    >>>       29     --index-filter 'git ls-files \
                                                  ^
              30                         | grep -v "^cmake\|^src/secp256k1" \
              31                         | xargs git rm -q --cached;
              32                     git ls-files -s \

   Advice  (SC1004) ShellCheck found an issue:
    This backslash+linefeed is literal. Break outside single quotes if you
    just want to break the line.

              27 pushd "${WORKDIR}"
              28 FILTER_BRANCH_SQUELCH_WARNING=1 git filter-branch \
              29     --index-filter 'git ls-files \
    >>>       30                         | grep -v "^cmake\|^src/secp256k1" \
                                                                            ^
              31                         | xargs git rm -q --cached;
              32                     git ls-files -s \
              33                         | sed "s%src/secp256k1/%%" \

   Advice  (SC1004) ShellCheck found an issue:
    This backslash+linefeed is literal. Break outside single quotes if you
    just want to break the line.

              29     --index-filter 'git ls-files \
              30                         | grep -v "^cmake\|^src/secp256k1" \
              31                         | xargs git rm -q --cached;
    >>>       32                     git ls-files -s \
                                                     ^
              33                         | sed "s%src/secp256k1/%%" \
              34                         | git update-index --index-info;
              35                     git rm -rq --cached --ignore-unmatch src/secp256k1' \

   Advice  (SC1004) ShellCheck found an issue:
    This backslash+linefeed is literal. Break outside single quotes if you
    just want to break the line.

              30                         | grep -v "^cmake\|^src/secp256k1" \
              31                         | xargs git rm -q --cached;
              32                     git ls-files -s \
    >>>       33                         | sed "s%src/secp256k1/%%" \
                                                                    ^
              34                         | git update-index --index-info;
              35                     git rm -rq --cached --ignore-unmatch src/secp256k1' \
              36     --prune-empty -- --all