Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add path for zig-dependencies #1932

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions base/src/buildy.act
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,23 @@ class ZigDependency(object):
name: str
url: ?str
hash: ?str
path: ?str
options: dict[str, str]
artifacts: list[str]

def __init__(self, name: str, url: ?str, hash: ?str, options: dict[str, str], artifacts: list[str]):
def __init__(self, name: str, url: ?str, hash: ?str, path: ?str, options: dict[str, str], artifacts: list[str]):
self.name = zig_safe_name(name)
self.url = url
self.hash = hash
self.path = path
self.options = options
self.artifacts = artifacts

@staticmethod
def from_json(dep_name, data: dict[str, str]):
dep_url: ?str = None
dep_hash: ?str = None
dep_path: ?str = None
dep_options: dict[str, str] = {}
dep_artifacts: list[str] = []

Expand All @@ -172,6 +175,10 @@ class ZigDependency(object):
data_hash = value
if isinstance(data_hash, str):
dep_hash = data_hash
elif key == "path":
data_path = value
if isinstance(data_path, str):
dep_path = data_path
elif key == "options":
data_options = value
if isinstance(data_options, dict):
Expand All @@ -182,27 +189,43 @@ class ZigDependency(object):
dep_artifacts = data_artifacts
else:
raise ValueError("Invalid build.act.json, unknown key '%s' in dependency '%s'" % (key, dep_name))
return ZigDependency(dep_name, dep_url, dep_hash, dep_options, dep_artifacts)
return ZigDependency(dep_name, dep_url, dep_hash, dep_path, dep_options, dep_artifacts)

def to_json(self) -> dict[str, str]:
res = {}

url = self.url
if url is not None:
res["url"] = url

hash = self.hash
if hash is not None:
res["hash"] = hash

path = self.path
if path is not None:
res["path"] = path

options = self.options
if len(options) > 0:
res["options"] = options

artifacts = self.artifacts
if len(artifacts) > 0:
res["artifacts"] = artifacts

return res

def to_zon(self) -> str:
url = self.url
hash = self.hash
self_path = self.path
if self_path is not None:
return """ .%s = .{
.path = "%s",
},
""" % (self.name, self_path)

return """ .%s = .{
.url = "%s",
.hash = "%s",
Expand Down
2 changes: 1 addition & 1 deletion cli/src/acton.act
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ actor CmdZigPkgAdd(env, args):
build_config.zig_dependencies[dep_name].hash = dep_hash
else:
# Add the hash
build_config.zig_dependencies[dep_name] = ZigDependency(dep_name, dep_url, dep_hash, {}, dep_artifacts)
build_config.zig_dependencies[dep_name] = ZigDependency(dep_name, dep_url, dep_hash, None, {}, dep_artifacts)
print("Added new Zig package dependency", dep_name, "with hash", dep_hash)

baj_file = file.WriteFile(file.WriteFileCap(file.FileCap(env.cap)), "build.act.json")
Expand Down
Loading