Post Makefile to support choo.

This commit is contained in:
Sigilante 2024-11-05 17:16:14 -06:00
parent c704e27201
commit a01a3024b1
3 changed files with 111 additions and 0 deletions

View File

@ -15,6 +15,10 @@ PROFILE_DEV_FAST = --profile dev-fast
# Fastest!
PROFILE_RELEASE = --profile release
# Retrieve latest choo build.
CHOO_URL=https://github.com/zorp-corp/nockapp
CHOO_TAG=$(shell git ls-remote --tags $(CHOO_URL) | grep 'refs/tags/choo-' | grep -o 'refs/tags/.*' | sed 's/refs\/tags\///' | sort -V | tail -n1)
-: ## -----------------------------------------------------------
-: ## -------------- Commonly used commands below --------------
-: ## -----------------------------------------------------------
@ -22,6 +26,9 @@ PROFILE_RELEASE = --profile release
.PHONY: build
build: build-dev-fast ## Build in default profile (dev-fast)
.PHONY: release
release: build-release
.PHONY: release-test-zero
release-test-zero:
cargo run $(PROFILE_RELEASE) -- --new test-n 0
@ -36,17 +43,33 @@ release-test-all:
.PHONY: build-dev-fast
build-dev-fast: ## Slower to compile, faster to execute. Builds all projects
./choo hoon/main.hoon hoon
python3 update-cargo.py
cargo build $(PROFILE_DEV_FAST)
.PHONY: build-parallel
build-parallel: ## profiling profile with parallel feature enabled
./choo hoon/main.hoon hoon
python3 update-cargo.py
cargo build $(FEATURES_PARALLEL) $(PROFILE_PROFILING)
.PHONY: build
build-dev-debug: ## Fast to compile, slow to execute. Builds all projects
./choo hoon/main.hoon hoon
python3 update-cargo.py
cargo build
.PHONY: build-release
build-release: ## Slowest to compile, fastest to execute. Builds all projects
./choo hoon/main.hoon hoon
python3 update-cargo.py
cargo build $(PROFILE_RELEASE)
.PHONY: update-choo
update-choo:
curl -L -o choo "$(CHOO_URL)/releases/download/$(CHOO_TAG)/choo"
chmod u+x choo
.PHONY: choo-version
choo-version:
@echo "Latest choo version: $(CHOO_TAG)"

View File

@ -3,3 +3,30 @@
This is a developer preview of Jock, a friendly programming language that compiles to Nock.
Visit the [blog post](https://zorp.io/blog/jock) for more information.
The Jock compiler is written in Hoon.
## Building
We recommend including the `choo` NockApp executable in the repo for convenience. The path to the `choo` executable in these docs assumes this configuration.
```bash
# Building the JockApp pill with Choo (check the latest version)
CHOO_VERSION=0.1.3 bash -c 'curl -L -o choo https://github.com/zorp-corp/nockapp/releases/download/choo-"$CHOO_VERSION"/choo'
chmod u+x choo
./choo hoon/main.hoon hoon
# Produce the Jock NockApp
## Build only
make build
## Build and run release version
make release
## - or -
cargo build --release
# Testing Jock
./target/release/jock-testing test-all
./target/release/jock-testing test-n 5
```
For `choo`, the first argument is the entrypoint to the program, while the second argument is the root directory for source files.

61
update-cargo.py Executable file
View File

@ -0,0 +1,61 @@
#!/usr/bin/env python3
import subprocess
import re
# Function to get the latest commit hash for the specified branch from a repo
def get_latest_commit(repo_url, branch="master"):
print(repo_url)
try:
result = subprocess.run(
["git", "ls-remote", repo_url, branch],
capture_output=True,
text=True,
check=True
)
print(result.stdout)
return result.stdout.split()[0]
except subprocess.CalledProcessError:
print(f"Failed to retrieve the latest commit from {repo_url} on branch {branch}")
return None
# Read the current Cargo.toml file
try:
with open("Cargo.toml", "r") as file:
cargo_toml = file.read()
# Find all Git repo dependencies with their current revision hashes
matches = re.findall(
r'(\s*([^=\s]+)\s*=\s*{[^}]*git\s*=\s*"([^"]+)",\s*rev\s*=\s*")([a-f0-9]+)(")',
cargo_toml
)
if not matches:
print("No git dependencies with revisions found in Cargo.toml.")
else:
updated_toml = cargo_toml
for match in matches:
repo_name, _, repo_url, current_hash, trailing = match
print(f"Checking latest commit for {repo_name} at {repo_url}...")
# Retrieve the latest commit hash
latest_commit_hash = get_latest_commit(repo_url, 'status' if repo_url[-9:] == 'sword.git' else 'master')
if latest_commit_hash and latest_commit_hash != current_hash:
print(f"Updating {repo_name}: {current_hash} -> {latest_commit_hash}")
updated_toml = re.sub(
rf'{current_hash}',
rf'{latest_commit_hash}',
updated_toml
)
else:
print(f"{repo_name} is already up to date.")
# Write the updated content back to Cargo.toml if changes were made
if updated_toml != cargo_toml:
with open("Cargo.toml", "w") as file:
file.write(updated_toml)
print("Cargo.toml updated with the latest commit hashes.")
else:
print("No updates were necessary.")
except Exception as e:
print(f"An error occurred: {e}")