From 70d51bcf2da336786ecaab52160dca5a0b19006a Mon Sep 17 00:00:00 2001 From: manta1130 Date: Mon, 14 Sep 2020 15:30:55 +0900 Subject: [PATCH 01/25] Implemented expand.py --- expand.py | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100755 expand.py diff --git a/expand.py b/expand.py new file mode 100755 index 0000000..8bb8477 --- /dev/null +++ b/expand.py @@ -0,0 +1,69 @@ +#!/usr/bin/python3 + +import sys +import getopt + + +def output_file(filename, output_comment, output_test): + global src_path + + res = [] + with open(src_path+filename+'.rs', 'r') as f: + res.append('mod {}{{'.format(filename)) + + for line in f: + res.append(line.rstrip()) + + res.append('}') + return res + + +opt_list = ['output-comment', 'output-test', ] +output_list_all = ('lazysegtree', 'segtree', 'convolution', 'twosat', 'scc', + 'fenwicktree', 'math', 'modint', 'maxflow', 'dsu', 'mincostflow', 'string', 'internal_bit', 'internal_math', 'internal_type_traits', 'internal_scc', 'internal_queue') +dependency_list = {'lazysegtree': ('internal_bit',), 'segtree': ('internal_bit',), 'convolution': ('internal_bit,modint',), 'math': ('internal_math',), 'modint': ( + 'internal_math', 'internal_type_traits'), 'fenwicktree': ('internal_type_traits',), 'twosat': ('internal_scc',), 'scc': ('internal_scc',), 'maxflow': ('internal_queue',)} +src_path = 'src/' + +try: + opts, args = getopt.getopt(sys.argv[1:], 'tc', opt_list) +except getopt.GetoptError as e: + print(e) + sys.exit(2) + +# unimplemented +output_comment = False +output_test = False + +for o, v in opts: + if o == '--output-comment' or o == '-c': + output_comment = True + if o == '--output-test' or o == '-t': + output_test = True + +output_list = set() + +while len(args) != 0: + pop = args.pop() + if not pop in output_list_all: + print('invalid args:{}'.format(pop)) + sys.exit(2) + output_list.add(pop) + if pop in dependency_list: + for d in dependency_list[pop]: + args.append(d) + +output_list = list(output_list) +output_list.sort() + +output_data = [] +for i in output_list: + buf = output_file(i, output_comment, output_test) + output_data.extend(buf) + +for i in output_list: + if not i.startswith('internal'): + output_data.append('use {}::*;'.format(i)) + +for i in output_data: + print(i) From c1ce0903343f1cf470fa40fad2c5534bf7f16697 Mon Sep 17 00:00:00 2001 From: manta1130 Date: Mon, 14 Sep 2020 15:34:08 +0900 Subject: [PATCH 02/25] Changed the order of codes. --- expand.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/expand.py b/expand.py index 8bb8477..54b37cb 100755 --- a/expand.py +++ b/expand.py @@ -3,6 +3,13 @@ import sys import getopt +opt_list = ['output-comment', 'output-test', ] +output_list_all = ('lazysegtree', 'segtree', 'convolution', 'twosat', 'scc', + 'fenwicktree', 'math', 'modint', 'maxflow', 'dsu', 'mincostflow', 'string', 'internal_bit', 'internal_math', 'internal_type_traits', 'internal_scc', 'internal_queue') +dependency_list = {'lazysegtree': ('internal_bit',), 'segtree': ('internal_bit',), 'convolution': ('internal_bit,modint',), 'math': ('internal_math',), 'modint': ( + 'internal_math', 'internal_type_traits'), 'fenwicktree': ('internal_type_traits',), 'twosat': ('internal_scc',), 'scc': ('internal_scc',), 'maxflow': ('internal_queue',)} +src_path = 'src/' + def output_file(filename, output_comment, output_test): global src_path @@ -18,13 +25,6 @@ def output_file(filename, output_comment, output_test): return res -opt_list = ['output-comment', 'output-test', ] -output_list_all = ('lazysegtree', 'segtree', 'convolution', 'twosat', 'scc', - 'fenwicktree', 'math', 'modint', 'maxflow', 'dsu', 'mincostflow', 'string', 'internal_bit', 'internal_math', 'internal_type_traits', 'internal_scc', 'internal_queue') -dependency_list = {'lazysegtree': ('internal_bit',), 'segtree': ('internal_bit',), 'convolution': ('internal_bit,modint',), 'math': ('internal_math',), 'modint': ( - 'internal_math', 'internal_type_traits'), 'fenwicktree': ('internal_type_traits',), 'twosat': ('internal_scc',), 'scc': ('internal_scc',), 'maxflow': ('internal_queue',)} -src_path = 'src/' - try: opts, args = getopt.getopt(sys.argv[1:], 'tc', opt_list) except getopt.GetoptError as e: From 2f36d26f8164c222ec8a179f14129b22bf271954 Mon Sep 17 00:00:00 2001 From: manta1130 Date: Mon, 14 Sep 2020 18:32:39 +0900 Subject: [PATCH 03/25] Implemented option(output_comment,output_test) --- expand.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/expand.py b/expand.py index 54b37cb..ba9d242 100755 --- a/expand.py +++ b/expand.py @@ -19,6 +19,10 @@ def output_file(filename, output_comment, output_test): res.append('mod {}{{'.format(filename)) for line in f: + if not output_test and line.strip()=='#[cfg(test)]': + break + if not output_comment and line.strip().startswith("//"): + continue res.append(line.rstrip()) res.append('}') @@ -31,7 +35,6 @@ def output_file(filename, output_comment, output_test): print(e) sys.exit(2) -# unimplemented output_comment = False output_test = False From c1ca28ee45c0288598344d7ab56fb6a208e6076a Mon Sep 17 00:00:00 2001 From: manta1130 Date: Mon, 14 Sep 2020 18:43:05 +0900 Subject: [PATCH 04/25] Added comments --- expand.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/expand.py b/expand.py index ba9d242..3cfebe7 100755 --- a/expand.py +++ b/expand.py @@ -19,9 +19,13 @@ def output_file(filename, output_comment, output_test): res.append('mod {}{{'.format(filename)) for line in f: - if not output_test and line.strip()=='#[cfg(test)]': + if not output_test and line.strip() == '#[cfg(test)]': + # TODO + # Find more better way. break if not output_comment and line.strip().startswith("//"): + # TODO + # Find more better way. continue res.append(line.rstrip()) @@ -65,6 +69,7 @@ def output_file(filename, output_comment, output_test): output_data.extend(buf) for i in output_list: + # Modules that begin with 'internal' are for internal use, so they are not declared. if not i.startswith('internal'): output_data.append('use {}::*;'.format(i)) From 21d6f5dc812c2f059e6d968c1e06b4967bcfe767 Mon Sep 17 00:00:00 2001 From: manta1130 Date: Mon, 14 Sep 2020 19:01:33 +0900 Subject: [PATCH 05/25] Added usage --- expand.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/expand.py b/expand.py index 3cfebe7..05549c3 100755 --- a/expand.py +++ b/expand.py @@ -3,7 +3,30 @@ import sys import getopt -opt_list = ['output-comment', 'output-test', ] +usage = '''Usage:expand.py [options] +Output Modules: + convolution + dsu + fenwicktree + lazysegtree + math + maxflow + mincostflow + modint + scc + segtree + string + twosat + +You can select multiple modules for + e.g.)expand.py math segtree + +Options: + -c --output_comment output comment + -t --output_test output test code + -h --help print help +''' +opt_list = ['output-comment', 'output-test', 'help'] output_list_all = ('lazysegtree', 'segtree', 'convolution', 'twosat', 'scc', 'fenwicktree', 'math', 'modint', 'maxflow', 'dsu', 'mincostflow', 'string', 'internal_bit', 'internal_math', 'internal_type_traits', 'internal_scc', 'internal_queue') dependency_list = {'lazysegtree': ('internal_bit',), 'segtree': ('internal_bit',), 'convolution': ('internal_bit,modint',), 'math': ('internal_math',), 'modint': ( @@ -34,9 +57,10 @@ def output_file(filename, output_comment, output_test): try: - opts, args = getopt.getopt(sys.argv[1:], 'tc', opt_list) + opts, args = getopt.getopt(sys.argv[1:], 'tch', opt_list) except getopt.GetoptError as e: print(e) + print(usage) sys.exit(2) output_comment = False @@ -47,6 +71,9 @@ def output_file(filename, output_comment, output_test): output_comment = True if o == '--output-test' or o == '-t': output_test = True + if o == '--help' or o == '-h': + print(usage) + sys.exit(0) output_list = set() @@ -54,6 +81,7 @@ def output_file(filename, output_comment, output_test): pop = args.pop() if not pop in output_list_all: print('invalid args:{}'.format(pop)) + print(usage) sys.exit(2) output_list.add(pop) if pop in dependency_list: From ddc4dfbb3d903146c6cef6c66ce40efba6cb5358 Mon Sep 17 00:00:00 2001 From: manta1130 Date: Mon, 14 Sep 2020 19:08:20 +0900 Subject: [PATCH 06/25] Added output header --- expand.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/expand.py b/expand.py index 05549c3..e3568d4 100755 --- a/expand.py +++ b/expand.py @@ -26,6 +26,7 @@ -t --output_test output test code -h --help print help ''' +output_header = '//https://github.com/rust-lang-ja/ac-library-rs\n' opt_list = ['output-comment', 'output-test', 'help'] output_list_all = ('lazysegtree', 'segtree', 'convolution', 'twosat', 'scc', 'fenwicktree', 'math', 'modint', 'maxflow', 'dsu', 'mincostflow', 'string', 'internal_bit', 'internal_math', 'internal_type_traits', 'internal_scc', 'internal_queue') @@ -101,5 +102,6 @@ def output_file(filename, output_comment, output_test): if not i.startswith('internal'): output_data.append('use {}::*;'.format(i)) +print(output_header) for i in output_data: print(i) From 839e3d7f35f2e66cefeb88d388b65035c8038634 Mon Sep 17 00:00:00 2001 From: manta1130 Date: Mon, 14 Sep 2020 22:55:12 +0900 Subject: [PATCH 07/25] Fixed dependency list --- expand.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/expand.py b/expand.py index e3568d4..8f7ddf7 100755 --- a/expand.py +++ b/expand.py @@ -30,8 +30,8 @@ opt_list = ['output-comment', 'output-test', 'help'] output_list_all = ('lazysegtree', 'segtree', 'convolution', 'twosat', 'scc', 'fenwicktree', 'math', 'modint', 'maxflow', 'dsu', 'mincostflow', 'string', 'internal_bit', 'internal_math', 'internal_type_traits', 'internal_scc', 'internal_queue') -dependency_list = {'lazysegtree': ('internal_bit',), 'segtree': ('internal_bit',), 'convolution': ('internal_bit,modint',), 'math': ('internal_math',), 'modint': ( - 'internal_math', 'internal_type_traits'), 'fenwicktree': ('internal_type_traits',), 'twosat': ('internal_scc',), 'scc': ('internal_scc',), 'maxflow': ('internal_queue',)} +dependency_list = {'lazysegtree': ('internal_bit',), 'segtree': ('internal_bit',), 'convolution': ('internal_bit', 'modint',), 'math': ('internal_math',), 'modint': ( + 'internal_math', 'internal_type_traits'), 'fenwicktree': ('internal_type_traits',), 'twosat': ('internal_scc',), 'scc': ('internal_scc',), 'maxflow': ('internal_queue', 'internal_type_traits',), 'mincostflow': ('internal_type_traits',)} src_path = 'src/' From deda790a51a09015889cd76b82113475cce80a14 Mon Sep 17 00:00:00 2001 From: manta1130 Date: Mon, 14 Sep 2020 23:37:48 +0900 Subject: [PATCH 08/25] Add tests for expand.py --- .github/workflows/ci.yml | 18 ++++++++++++++++++ .github/workflows/test-expand.sh | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100755 .github/workflows/test-expand.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c5a67e5..e693cfe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -95,3 +95,21 @@ jobs: args: --workspace --no-fail-fast env: RUST_BACKTRACE: full + + expander_test: + strategy: + fail-fast: false + matrix: + toolchain: + - 1.42.0-x86_64-unknown-linux-gnu + - stable-x86_64-unknown-linux-gnu + + name: Expand_test (${{ matrix.toolchain }}) + runs-on: ubuntu-18.04 + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: expand.py tests + run: bash ./.github/workflows/test-expand.sh diff --git a/.github/workflows/test-expand.sh b/.github/workflows/test-expand.sh new file mode 100755 index 0000000..0fc5fdc --- /dev/null +++ b/.github/workflows/test-expand.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +TEST_MODULES=(convolution dsu fenwicktree lazysegtree math maxflow mincostflow modint scc segtree string twosat) +TMP_PATH=$(mktemp -d) +SCRIPT_DIR=$(cd $(dirname $0); pwd) +TEST_FILE="test.rs" +FILE_HEAD="fn main() {}" + +for MODULE in ${TEST_MODULES[@]};do + python3 $SCRIPT_DIR/../../expand.py $MODULE > $TMP_PATH/$TEST_FILE + echo $FILE_HEAD >> $TMP_PATH/$TEST_FILE + rustc $TMP_PATH/$TEST_FILE 2>/dev/null + if [ $? -ne 0 ];then + echo "Error compiling for $MODULE" + exit 1 + else + echo "Test passed($MODULE)" + fi +done \ No newline at end of file From ac05f13c422815c23548c9cb8ac950d7d2ef0b4e Mon Sep 17 00:00:00 2001 From: manta1130 Date: Tue, 15 Sep 2020 00:08:51 +0900 Subject: [PATCH 09/25] Fixed help --- expand.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/expand.py b/expand.py index 8f7ddf7..24942af 100755 --- a/expand.py +++ b/expand.py @@ -22,8 +22,8 @@ e.g.)expand.py math segtree Options: - -c --output_comment output comment - -t --output_test output test code + -c --output-comment output comment + -t --output-test output test code -h --help print help ''' output_header = '//https://github.com/rust-lang-ja/ac-library-rs\n' From e9e290bc8495e35a1b7a41b33d5c7311b9669c04 Mon Sep 17 00:00:00 2001 From: manta1130 Date: Tue, 15 Sep 2020 20:32:52 +0900 Subject: [PATCH 10/25] Removed some options. --- expand.py | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/expand.py b/expand.py index 24942af..d7c017d 100755 --- a/expand.py +++ b/expand.py @@ -22,12 +22,10 @@ e.g.)expand.py math segtree Options: - -c --output-comment output comment - -t --output-test output test code -h --help print help ''' output_header = '//https://github.com/rust-lang-ja/ac-library-rs\n' -opt_list = ['output-comment', 'output-test', 'help'] +opt_list = ['help'] output_list_all = ('lazysegtree', 'segtree', 'convolution', 'twosat', 'scc', 'fenwicktree', 'math', 'modint', 'maxflow', 'dsu', 'mincostflow', 'string', 'internal_bit', 'internal_math', 'internal_type_traits', 'internal_scc', 'internal_queue') dependency_list = {'lazysegtree': ('internal_bit',), 'segtree': ('internal_bit',), 'convolution': ('internal_bit', 'modint',), 'math': ('internal_math',), 'modint': ( @@ -35,7 +33,7 @@ src_path = 'src/' -def output_file(filename, output_comment, output_test): +def output_file(filename): global src_path res = [] @@ -43,14 +41,6 @@ def output_file(filename, output_comment, output_test): res.append('mod {}{{'.format(filename)) for line in f: - if not output_test and line.strip() == '#[cfg(test)]': - # TODO - # Find more better way. - break - if not output_comment and line.strip().startswith("//"): - # TODO - # Find more better way. - continue res.append(line.rstrip()) res.append('}') @@ -58,20 +48,13 @@ def output_file(filename, output_comment, output_test): try: - opts, args = getopt.getopt(sys.argv[1:], 'tch', opt_list) + opts, args = getopt.getopt(sys.argv[1:], 'h', opt_list) except getopt.GetoptError as e: print(e) print(usage) sys.exit(2) -output_comment = False -output_test = False - for o, v in opts: - if o == '--output-comment' or o == '-c': - output_comment = True - if o == '--output-test' or o == '-t': - output_test = True if o == '--help' or o == '-h': print(usage) sys.exit(0) @@ -94,7 +77,7 @@ def output_file(filename, output_comment, output_test): output_data = [] for i in output_list: - buf = output_file(i, output_comment, output_test) + buf = output_file(i) output_data.extend(buf) for i in output_list: From 2e036cabf34f4f68f46a74e8a0f459ac2796db3e Mon Sep 17 00:00:00 2001 From: manta1130 Date: Tue, 15 Sep 2020 20:43:08 +0900 Subject: [PATCH 11/25] Added -a --all options --- .github/workflows/test-expand.sh | 2 +- expand.py | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-expand.sh b/.github/workflows/test-expand.sh index 0fc5fdc..3e8a1c3 100755 --- a/.github/workflows/test-expand.sh +++ b/.github/workflows/test-expand.sh @@ -1,6 +1,6 @@ #!/bin/bash -TEST_MODULES=(convolution dsu fenwicktree lazysegtree math maxflow mincostflow modint scc segtree string twosat) +TEST_MODULES=(convolution dsu fenwicktree lazysegtree math maxflow mincostflow modint scc segtree string twosat --all) TMP_PATH=$(mktemp -d) SCRIPT_DIR=$(cd $(dirname $0); pwd) TEST_FILE="test.rs" diff --git a/expand.py b/expand.py index d7c017d..c3f2b3e 100755 --- a/expand.py +++ b/expand.py @@ -22,10 +22,11 @@ e.g.)expand.py math segtree Options: - -h --help print help + -a --all import all modules + -h --help print help ''' output_header = '//https://github.com/rust-lang-ja/ac-library-rs\n' -opt_list = ['help'] +opt_list = ['help', 'all'] output_list_all = ('lazysegtree', 'segtree', 'convolution', 'twosat', 'scc', 'fenwicktree', 'math', 'modint', 'maxflow', 'dsu', 'mincostflow', 'string', 'internal_bit', 'internal_math', 'internal_type_traits', 'internal_scc', 'internal_queue') dependency_list = {'lazysegtree': ('internal_bit',), 'segtree': ('internal_bit',), 'convolution': ('internal_bit', 'modint',), 'math': ('internal_math',), 'modint': ( @@ -48,7 +49,7 @@ def output_file(filename): try: - opts, args = getopt.getopt(sys.argv[1:], 'h', opt_list) + opts, args = getopt.getopt(sys.argv[1:], 'ah', opt_list) except getopt.GetoptError as e: print(e) print(usage) @@ -58,6 +59,8 @@ def output_file(filename): if o == '--help' or o == '-h': print(usage) sys.exit(0) + elif o == '--all' or o == '-a': + args = list(output_list_all) output_list = set() From 83783b33bc663570f548bab2e1a5b68f60003bfa Mon Sep 17 00:00:00 2001 From: manta1130 Date: Tue, 15 Sep 2020 20:45:47 +0900 Subject: [PATCH 12/25] Changed if start with no args,it shows usage. --- expand.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/expand.py b/expand.py index c3f2b3e..ba02fdc 100755 --- a/expand.py +++ b/expand.py @@ -55,6 +55,10 @@ def output_file(filename): print(usage) sys.exit(2) +if len(opts) == 0 and len(args) == 0: + print(usage) + sys.exit(0) + for o, v in opts: if o == '--help' or o == '-h': print(usage) From d8a81476ea5c77169ec6a6863fecd076ee6d401f Mon Sep 17 00:00:00 2001 From: manta1130 Date: Tue, 15 Sep 2020 22:03:01 +0900 Subject: [PATCH 13/25] Changed the test code --- .github/workflows/test-expand.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-expand.sh b/.github/workflows/test-expand.sh index 3e8a1c3..e1d65b1 100755 --- a/.github/workflows/test-expand.sh +++ b/.github/workflows/test-expand.sh @@ -7,13 +7,15 @@ TEST_FILE="test.rs" FILE_HEAD="fn main() {}" for MODULE in ${TEST_MODULES[@]};do + echo Test module $MODULE python3 $SCRIPT_DIR/../../expand.py $MODULE > $TMP_PATH/$TEST_FILE + echo "Output" $(wc -c < $TMP_PATH/$TEST_FILE) "Bytes" echo $FILE_HEAD >> $TMP_PATH/$TEST_FILE rustc $TMP_PATH/$TEST_FILE 2>/dev/null if [ $? -ne 0 ];then echo "Error compiling for $MODULE" exit 1 else - echo "Test passed($MODULE)" + echo "Test passed" fi done \ No newline at end of file From eee7f857d82f4673362a5882ab62abab4b71f4d5 Mon Sep 17 00:00:00 2001 From: manta1130 Date: Tue, 15 Sep 2020 22:29:11 +0900 Subject: [PATCH 14/25] Added the process of rustfmt --- expand.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/expand.py b/expand.py index ba02fdc..ffdf2d1 100755 --- a/expand.py +++ b/expand.py @@ -2,6 +2,8 @@ import sys import getopt +import tempfile +import subprocess usage = '''Usage:expand.py [options] Output Modules: @@ -92,6 +94,14 @@ def output_file(filename): if not i.startswith('internal'): output_data.append('use {}::*;'.format(i)) -print(output_header) -for i in output_data: - print(i) +# rustfmt +with tempfile.TemporaryDirectory() as temp_dir: + temp_file = temp_dir + '/output.rs' + with open(temp_file, 'w') as f: + print(output_header, file=f) + for i in output_data: + print(i, file=f) + output_data = subprocess.run(["rustfmt", temp_file]) + with open(temp_file, 'r') as f: + for line in f: + print(line, end="") From ee9defa7f1bdefaa142af210ffbfa50748440015 Mon Sep 17 00:00:00 2001 From: manta1130 Date: Tue, 15 Sep 2020 22:35:48 +0900 Subject: [PATCH 15/25] Added rustfmt install command --- .github/workflows/test-expand.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/test-expand.sh b/.github/workflows/test-expand.sh index e1d65b1..01e02af 100755 --- a/.github/workflows/test-expand.sh +++ b/.github/workflows/test-expand.sh @@ -6,6 +6,10 @@ SCRIPT_DIR=$(cd $(dirname $0); pwd) TEST_FILE="test.rs" FILE_HEAD="fn main() {}" +if [ -v CI ];then + rustup component add rustfmt +fi + for MODULE in ${TEST_MODULES[@]};do echo Test module $MODULE python3 $SCRIPT_DIR/../../expand.py $MODULE > $TMP_PATH/$TEST_FILE From 47bd974b27ded209e999d06b776f83cf791ec3cd Mon Sep 17 00:00:00 2001 From: manta1130 Date: Tue, 15 Sep 2020 23:04:19 +0900 Subject: [PATCH 16/25] show error message --- .github/workflows/test-expand.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-expand.sh b/.github/workflows/test-expand.sh index 01e02af..f2be6b4 100755 --- a/.github/workflows/test-expand.sh +++ b/.github/workflows/test-expand.sh @@ -15,7 +15,7 @@ for MODULE in ${TEST_MODULES[@]};do python3 $SCRIPT_DIR/../../expand.py $MODULE > $TMP_PATH/$TEST_FILE echo "Output" $(wc -c < $TMP_PATH/$TEST_FILE) "Bytes" echo $FILE_HEAD >> $TMP_PATH/$TEST_FILE - rustc $TMP_PATH/$TEST_FILE 2>/dev/null + rustc -A warnings $TMP_PATH/$TEST_FILE if [ $? -ne 0 ];then echo "Error compiling for $MODULE" exit 1 From 9760ead7edceb01b159034268a0d5ba618e40c84 Mon Sep 17 00:00:00 2001 From: manta1130 Date: Wed, 16 Sep 2020 19:15:48 +0900 Subject: [PATCH 17/25] Formatted codes --- expand.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/expand.py b/expand.py index ffdf2d1..7c8881a 100755 --- a/expand.py +++ b/expand.py @@ -24,15 +24,24 @@ e.g.)expand.py math segtree Options: - -a --all import all modules + -a --all import all modules -h --help print help ''' output_header = '//https://github.com/rust-lang-ja/ac-library-rs\n' opt_list = ['help', 'all'] output_list_all = ('lazysegtree', 'segtree', 'convolution', 'twosat', 'scc', - 'fenwicktree', 'math', 'modint', 'maxflow', 'dsu', 'mincostflow', 'string', 'internal_bit', 'internal_math', 'internal_type_traits', 'internal_scc', 'internal_queue') -dependency_list = {'lazysegtree': ('internal_bit',), 'segtree': ('internal_bit',), 'convolution': ('internal_bit', 'modint',), 'math': ('internal_math',), 'modint': ( - 'internal_math', 'internal_type_traits'), 'fenwicktree': ('internal_type_traits',), 'twosat': ('internal_scc',), 'scc': ('internal_scc',), 'maxflow': ('internal_queue', 'internal_type_traits',), 'mincostflow': ('internal_type_traits',)} + 'fenwicktree', 'math', 'modint', 'maxflow', 'dsu', + 'mincostflow', 'string', 'internal_bit', 'internal_math', + 'internal_type_traits', 'internal_scc', 'internal_queue') +dependency_list = {'lazysegtree': ('internal_bit',), + 'segtree': ('internal_bit',), + 'convolution': ('internal_bit', 'modint',), + 'math': ('internal_math',), + 'modint': ('internal_math', 'internal_type_traits'), + 'fenwicktree': ('internal_type_traits',), + 'twosat': ('internal_scc',), 'scc': ('internal_scc',), + 'maxflow': ('internal_queue', 'internal_type_traits',), + 'mincostflow': ('internal_type_traits',)} src_path = 'src/' @@ -72,7 +81,7 @@ def output_file(filename): while len(args) != 0: pop = args.pop() - if not pop in output_list_all: + if pop not in output_list_all: print('invalid args:{}'.format(pop)) print(usage) sys.exit(2) @@ -90,7 +99,8 @@ def output_file(filename): output_data.extend(buf) for i in output_list: - # Modules that begin with 'internal' are for internal use, so they are not declared. + # Modules that begin with 'internal' are for internal use, so they are not + # declared. if not i.startswith('internal'): output_data.append('use {}::*;'.format(i)) From d6ed636d09ca8fd49ca9522967cba10d034077be Mon Sep 17 00:00:00 2001 From: manta1130 <46486762+manta1130@users.noreply.github.com> Date: Wed, 16 Sep 2020 19:19:13 +0900 Subject: [PATCH 18/25] Added EOL Co-authored-by: Ryo Yamashita --- .github/workflows/test-expand.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-expand.sh b/.github/workflows/test-expand.sh index f2be6b4..8a7b68f 100755 --- a/.github/workflows/test-expand.sh +++ b/.github/workflows/test-expand.sh @@ -22,4 +22,4 @@ for MODULE in ${TEST_MODULES[@]};do else echo "Test passed" fi -done \ No newline at end of file +done From c3cbe599fa9da38887266bca05099b4f49e2e452 Mon Sep 17 00:00:00 2001 From: manta1130 <46486762+manta1130@users.noreply.github.com> Date: Wed, 16 Sep 2020 20:34:02 +0900 Subject: [PATCH 19/25] Change the process if rustfmt returns error Co-authored-by: Ryo Yamashita --- expand.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/expand.py b/expand.py index 7c8881a..74c8340 100755 --- a/expand.py +++ b/expand.py @@ -111,7 +111,7 @@ def output_file(filename): print(output_header, file=f) for i in output_data: print(i, file=f) - output_data = subprocess.run(["rustfmt", temp_file]) + output_data = subprocess.run(["rustfmt", temp_file], check=True) with open(temp_file, 'r') as f: for line in f: print(line, end="") From 7363691c1e150ffe9b3918c8a5c759042bf3eca5 Mon Sep 17 00:00:00 2001 From: manta1130 Date: Wed, 16 Sep 2020 20:50:49 +0900 Subject: [PATCH 20/25] Change the test environment construction method --- .github/workflows/ci.yml | 18 +++++++++++++++++- .github/workflows/test-expand.sh | 4 ---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e693cfe..9658366 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -103,13 +103,29 @@ jobs: toolchain: - 1.42.0-x86_64-unknown-linux-gnu - stable-x86_64-unknown-linux-gnu + python-version: + - '3.6' # https://packages.ubuntu.com/bionic/python3 + - '3.8' # https://packages.ubuntu.com/focal/python3 - name: Expand_test (${{ matrix.toolchain }}) + name: Expand_test (${{ matrix.toolchain }}, ${{ matrix.python-version }}) runs-on: ubuntu-18.04 steps: - name: Checkout uses: actions/checkout@v2 + - name: 'Setup `${{ matrix.toolchain }}`' + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.toolchain }} + override: true + profile: minimal + components: rustfmt + + - name: Setup Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: expand.py tests run: bash ./.github/workflows/test-expand.sh diff --git a/.github/workflows/test-expand.sh b/.github/workflows/test-expand.sh index 8a7b68f..43ef8c9 100755 --- a/.github/workflows/test-expand.sh +++ b/.github/workflows/test-expand.sh @@ -6,10 +6,6 @@ SCRIPT_DIR=$(cd $(dirname $0); pwd) TEST_FILE="test.rs" FILE_HEAD="fn main() {}" -if [ -v CI ];then - rustup component add rustfmt -fi - for MODULE in ${TEST_MODULES[@]};do echo Test module $MODULE python3 $SCRIPT_DIR/../../expand.py $MODULE > $TMP_PATH/$TEST_FILE From 23ba807e005c67d40862b26c7f1d17c02503910c Mon Sep 17 00:00:00 2001 From: manta1130 Date: Wed, 16 Sep 2020 21:10:34 +0900 Subject: [PATCH 21/25] Sort output_list_all,dependency_list in lexicographical order --- expand.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/expand.py b/expand.py index 74c8340..24b0346 100755 --- a/expand.py +++ b/expand.py @@ -29,19 +29,21 @@ ''' output_header = '//https://github.com/rust-lang-ja/ac-library-rs\n' opt_list = ['help', 'all'] -output_list_all = ('lazysegtree', 'segtree', 'convolution', 'twosat', 'scc', - 'fenwicktree', 'math', 'modint', 'maxflow', 'dsu', - 'mincostflow', 'string', 'internal_bit', 'internal_math', - 'internal_type_traits', 'internal_scc', 'internal_queue') -dependency_list = {'lazysegtree': ('internal_bit',), - 'segtree': ('internal_bit',), - 'convolution': ('internal_bit', 'modint',), - 'math': ('internal_math',), - 'modint': ('internal_math', 'internal_type_traits'), +output_list_all = ('convolution', 'dsu', 'fenwicktree', 'lazysegtree', 'math', + 'maxflow', 'mincostflow', 'modint', 'scc', 'segtree', + 'string', 'twosat', + 'internal_bit', 'internal_math', 'internal_queue', + 'internal_scc', 'internal_type_traits',) +dependency_list = {'convolution': ('internal_bit', 'modint',), 'fenwicktree': ('internal_type_traits',), - 'twosat': ('internal_scc',), 'scc': ('internal_scc',), - 'maxflow': ('internal_queue', 'internal_type_traits',), - 'mincostflow': ('internal_type_traits',)} + 'lazysegtree': ('internal_bit',), + 'math': ('internal_math',), + 'maxflow': ('internal_type_traits', 'internal_queue',), + 'mincostflow': ('internal_type_traits',), + 'modint': ('internal_math', 'internal_type_traits',), + 'scc': ('internal_scc',), + 'segtree': ('internal_bit',), + 'twosat': ('internal_scc',), } src_path = 'src/' From fcacbc1981073d144b682c67e47f80ff4a694061 Mon Sep 17 00:00:00 2001 From: manta1130 <46486762+manta1130@users.noreply.github.com> Date: Thu, 17 Sep 2020 08:16:47 +0900 Subject: [PATCH 22/25] Remove unnecessary space Co-authored-by: Ryo Yamashita --- .github/workflows/test-expand.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-expand.sh b/.github/workflows/test-expand.sh index 43ef8c9..1430e0a 100755 --- a/.github/workflows/test-expand.sh +++ b/.github/workflows/test-expand.sh @@ -7,11 +7,11 @@ TEST_FILE="test.rs" FILE_HEAD="fn main() {}" for MODULE in ${TEST_MODULES[@]};do - echo Test module $MODULE + echo Test module $MODULE python3 $SCRIPT_DIR/../../expand.py $MODULE > $TMP_PATH/$TEST_FILE echo "Output" $(wc -c < $TMP_PATH/$TEST_FILE) "Bytes" echo $FILE_HEAD >> $TMP_PATH/$TEST_FILE - rustc -A warnings $TMP_PATH/$TEST_FILE + rustc -A warnings $TMP_PATH/$TEST_FILE if [ $? -ne 0 ];then echo "Error compiling for $MODULE" exit 1 From 0872289feca7f72d86a721045f5693d03e75d849 Mon Sep 17 00:00:00 2001 From: manta1130 Date: Thu, 17 Sep 2020 08:23:53 +0900 Subject: [PATCH 23/25] Fix dependency_list --- expand.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/expand.py b/expand.py index 24b0346..3c983c2 100755 --- a/expand.py +++ b/expand.py @@ -35,14 +35,13 @@ 'internal_bit', 'internal_math', 'internal_queue', 'internal_scc', 'internal_type_traits',) dependency_list = {'convolution': ('internal_bit', 'modint',), - 'fenwicktree': ('internal_type_traits',), - 'lazysegtree': ('internal_bit',), + 'lazysegtree': ('internal_bit', 'segtree'), 'math': ('internal_math',), 'maxflow': ('internal_type_traits', 'internal_queue',), 'mincostflow': ('internal_type_traits',), - 'modint': ('internal_math', 'internal_type_traits',), + 'modint': ('internal_math',), 'scc': ('internal_scc',), - 'segtree': ('internal_bit',), + 'segtree': ('internal_bit', 'internal_type_traits',), 'twosat': ('internal_scc',), } src_path = 'src/' From fb4785962d4209e605cc2a3d7c7e6cf12b5a7575 Mon Sep 17 00:00:00 2001 From: manta1130 <46486762+manta1130@users.noreply.github.com> Date: Thu, 17 Sep 2020 08:27:35 +0900 Subject: [PATCH 24/25] Change module definition(mod -> pub mod) Co-authored-by: Ryo Yamashita --- expand.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/expand.py b/expand.py index 3c983c2..4072ced 100755 --- a/expand.py +++ b/expand.py @@ -51,7 +51,7 @@ def output_file(filename): res = [] with open(src_path+filename+'.rs', 'r') as f: - res.append('mod {}{{'.format(filename)) + res.append('pub mod {} {{'.format(filename)) for line in f: res.append(line.rstrip()) From 2bcaf15030c91d6933fb9b315a9485ae1d0d58e4 Mon Sep 17 00:00:00 2001 From: manta1130 Date: Thu, 17 Sep 2020 12:24:01 +0900 Subject: [PATCH 25/25] Format codes --- .github/workflows/test-expand.sh | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test-expand.sh b/.github/workflows/test-expand.sh index 1430e0a..2d5b4c5 100755 --- a/.github/workflows/test-expand.sh +++ b/.github/workflows/test-expand.sh @@ -2,20 +2,21 @@ TEST_MODULES=(convolution dsu fenwicktree lazysegtree math maxflow mincostflow modint scc segtree string twosat --all) TMP_PATH=$(mktemp -d) -SCRIPT_DIR=$(cd $(dirname $0); pwd) +# shellcheck disable=SC2164 +SCRIPT_DIR="$(cd "$(dirname "$0")"; pwd)" TEST_FILE="test.rs" FILE_HEAD="fn main() {}" -for MODULE in ${TEST_MODULES[@]};do - echo Test module $MODULE - python3 $SCRIPT_DIR/../../expand.py $MODULE > $TMP_PATH/$TEST_FILE - echo "Output" $(wc -c < $TMP_PATH/$TEST_FILE) "Bytes" - echo $FILE_HEAD >> $TMP_PATH/$TEST_FILE - rustc -A warnings $TMP_PATH/$TEST_FILE - if [ $? -ne 0 ];then - echo "Error compiling for $MODULE" +for MODULE in "${TEST_MODULES[@]}" ;do + echo Test module "$MODULE" + python3 "$SCRIPT_DIR/../../expand.py" "$MODULE" > "$TMP_PATH/$TEST_FILE" + echo Output "$(wc -c < "$TMP_PATH/$TEST_FILE")" Bytes + echo "$FILE_HEAD" >> "$TMP_PATH/$TEST_FILE" + if ! rustc -A warnings "$TMP_PATH/$TEST_FILE"; + then + echo Error compiling for "$MODULE" exit 1 else - echo "Test passed" + echo Test passed fi done