diff --git a/.github/workflows/javascript.yml b/.github/workflows/javascript.yml index 244e8bd0..3a47640c 100644 --- a/.github/workflows/javascript.yml +++ b/.github/workflows/javascript.yml @@ -49,15 +49,15 @@ jobs: cache-dependency-path: 'javascript/package-lock.json' - name: Install dependencies - run: make js_dependencies + run: make js_dependencies COV=true - name: Run tests (serially) if: ${{ matrix.version == 22 && matrix.os == 'ubuntu-latest' }} - run: make js_test COV=true + run: make js_test COV=true HAS_NPM=0 - name: Run tests (in parallel) if: ${{ !(matrix.version == 22 && matrix.os == 'ubuntu-latest') }} - run: make js_test_auto COV=true + run: make js_test_auto COV=true HAS_NPM=0 - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v4.0.1 diff --git a/Makefile b/Makefile index 3c4d3b75..042c550d 100644 --- a/Makefile +++ b/Makefile @@ -42,39 +42,39 @@ html dirhtml singlehtml epub latex: LICENSE @$(MAKE) docs_$@ $(MFLAGS) .PHONY: clean -clean: LICENSE cs_clean cp_clean c_clean ja_clean js_clean py_clean rs_clean docs_clean +clean: cs_clean cp_clean c_clean ja_clean js_clean py_clean rs_clean docs_clean .PHONY: cs_% cs_%: LICENSE - @cd csharp && $(MAKE) $* $(MFLAGS) + @cd csharp && $(MAKE) $* $(MFLAGS) --no-print-directory .PHONY: cp_% cp_%: LICENSE - @cd cplusplus && $(MAKE) $* $(MFLAGS) + @cd cplusplus && $(MAKE) $* $(MFLAGS) --no-print-directory .PHONY: c_% c_%: LICENSE - @cd c && $(MAKE) $* $(MFLAGS) + @cd c && $(MAKE) $* $(MFLAGS) --no-print-directory .PHONY: docs_% docs_%: LICENSE - @cd docs && $(MAKE) $* $(MFLAGS) + @cd docs && $(MAKE) $* $(MFLAGS) --no-print-directory .PHONY: ja_% ja_%: LICENSE - @cd java && $(MAKE) $* $(MFLAGS) + @cd java && $(MAKE) $* $(MFLAGS) --no-print-directory .PHONY: js_% js_%: LICENSE - @cd javascript && $(MAKE) $* $(MFLAGS) + @cd javascript && $(MAKE) $* $(MFLAGS) --no-print-directory .PHONY: py_% py_%: LICENSE - @cd python && $(MAKE) $* $(MFLAGS) + @cd python && $(MAKE) $* $(MFLAGS) --no-print-directory .PHONY: rs_% rs_%: LICENSE - @cd rust && $(MAKE) $* $(MFLAGS) + @cd rust && $(MAKE) $* $(MFLAGS) --no-print-directory %: - @$(MAKE) c_$* cp_$* cs_$* ja_$* js_$* py_$* rs_$* $(MFLAGS) + @$(MAKE) c_$* cp_$* cs_$* ja_$* js_$* py_$* rs_$* $(MFLAGS) --no-print-directory diff --git a/c/Makefile b/c/Makefile index 2a6a8909..f7d99994 100644 --- a/c/Makefile +++ b/c/Makefile @@ -25,25 +25,25 @@ help: .PHONY: test_% test_%: ../LICENSE submodules dependencies - cd ../python; $(MAKE) dependencies $(MFLAGS) - $(PY) -m pytest -dvl -n$* test_euler.py --cov + @cd ../python; $(MAKE) dependencies $(MFLAGS) + @$(PY) -m pytest -dvl -n$* test_euler.py --cov .PHONY: test test: ../LICENSE submodules dependencies - $(PY) -m pytest -vl --benchmark-sort=fullname --benchmark-group-by=fullfunc --benchmark-verbose test_euler.py --cov + @$(PY) -m pytest -vl --benchmark-sort=fullname --benchmark-group-by=fullfunc --benchmark-verbose test_euler.py --cov .PHONY: submodules submodules: - git submodule init - git submodule update + @git submodule init + @git submodule update .PHONY: dependencies dependencies: submodules - $(PIP) install -r requirements.txt -r ../python/requirements.txt $(USER_FLAG) $(PROXY_ARG) + @$(PIP) install -r requirements.txt -r ../python/requirements.txt $(USER_FLAG) $(PROXY_ARG) .PHONY: lint lint: - if test -z "$(clang-tidy src/p0000_template.c -warnings-as-errors=* 2>&1 | grep "Unknown command line argument")"; then \ + @if test -z "$(clang-tidy src/p0000_template.c -warnings-as-errors=* 2>&1 | grep "Unknown command line argument")"; then \ clang-tidy src/*.c -warnings-as-errors=-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling; \ else \ clang-tidy src/*.c; \ @@ -51,14 +51,14 @@ lint: .PHONY: native native: ../LICENSE submodules - $(CC) test.c Unity/src/unity.c -O2 -lm -lc -Wall -Werror -march=native -flto -DAMD_COMPILER=0 + @$(CC) test.c Unity/src/unity.c -O2 -lm -lc -Wall -Werror -march=native -flto -DAMD_COMPILER=0 .PHONY: clean clean: - rm -r build ./{*,*/*}{.pyc,__pycache__,.mypy_cache} || echo + @rm -rf build {.,*,*/*}/{*.pyc,__pycache__,.mypy_cache,.pytest_cache,.benchmarks} || echo .PHONY: wasm wasm: ../LICENSE submodules - wget https://github.com/jedisct1/libclang_rt.builtins-wasm32.a -O wasm32.a - mkdir -p build - clang -DUNITY_END --target=wasm32-unknown-wasi --sysroot /tmp/wasi-libc -nostartfiles -Wl,--import-memory -Wl,--no-entry -Wl,--export-all -o build/c.wasm test.c + @wget https://github.com/jedisct1/libclang_rt.builtins-wasm32.a -O wasm32.a + @mkdir -p build + @clang -DUNITY_END --target=wasm32-unknown-wasi --sysroot /tmp/wasi-libc -nostartfiles -Wl,--import-memory -Wl,--no-entry -Wl,--export-all -o build/c.wasm test.c diff --git a/cplusplus/Makefile b/cplusplus/Makefile index 5ef1ff14..5fd56f98 100644 --- a/cplusplus/Makefile +++ b/cplusplus/Makefile @@ -24,25 +24,25 @@ help: .PHONY: test_% test_%: ../LICENSE dependencies - cd ../python; $(MAKE) dependencies $(MFLAGS) - $(PY) -m pytest -dvl -n$* test_euler.py --cov + @cd ../python; $(MAKE) dependencies $(MFLAGS) + @$(PY) -m pytest -dvl -n$* test_euler.py --cov .PHONY: test test: ../LICENSE dependencies - $(PY) -m pytest -vl --benchmark-sort=fullname --benchmark-group-by=fullfunc --benchmark-verbose test_euler.py --cov + @$(PY) -m pytest -vl --benchmark-sort=fullname --benchmark-group-by=fullfunc --benchmark-verbose test_euler.py --cov .PHONY: submodules submodules: - git submodule init - git submodule update + @git submodule init + @git submodule update .PHONY: dependencies dependencies: - $(PIP) install -r requirements.txt -r ../python/requirements.txt $(USER_FLAG) $(PROXY_ARG) + @$(PIP) install -r requirements.txt -r ../python/requirements.txt $(USER_FLAG) $(PROXY_ARG) .PHONY: lint lint: - if test -z "$(clang-tidy src/p0000_template.cpp -warnings-as-errors=* 2>&1 | grep "Unknown command line argument")"; then \ + @if test -z "$(clang-tidy src/p0000_template.cpp -warnings-as-errors=* 2>&1 | grep "Unknown command line argument")"; then \ clang-tidy src/*.cpp -warnings-as-errors=-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling; \ else \ clang-tidy src/*.cpp; \ @@ -50,8 +50,8 @@ lint: .PHONY: native native: ../LICENSE submodules - $(CXX) test.cpp Unity/src/unity.c -O2 -lm -Wall -Werror -std=c++11 -march=native -flto -DAMD_COMPILER=0 -Wno-deprecated + @$(CXX) test.cpp Unity/src/unity.c -O2 -lm -Wall -Werror -std=c++11 -march=native -flto -DAMD_COMPILER=0 -Wno-deprecated .PHONY: clean clean: - rm -r build ./{*,*/*}{.pyc,__pycache__,.mypy_cache} || echo + @rm -rf build {.,*,*/*}/{*.pyc,__pycache__,.mypy_cache,.pytest_cache,.benchmarks} || echo diff --git a/csharp/Makefile b/csharp/Makefile index 04111e5b..cdfbb696 100644 --- a/csharp/Makefile +++ b/csharp/Makefile @@ -18,26 +18,26 @@ help: .PHONY: clean clean: - dotnet clean || rm ./*/{bin,obj,TestResults} || echo + @dotnet clean || rm -rf ./*/{bin,obj,TestResults} || echo .PHONY: test test: ../LICENSE ifneq ($(NOT_TERMUX),0) - dotnet test --nologo $(cov_args) + @dotnet test --nologo $(cov_args) endif .PHONY: test_% -test_%: ../LICENSE - $(MAKE) test $(MFLAGS) +test_%: + @$(MAKE) test $(MFLAGS) --no-print-directory .PHONY: dependencies dependencies: ifneq ($(NOT_TERMUX),0) - dotnet restore + @dotnet restore endif .PHONY: lint lint: ifneq ($(NOT_TERMUX),0) - dotnet format --verify-no-changes + @dotnet format --verify-no-changes endif diff --git a/docs/Makefile b/docs/Makefile index 67b75649..373da406 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -27,50 +27,26 @@ help: .PHONY: clean clean: - rm -r _build _static/dist || echo + @rm -rf _build _static/dist || echo .PHONY: dependencies dependencies: - $(PIP) install -r requirements.txt -r ../c/requirements.txt -r ../python/requirements.txt --upgrade $(USER_FLAG) $(PROXY_ARG) - npm install -g jsdoc - -_static/test-c.html: - cd ../c && $(MAKE) webpack $(MFLAGS) - mkdir -p _static/dist - cp ../c/dist/bundle-c.js _static/dist/bundle-c.js - cat _static/test-js.html | sed s#_static/bundle-js.js#_static/bundle-c.js > _static/test-c.html - -_static/test-cp.html: - cd ../cplusplus && $(MAKE) webpack $(MFLAGS) - mkdir -p _static/dist - cp ../cplusplus/dist/bundle-cp.js _static/dist/bundle-cp.js - cat _static/test-js.html | sed s#_static/bundle-js.js#_static/bundle-cp.js > _static/test-cp.html - -_static/test-cs.html: - cd ../csharp && $(MAKE) webpack $(MFLAGS) - mkdir -p _static/dist - cp ../csharp/dist/bundle-cs.js _static/dist/bundle-cs.js - cat _static/dist/test-js.html | sed s#_static/bundle-js.js#_static/bundle-cs.js > _static/test-cs.html + @$(PIP) install -r requirements.txt -r ../c/requirements.txt -r ../python/requirements.txt --upgrade $(USER_FLAG) $(PROXY_ARG) + @npm install -g jsdoc _static/dist/bundle.js: - cd ../javascript && $(MAKE) webpack $(MFLAGS) - mkdir -p _static/dist - cp ../javascript/dist/bundle-js.js _static/dist/bundle-js.js + @cd ../javascript && $(MAKE) webpack $(MFLAGS) + @mkdir -p _static/dist + @cp ../javascript/dist/bundle-js.js _static/dist/bundle-js.js _static/dist/python.tar.gz: - cd ../python && $(MAKE) webpack $(MFLAGS) - -_static/test-rs.html: - cd ../rust && $(MAKE) webpack $(MFLAGS) - mkdir -p _static/dist - cp ../rust/dist/bundle-rs.js _static/dist/bundle-rs.js - cat _static/dist/test-js.html | sed s#_static/bundle-js.js#_static/bundle-rs.js > _static/test-rs.html + @cd ../python && $(MAKE) webpack $(MFLAGS) .PHONY: html -html: ../LICENSE _static/dist/bundle.js _static/dist/python.tar.gz - $(SPHINXBUILD) -M html "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) +html: _static/dist/bundle.js _static/dist/python.tar.gz + @$(SPHINXBUILD) -M html "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) # Catch-all target: route all unknown targets to Sphinx using the new # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). -%: ../LICENSE - $(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) +%: + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/java/Makefile b/java/Makefile index 59d82feb..2bfc91f4 100644 --- a/java/Makefile +++ b/java/Makefile @@ -11,19 +11,19 @@ help: .PHONY: clean clean: - $(MVN) clean || echo "Maven not installed" + @$(MVN) clean || echo "Maven not installed" .PHONY: test test: ../LICENSE - $(MVN) -e test -Dtest.single + @$(MVN) -e test -Dtest.single test_auto: ../LICENSE - $(MVN) -e test -T 1C + @$(MVN) -e test -T 1C .PHONY: test_% test_%: ../LICENSE - $(MVN) -e test -T $* + @$(MVN) -e test -T $* .PHONY: lint lint: - $(MVN) formatter:format + @$(MVN) formatter:format diff --git a/javascript/Makefile b/javascript/Makefile index e05107c1..98467be5 100644 --- a/javascript/Makefile +++ b/javascript/Makefile @@ -22,75 +22,80 @@ help: @echo " $(BLUE)clean$(NC) clean up any stray files" .PHONY: test -test: ../LICENSE dependencies - $(MOCHA) euler.test.js +test: ../LICENSE dependencies bun_test + @$(MOCHA) euler.test.js -test_auto: dependencies - $(MOCHA) --parallel euler.test.js +test_auto: dependencies bun_test + @$(MOCHA) --parallel euler.test.js .PHONY: test_% -test_%: ../LICENSE dependencies - $(MOCHA) --parallel -j $* euler.test.js +test_%: ../LICENSE dependencies bun_test + @$(MOCHA) --parallel -j $* euler.test.js .PHONY: bun_dependencies bun_dependencies: - if ! command -v bun; then npm -g install bun; fi - bun install +ifeq ($(NOT_TERMUX),1) +ifneq ($(HAS_NPM),0) + @if ! command -v bun; then npm -g install bun; fi +endif + @bun install +endif .PHONY: bun_test bun_test: ../LICENSE bun_dependencies +ifeq ($(NOT_TERMUX),1) ifeq ($(COV),true) - bun test --coverage --coverage-reporter lcov + @bun test --coverage --coverage-reporter lcov else - bun test + @bun test +endif endif .PHONY: dependencies ifneq ($(HAS_NPM),0) ifeq ($(OS),Windows_NT) # if no NPM and Windows dependencies: - 1>&2 echo "Windows not yet supported" - exit /b -1 + @1>&2 echo "Windows not yet supported" + @exit /b -1 else ifeq ($(NOT_TERMUX),0) # if no NPM and Termux dependencies: - pkg install -y nodejs; - $(MAKE) _dependencies $(MFLAGS) + @pkg install -y nodejs; + @$(MAKE) node_modules $(MFLAGS) else # if no NPM and not Termux dependencies: - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash \ - export NVM_DIR="$$HOME/.nvm"; \ - [ -s "$$NVM_DIR/nvm.sh" ] && \. "$$NVM_DIR/nvm.sh" \ - nvm install --lts - $(MAKE) _dependencies $(MFLAGS) + @curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash \ + @export NVM_DIR="$$HOME/.nvm"; \ + @[ -s "$$NVM_DIR/nvm.sh" ] && \. "$$NVM_DIR/nvm.sh" \ + @nvm install --lts + @$(MAKE) node_modules $(MFLAGS) endif endif else # has NPM -dependencies: _dependencies +dependencies: node_modules endif -.PHONY: _dependencies -_dependencies: +node_modules: ifeq ($(COV),true) - npm install -g istanbul + @npm install -g istanbul endif - npm install --include=dev + @npm install --include=dev .PHONY: lint lint: dependencies - npx eslint *.js src/*.js src/lib/*.js --ignore-pattern "dist/*" + @npx eslint *.js src/*.js src/lib/*.js --ignore-pattern "dist/*" .PHONY: clean clean: - rm -r node_modules dist src/lib/fallbacks || echo + @rm -rf node_modules dist src/lib/fallbacks || echo .PHONY: webpack webpack: ../LICENSE dependencies - mkdir -p src/lib/fallbacks - for f in ../_data/*; do \ + @mkdir -p src/lib/fallbacks + @for f in ../_data/*; do \ bf=$$(echo $$f | sed "s/.*\///"); \ echo -n "exports.value = '" > ./src/lib/fallbacks/$$bf.js; \ base64 -w0 $$f | head --bytes -1 >> ./src/lib/fallbacks/$$bf.js; \ echo "';" >> ./src/lib/fallbacks/$$bf.js; \ done - npx webpack + @npx webpack diff --git a/python/Makefile b/python/Makefile index b9bfe662..84320f4e 100644 --- a/python/Makefile +++ b/python/Makefile @@ -50,41 +50,35 @@ help: .PHONY: test test: ../LICENSE dependencies - $(PY) -m pytest $(pytest_args) $(benchmark_flags) + @$(PY) -m pytest $(pytest_args) $(benchmark_flags) .PHONY: test_% test_%: ../LICENSE dependencies - $(PY) -m pytest $(pytest_args) -d -n$* + @$(PY) -m pytest $(pytest_args) -d -n$* .PHONY: dependencies ifeq ($(MYPY),true) dependencies: - $(PIP) install -r requirements.txt $(USER_FLAG) $(PROXY_ARG) + @$(PIP) install -r requirements.txt $(USER_FLAG) $(PROXY_ARG) else dependencies: - cat requirements.txt | grep -v "mypy" > .requirements.txt - $(PIP) install -r .requirements.txt $(USER_FLAG) $(PROXY_ARG) + @cat requirements.txt | grep -v "mypy" > .requirements.txt + @$(PIP) install -r .requirements.txt $(USER_FLAG) $(PROXY_ARG) endif .PHONY: clean +clean: SHELL := bash clean: - rm -r ./{*,*/*}{.pyc,__pycache__,.mypy_cache} || echo + @rm -rf {.,*,*/*}/{*.pyc,__pycache__,.mypy_cache,.pytest_cache,.benchmarks} || echo .PHONY: webpack -webpack: ../LICENSE - # Create temporary directory for the archive content - mkdir -p ../docs/_static/dist/tmp/euler - cp -r ../_data ../docs/_static/dist/tmp/euler/_data - cp -r ../python ../docs/_static/dist/tmp/euler/python - - # Add __init__.py files to the temporary directory - echo "# init file" > ../docs/_static/dist/tmp/euler/__init__.py - echo "# init file" > ../docs/_static/dist/tmp/euler/python/__init__.py - - # Exclude unwanted directories and create tarball - cd ../docs/_static/dist/tmp && \ - tar --exclude='__pycache__' --exclude='*/__pycache__' \ - -czvf ../python.tar.gz euler - - # Clean up temporary directory - rm -rf ../docs/_static/dist/tmp +webpack: SHELL := bash +webpack: TMPDIR := ../docs/_static/dist/tmp-python-webpack +webpack: ../LICENSE clean + @mkdir -p $(TMPDIR)/euler + @cp -r ../{_data,python} $(TMPDIR)/euler/ + @touch $(TMPDIR)/euler{,/python}/__init__.py + @cd $(TMPDIR) && tar -czv \ + --exclude=euler/python/{Makefile,README.rst,primes.mpack,requirements.txt,setup.cfg,src/lib/primes_cache.mpack} \ + -f ../python.tar.gz euler + @rm -rf $(TMPDIR) diff --git a/rust/Makefile b/rust/Makefile index 460a4c2c..8bce11e8 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -10,15 +10,15 @@ help: .PHONY: test test: ../LICENSE - cargo test -j 1 + @cargo test -j 1 test_auto: ../LICENSE - cargo test + @cargo test .PHONY: test_% test_%: ../LICENSE - cargo test -j $* + @cargo test -j $* .PHONY: clean clean: - cargo clean || echo + @cargo clean || echo