-
Couldn't load subscription status.
- Fork 43
feat: add ability to cache json responses in-repo #1696
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ def _get_dump_manifest( | |
| env = {}, | ||
| working_directory = "", | ||
| debug_path = None, | ||
| cache_path = None, | ||
| registries_directory = None, | ||
| replace_scm_with_registry = False): | ||
| """Returns a dict representing the package dump for an SPM package. | ||
|
|
@@ -52,6 +53,10 @@ def _get_dump_manifest( | |
| debug_path = str(repository_ctx.path(".")) | ||
| debug_json_path = paths.join(debug_path, "dump.json") | ||
|
|
||
| cached_json_path = None | ||
| if cache_path: | ||
| cached_json_path = paths.join(cache_path, "dump.json") | ||
|
|
||
| args = ["swift", "package"] | ||
|
|
||
| if registries_directory: | ||
|
|
@@ -66,13 +71,15 @@ def _get_dump_manifest( | |
| env = env, | ||
| working_directory = working_directory, | ||
| debug_json_path = debug_json_path, | ||
| cached_json_path = cached_json_path, | ||
| ) | ||
|
|
||
| def _get_desc_manifest( | ||
| repository_ctx, | ||
| env = {}, | ||
| working_directory = "", | ||
| debug_path = None, | ||
| cache_path = None, | ||
| registries_directory = None, | ||
| replace_scm_with_registry = False): | ||
| """Returns a dict representing the package description for an SPM package. | ||
|
|
@@ -97,6 +104,10 @@ def _get_desc_manifest( | |
| debug_path = str(repository_ctx.path(".")) | ||
| debug_json_path = paths.join(debug_path, "desc.json") | ||
|
|
||
| cached_json_path = None | ||
| if cache_path: | ||
| cached_json_path = paths.join(cache_path, "desc.json") | ||
|
|
||
| args = ["swift", "package"] | ||
|
|
||
| if registries_directory: | ||
|
|
@@ -112,13 +123,15 @@ def _get_desc_manifest( | |
| env = env, | ||
| working_directory = working_directory, | ||
| debug_json_path = debug_json_path, | ||
| cached_json_path = cached_json_path, | ||
| ) | ||
|
|
||
| def _get( | ||
| repository_ctx, | ||
| directory, | ||
| env = {}, | ||
| debug_path = None, | ||
| cached_json_directory = None, | ||
| resolved_pkg_map = None, | ||
| collect_src_info = True, | ||
| registries_directory = None, | ||
|
|
@@ -150,11 +163,13 @@ def _get( | |
| if not paths.is_absolute(debug_path): | ||
| # For backwards compatibility, resolve relative to the working directory. | ||
| debug_path = paths.join(directory, debug_path) | ||
|
|
||
| dump_manifest = _get_dump_manifest( | ||
| repository_ctx, | ||
| env = env, | ||
| working_directory = directory, | ||
| debug_path = debug_path, | ||
| cache_path = cached_json_directory, | ||
| registries_directory = registries_directory, | ||
| replace_scm_with_registry = replace_scm_with_registry, | ||
| ) | ||
|
|
@@ -163,6 +178,7 @@ def _get( | |
| env = env, | ||
| working_directory = directory, | ||
| debug_path = debug_path, | ||
| cache_path = cached_json_directory, | ||
| registries_directory = registries_directory, | ||
| replace_scm_with_registry = replace_scm_with_registry, | ||
| ) | ||
|
|
@@ -1648,7 +1664,9 @@ def _new_resource_rule_process(localization = None): | |
|
|
||
| def _new_resource_from_desc_map(desc_map, pkg_path): | ||
| path = desc_map["path"] | ||
| if paths.is_absolute(path): | ||
| if path.startswith("./"): | ||
| path = path[2:] | ||
|
Comment on lines
+1667
to
+1668
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be |
||
| elif paths.is_absolute(path): | ||
| path = paths.relativize(path, pkg_path) | ||
| return _new_resource( | ||
| path = path, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| """Implementation for `swift_package`.""" | ||
|
|
||
| load("@bazel_skylib//lib:dicts.bzl", "dicts") | ||
| load("@bazel_skylib//lib:paths.bzl", "paths") | ||
| load("@bazel_tools//tools/build_defs/repo:git_worker.bzl", "git_repo") | ||
| load( | ||
| "@bazel_tools//tools/build_defs/repo:utils.bzl", | ||
|
|
@@ -68,10 +69,18 @@ def _swift_package_impl(repository_ctx): | |
| registries_directory = None | ||
|
|
||
| # Generate the build file | ||
| cached_json_directory = None | ||
| if repository_ctx.attr.cached_json_directory: | ||
| cached_json_directory = paths.join( | ||
| str(repository_ctx.workspace_root), | ||
| repository_ctx.attr.cached_json_directory, | ||
| ) | ||
|
|
||
| pkg_ctx = pkg_ctxs.read( | ||
| repository_ctx, | ||
| directory, | ||
| env, | ||
| cached_json_directory, | ||
| registries_directory = registries_directory, | ||
| replace_scm_with_registry = replace_scm_with_registry, | ||
| ) | ||
|
|
@@ -212,7 +221,10 @@ _ALL_ATTRS = dicts.add( | |
| _GIT_ATTRS, | ||
| repo_rules.env_attrs, | ||
| repo_rules.swift_attrs, | ||
| {"version": attr.string(doc = "The resolved version of the package.")}, | ||
| { | ||
| "cached_json_directory": attr.string(), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add a doc string. |
||
| "version": attr.string(doc = "The resolved version of the package."), | ||
| }, | ||
| ) | ||
|
|
||
| swift_package = repository_rule( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: