Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
aappleby committed Mar 25, 2024
1 parent 770ee10 commit dec06fd
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 35 deletions.
34 changes: 22 additions & 12 deletions hancho.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ def relpath(path1, path2):
return Path(str(path1).removeprefix(str(path2) + "/"))


def join(*args):
def joinpath(*args):
"""Produces all possible concatenated paths from the given paths (or arrays of paths)."""
if len(args) > 2:
return join(args[0], join(*args[1:]))
return joinpath(args[0], joinpath(*args[1:]))
if isinstance(args[0], list):
return [join(a, args[1]) for a in args[0]]
return [joinpath(a, args[1]) for a in args[0]]
if isinstance(args[1], list):
return [join(args[0], a) for a in args[1]]
return [joinpath(args[0], a) for a in args[1]]
return Path(args[0]) / Path(args[1])


Expand Down Expand Up @@ -653,34 +653,44 @@ def __init__(self):
# fmt: off
self.global_config = Config(
name="<Global Config>",

# Config flags
start_path=Path.cwd(),
start_files="build.hancho",
desc = "{source_files} -> {build_files}",
job_count=1,
depformat="gcc",
chdir=".",
jobs=os.cpu_count(),
verbose=False,
quiet=False,
dry_run=False,
debug=False,
force=False,
ext_build=False,

# Helper functions
abspath=abspath,
relpath=relpath,
joinpath=joinpath,
color=color,
glob=glob,
len=len,
Path=Path,
run_cmd=run_cmd,
swap_ext=swap_ext,
join=join,
abs_source_files = "{join(source_path, source_files)}",
abs_build_files = "{join(build_path, build_files)}",
abs_command_files = "{join(command_path, command_files)}",

# Helper macros
abs_source_files = "{joinpath(source_path, source_files)}",
abs_build_files = "{joinpath(build_path, build_files)}",
abs_command_files = "{joinpath(command_path, command_files)}",
rel_source_files = "{relpath(abs_source_files, command_path)}",
rel_build_files = "{relpath(abs_build_files, command_path)}",
rel_command_files = "{relpath(abs_command_files, command_path)}",

# Rule defaults
desc = "{source_files} -> {build_files}",
job_count=1,
depformat="gcc",
ext_build=False,

# Global config has no base.
base=None,
)
# fmt: on
Expand Down
6 changes: 1 addition & 5 deletions tutorial/src/src.hancho
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import glob

this_path = Path(__file__).parent

build_config.set_defaults(
command_path = this_path,
source_path = this_path,
build_path = this_path / "build",
)
build_config.source_path = this_path

rules = load("../rules.hancho", build_config)

Expand Down
2 changes: 1 addition & 1 deletion tutorial/tut0.hancho
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ from hancho import *
import os

Task(
command = "g++ {source_files} -o {build_files}",
command = "g++ {rel_source_files} -o {rel_build_files}",
command_path = Path.cwd(),

source_files = ["src/main.cpp", "src/util.cpp"],
Expand Down
8 changes: 4 additions & 4 deletions tutorial/tut1.hancho
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
from hancho import *

compile = Rule(
desc = "Compile {source_files} -> {build_files}",
command = "g++ -c {source_files} -o {build_files}",
desc = "Compile {rel_source_files} -> {rel_build_files}",
command = "g++ -c {rel_source_files} -o {rel_build_files}",
command_path = Path.cwd(),
source_path = Path.cwd(),
build_path = Path.cwd(),
)

link = Rule(
desc = "Link {source_files} -> {build_files}",
command = "g++ {source_files} -o {build_files}",
desc = "Link {rel_source_files} -> {rel_build_files}",
command = "g++ {rel_source_files} -o {rel_build_files}",
command_path = Path.cwd(),
source_path = Path.cwd(),
build_path = Path.cwd(),
Expand Down
14 changes: 6 additions & 8 deletions tutorial/tut2.hancho
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@ config = global_config.extend(
)

compile = config.rule(
desc = "Compile {source_files} -> {build_files}",
command = "g++ -MMD -c {source_files} -o {join(build_dir, build_files)}",
build_files = "{swap_ext(source_files, '.o')}",
build_deps = "{swap_ext(source_files, '.d')}",
build_dir = "{relpath(build_path, command_path)}",
desc = "Compile {rel_source_files} -> {rel_build_files}",
command = "g++ -MMD -c {rel_source_files} -o {rel_build_files}",
build_files = "{swap_ext(rel_source_files, '.o')}",
build_deps = "{swap_ext(rel_source_files, '.d')}",
)

link = config.rule(
desc = "Link {source_files} -> {build_files}",
command = "g++ {source_files} -o {join(build_dir,build_files)}",
build_dir = "{relpath(build_path, command_path)}",
desc = "Link {rel_source_files} -> {rel_build_files}",
command = "g++ {rel_source_files} -o {rel_build_files}",
)

main_o = compile("src/main.cpp")
Expand Down
9 changes: 4 additions & 5 deletions tutorial/tut4.hancho
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ from hancho import *

this_path = Path(__file__).parent

load(
"src/src.hancho",
command_path = this_path,
build_path = this_path / "build/tut4",
)
build_config.command_path = this_path
build_config.build_path = this_path / "build/tut4"

load("src/src.hancho", build_config)

0 comments on commit dec06fd

Please sign in to comment.