Skip to content

Commit

Permalink
Ditch HANCHO_HEADER - as @tannewt pointed out, it breaks line numbers…
Browse files Browse the repository at this point in the history
… when debugging.
  • Loading branch information
aappleby committed Mar 9, 2024
1 parent d72009d commit 8bf365c
Show file tree
Hide file tree
Showing 32 changed files with 43 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ options:
## Simple Example
```py
# examples/hello_world/build.hancho
from hancho import *

compile = Rule(
desc = "Compile {files_in} -> {files_out}",
Expand Down
2 changes: 2 additions & 0 deletions build.hancho
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from hancho import *

config.verbose = True
config.jobs = 1

Expand Down
2 changes: 1 addition & 1 deletion examples/hello_world/build.hancho
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# examples/hello_world/build.hancho

from hancho import *
import asyncio

compile = Rule(
Expand Down
1 change: 1 addition & 0 deletions examples/meson/build.hancho
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# examples/meson/build.hancho
from hancho import *

config.build_type = "debug"
config.build_dir = "build/{build_type}"
Expand Down
1 change: 1 addition & 0 deletions examples/windows/build.hancho
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# hancho/examples/windows/build.hancho - Builds a trivial Win32 app.
from hancho import *

compile = Rule(
desc = "Compile {files_in} -> {files_out}",
Expand Down
9 changes: 1 addition & 8 deletions hancho.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,6 @@ async def async_main():
# The .hancho file loader does a small amount of work to keep track of the
# stack of .hancho files that have been loaded.

# This is prepended to each .hancho file
HANCHO_HEADER = """
from hancho import *
from glob import glob
"""


def load(mod_path):
"""
Searches the loaded Hancho module stack for a module whose directory
Expand All @@ -296,7 +289,7 @@ def load_abs(abs_path):
mod_name = mod_file.split(".")[0]

with open(abs_path, encoding="utf-8") as file:
source = HANCHO_HEADER + file.read()
source = file.read()
code = compile(source, abs_path, "exec", dont_inherit=True)

module = type(sys)(mod_name)
Expand Down
2 changes: 2 additions & 0 deletions tests/always_rebuild_if_no_inputs.hancho
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
from hancho import *

rules = load("rules.hancho")
rules.touch_outputs([], "result.txt")
2 changes: 2 additions & 0 deletions tests/build_dir_works.hancho
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from hancho import *

rules = load("rules.hancho")
config.build_dir = "build/build_dir_works"
rules.touch_outputs([], "result.txt")
1 change: 1 addition & 0 deletions tests/check_output.hancho
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# tests/check_output.hancho
from hancho import *

check_output = Rule(command = "echo foo > {files_out[0]}")

Expand Down
2 changes: 2 additions & 0 deletions tests/command_missing.hancho
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
from hancho import *

command_missing = Rule()
command_missing(__file__)
2 changes: 2 additions & 0 deletions tests/dep_changed.hancho
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from hancho import *

rules = load("rules.hancho")
rules.touch_outputs(
"src/test.cpp",
Expand Down
2 changes: 2 additions & 0 deletions tests/does_create_output.hancho
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
from hancho import *

rules = load("rules.hancho")
rules.touch_outputs([], files_out = "result.txt")
2 changes: 2 additions & 0 deletions tests/doesnt_create_output.hancho
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
from hancho import *

doesnt_create_output = Rule(command = ":")
doesnt_create_output(__file__, "result.txt")
1 change: 1 addition & 0 deletions tests/expand_failed_to_terminate.hancho
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# tests/expand_failed_to_terminate.hancho
from hancho import *

expand_failed_to_terminate = Rule(
command = "{flarp}",
Expand Down
2 changes: 2 additions & 0 deletions tests/garbage_command.hancho
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
from hancho import *

garbage_command = Rule(command = "aklsjdflksjdlfkjldfk")
garbage_command(__file__, "result.txt")
2 changes: 2 additions & 0 deletions tests/header_changed.hancho
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
from hancho import *

rules = load("rules.hancho")
rules.compile_cpp("src/test.cpp")
2 changes: 2 additions & 0 deletions tests/input_changed.hancho
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
from hancho import *

rules = load("rules.hancho")
rules.compile_cpp("src/test.cpp")
2 changes: 2 additions & 0 deletions tests/missing_src.hancho
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
from hancho import *

rules = load("rules.hancho")
rules.touch_outputs("src/does_not_exist.txt", "build/missing_src.txt")
1 change: 1 addition & 0 deletions tests/multiple_commands.hancho
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from hancho import *
import os

multiple_commands = Rule(
Expand Down
1 change: 1 addition & 0 deletions tests/recursive_base_is_bad.hancho
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# tests/recursive_base_is_bad.hancho
from hancho import *

rule1 = Rule(
command = "{thing}",
Expand Down
1 change: 1 addition & 0 deletions tests/rules.hancho
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from hancho import *
import os

if os.name == 'nt':
Expand Down
1 change: 1 addition & 0 deletions tests/should_fail.hancho
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# tests/should_fail.hancho
from hancho import *

should_fail = Rule(
desc = "This task should fail",
Expand Down
1 change: 1 addition & 0 deletions tests/should_pass.hancho
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# tests/should_pass.hancho
from hancho import *

should_pass = Rule(
desc = "This task should pass",
Expand Down
2 changes: 1 addition & 1 deletion tests/sync_command.hancho
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

from hancho import *

def sync_command(task):
touch(task.files_out[0])
Expand Down
1 change: 1 addition & 0 deletions tutorial/build.hancho
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# hancho/tutorial/build.hancho - Tests all the tutorials
from hancho import *

config.jobs = 1
#config.verbose = True
Expand Down
2 changes: 1 addition & 1 deletion tutorial/rules.hancho
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# tutorial/rules.hancho

from hancho import *
import os

compile = Rule(
Expand Down
1 change: 1 addition & 0 deletions tutorial/src/src.hancho
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# tutorial/src/src.hancho
from hancho import *
import glob
import os

Expand Down
2 changes: 1 addition & 1 deletion tutorial/tut0.hancho
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# tutorial/tut0.hancho

from hancho import *
import os

rule = Rule(
Expand Down
1 change: 1 addition & 0 deletions tutorial/tut1.hancho
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# tutorial/tut1.hancho
from hancho import *

compile = Rule(
desc = "Compile {files_in} -> {files_out}",
Expand Down
1 change: 1 addition & 0 deletions tutorial/tut2.hancho
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# tutorial/tut2.hancho
from hancho import *

config.build_dir = "build/tut2"

Expand Down
1 change: 1 addition & 0 deletions tutorial/tut3.hancho
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# tutorial/tut3.hancho
from hancho import *

config.build_dir = "build/tut3"

Expand Down
1 change: 1 addition & 0 deletions tutorial/tut4.hancho
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# tutorial/tut4.hancho - Async/await and custom commands
from hancho import *
import asyncio

config.build_dir = "build/tut4"
Expand Down

0 comments on commit 8bf365c

Please sign in to comment.