Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • bazel/rules_curl
1 result
Show changes
Commits on Source (12)
Showing
with 105 additions and 148 deletions
# [1.0.0-alpha.11](https://git.gitlab.arm.com/bazel/rules_curl/compare/v1.0.0-alpha.10...v1.0.0-alpha.11) (2024-07-05)
### Bug Fixes
- labeled csv file name ([280e5b9](https://git.gitlab.arm.com/bazel/rules_curl/commit/280e5b91eec50fec5a5d87f7aeb2f68873513a17))
- no empty lines ([939299b](https://git.gitlab.arm.com/bazel/rules_curl/commit/939299b0fa2249f626a55426e0ebeddcf554f455))
- non-executable runfiles ([f805b91](https://git.gitlab.arm.com/bazel/rules_curl/commit/f805b9163fe7d46db8f94d98a000e2acfaf0c4eb))
- template `pathname` ([cffc673](https://git.gitlab.arm.com/bazel/rules_curl/commit/cffc6734e2fbee2ecaa4567a699505cd734795ac))
### Code Refactoring
- unify rules ([c3d93d1](https://git.gitlab.arm.com/bazel/rules_curl/commit/c3d93d1de282ae1d3ba80e448de84bd638737ef0))
### BREAKING CHANGES
- different set of `curl_upload_file` run arguments
`curl_upload_file` and `curl_upload_manifests` are unified
of uploading files.
# [1.0.0-alpha.10](https://git.gitlab.arm.com/bazel/rules_curl/compare/v1.0.0-alpha.9...v1.0.0-alpha.10) (2024-06-27)
### Bug Fixes
......
......@@ -31,7 +31,3 @@
*.bazel
*.bzl
WORKSPACE
[curl_upload_file] @fredrik.paulsson
/curl/upload/file/
module(
name = "rules_curl",
version = "1.0.0-alpha.10",
version = "1.0.0-alpha.11",
bazel_compatibility = [
">=7.0.0",
],
......
......@@ -168,15 +168,7 @@ func main() {
flag.Var(&manifest.URL.Host, "host", "The domain name of the URL")
flag.Var(&manifest.URL.Protocol, "scheme", "The scheme for the URL")
flag.Func("pathname", "A location in a hierachical structure of the URL", func(s string) error {
buf := new(bytes.Buffer)
if !strings.HasPrefix(s, "/") {
buf.WriteString("/")
}
buf.WriteString(s)
manifest.URL.Pathname.Set(buf.String())
return nil
return manifest.URL.Pathname.Set(s)
})
flag.Func("origin", "The origin of the represented URL.", func(s string) error {
index := strings.Index(s, "//")
......
exports_files([
"posix.tmpl.sh",
"nt.tmpl.bat",
])
alias(
name = "script",
actual = select(
{
"@toolchain_utils//toolchain/constraint/os:windows": ":nt.tmpl.bat",
"//conditions:default": ":posix.tmpl.sh",
},
no_match_error = "No script template available for `curl_upload_manifests`",
),
visibility = ["//curl/upload:__subpackages__"],
)
sh_binary(
name = "csv",
srcs = ["csv.sh"],
visibility = ["//curl/upload:__subpackages__"],
)
load("@bazel_skylib//lib:types.bzl", "types")
visibility("public")
visibility("//...")
def init(file, url):
"""
......
load("@bazel_skylib//lib:types.bzl", "types")
visibility("public")
visibility("//...")
def init(manifests):
"""
......
......@@ -7,5 +7,7 @@ shift
readonly OUT
for ARG in "${@}"; do
printf >>"${OUT}" '%s\n' "${ARG}"
if test -n "${ARG}"; then
printf >>"${OUT}" '%s\n' "${ARG}"
fi
done
exports_files([
"posix.tmpl.sh",
"nt.tmpl.bat",
])
alias(
name = "template",
actual = select(
{
"@toolchain_utils//toolchain/constraint/os:windows": ":nt.tmpl.bat",
"//conditions:default": ":posix.tmpl.sh",
},
no_match_error = "No script template available for `curl_upload_file`",
),
visibility = ["//visibility:public"],
)
#! /usr/bin/env sh
# Strict shell
set -o errexit -o nounset
# Bazel substitutions
CURL="{{curl}}"
SRC="{{src}}"
DST="{{dst}}"
URL="{{url}}"
RETRY="{{retry}}"
RETRY_DELAY="{{retry_delay}}"
readonly CURL SRC DST URL RETRY RETRY_DELAY
# Runfiles
RUNFILES_DIR="${RUNFILES_DIR-${0}.runfiles}"
REPO_MAPPING="${RUNFILES_DIR}/_repo_mapping"
readonly RUNFILES_DIR REPO_MAPPING
# Repository Mapping
if test -f "${REPO_MAPPING}"; then
while IFS=, read -r CURRENT_CANONICAL TARGET_LOCAL TARGET_CANONICAL; do
if test "${TARGET_LOCAL}" != "__main__"; then
printf >&2 'Error: Unexpected repository mapping: %s,%s,%s\n' "${CURRENT_CANONICAL}" "${TARGET_LOCAL}" "${TARGET_CANONICAL}"
exit 2
fi
RUNFILES="${RUNFILES_DIR}/${TARGET_CANONICAL}"
break
done <"${REPO_MAPPING}"
unset CURRENT_CANONICAL TARGET_LOCAL TARGET_CANONICAL
else
RUNFILES="${0%/*}"
fi
# Parse arguments
ENDPOINT="${URL}"
DIRECTORY="/"
DESTINATION="${DST}"
while test 0 -ne "${#}"; do
case "${1}" in
"--url")
shift
ENDPOINT="${1?Must provide an argument for --url}"
;;
"--dir" | "--directory")
shift
DIRECTORY="${DIRECTORY}${1?Must provide an argument for --directory}/"
;;
"--dst" | "--destination")
shift
DESTINATION="${1?Must provide an argument for --destination}"
;;
*)
printf >&2 'Error: unknown argument: %s\n' "${1}"
exit 2
;;
esac
shift
done
readonly ENDPOINT DIRECTORY DESTINATION
COMPOSED="${ENDPOINT}${DIRECTORY}${DESTINATION}"
readonly COMPOSED
printf >&2 "Uploading: %s to %s\n" "${SRC}" "${COMPOSED}"
# Do the upload
"${RUNFILES}/${CURL}" \
--netrc \
--location \
--progress-bar \
--retry "${RETRY}" \
--retry-delay "${RETRY_DELAY}" \
--upload-file "${RUNFILES}/${SRC}" \
"${COMPOSED}"
load("@rules_curl//curl/upload:ManifestInfo.bzl", "ManifestInfo", "manifest_info")
visibility("//curl/...")
DOC = """Upload a file to a URL endpoint with cURL.
......@@ -34,37 +36,66 @@ ATTRS = {
doc = "The seconds to wait before attempting a upload retry.",
default = 1,
),
"template": attr.label(
"_script": attr.label(
doc = "The template that is expanded into the upload binary.",
default = ":template",
default = "//curl/upload:script",
allow_single_file = True,
),
"_template": attr.label(
default = "//curl/template:template",
cfg = "exec",
allow_single_file = True,
executable = True,
),
"_csv": attr.label(
doc = "CSV tool",
default = "//curl/upload:csv",
cfg = "exec",
executable = True,
),
}
def implementation(ctx):
curl = ctx.toolchains["//curl/toolchain/curl:type"]
csv = ctx.actions.declare_file("{}.upload.csv".format(ctx.label.name))
href = ctx.attr.url.rstrip("/").replace(",", "%2C")
dst = ctx.attr.dst
args = ctx.actions.args()
args.add("{},{},{}".format(ctx.file.src.short_path, "{{{{.URL.Href}}}}/{}".format(dst), href))
ctx.actions.run(
outputs = [csv],
inputs = [ctx.file.src],
arguments = [csv.path, args],
executable = ctx.executable._csv,
mnemonic = "PrepareUploadCSV",
)
executable = ctx.actions.declare_file("{}.sh".format(ctx.label.name))
substitutions = ctx.actions.template_dict()
substitutions.add("{{curl}}", str(curl.executable.short_path))
substitutions.add("{{url}}", ctx.attr.url.rstrip("/"))
substitutions.add("{{retry}}", str(ctx.attr.retry))
substitutions.add("{{retry_delay}}", str(ctx.attr.retry_delay))
substitutions.add("{{src}}", str(ctx.file.src.short_path))
substitutions.add("{{dst}}", str(ctx.attr.dst))
substitutions.add("{{csv}}", str(csv.short_path))
substitutions.add("{{template}}", str(ctx.executable._template.short_path))
substitutions.add("{{directory}}", str(ctx.file.src.short_path))
ctx.actions.expand_template(
template = ctx.file.template,
template = ctx.file._script,
output = executable,
computed_substitutions = substitutions,
is_executable = True,
)
files = depset([executable])
runfiles = ctx.runfiles([curl.executable, ctx.file.src])
runfiles = ctx.runfiles([curl.executable, ctx.file.src, csv])
runfiles = runfiles.merge(ctx.attr.src.default_runfiles)
runfiles = runfiles.merge(curl.default.default_runfiles)
runfiles = runfiles.merge(ctx.attr._template.default_runfiles)
runfiles = runfiles.merge(ctx.attr._csv.default_runfiles)
return DefaultInfo(
executable = executable,
......
load("//curl/upload:ManifestInfo.bzl", _Manifest = "Info")
visibility("public")
CurlUploadManifestInfo = _Manifest
exports_files([
"posix.tmpl.sh",
"nt.tmpl.bat",
])
alias(
name = "script",
actual = select(
{
"@toolchain_utils//toolchain/constraint/os:windows": ":nt.tmpl.bat",
"//conditions:default": ":posix.tmpl.sh",
},
no_match_error = "No script template available for `curl_upload_manifests`",
),
visibility = ["//curl/upload/manifests:__pkg__"],
)
sh_binary(
name = "csv",
srcs = ["csv.sh"],
visibility = ["//curl/upload/manifests:__pkg__"],
)
load(":rule.bzl", _manifests = "manifests")
load("//curl/upload:ManifestInfo.bzl", _Manifest = "Info")
load("//curl/upload:ManifestsInfo.bzl", _Manifests = "Info")
visibility("public")
curl_upload_manifests = _manifests
CurlUploadManifestInfo = _Manifest
CurlUploadManifestsInfo = _Manifests
@echo off
# TODO: implement Windows Batch for `curl_upload`
exit /b 121
......@@ -42,7 +42,7 @@ ATTRS = {
),
"_script": attr.label(
doc = "The template that is expanded into the upload binary.",
default = ":script",
default = "//curl/upload:script",
allow_single_file = True,
),
"_template": attr.label(
......@@ -53,7 +53,7 @@ ATTRS = {
),
"_csv": attr.label(
doc = "CSV tool",
default = ":csv",
default = "//curl/upload:csv",
cfg = "exec",
executable = True,
),
......@@ -62,7 +62,7 @@ ATTRS = {
def implementation(ctx):
curl = ctx.toolchains["//curl/toolchain/curl:type"]
csv = ctx.actions.declare_file("upload.csv")
csv = ctx.actions.declare_file("{}.upload.csv".format(ctx.label.name))
manifests = depset(
direct = [src[ManifestInfo] for src in ctx.attr.srcs if ManifestInfo in src],
transitive = [src[ManifestsInfo].manifests for src in ctx.attr.srcs if ManifestsInfo in src],
......@@ -81,6 +81,7 @@ def implementation(ctx):
outputs = [csv],
arguments = [csv.path, args],
executable = ctx.executable._csv,
mnemonic = "PrepareUploadCSV",
)
executable = ctx.actions.declare_file("{}.sh".format(ctx.label.name))
......
File moved
......@@ -7,23 +7,24 @@ set -o errexit -o nounset
rlocation() (
readonly FILEPATH="${1}"
if test -x "${FILEPATH}"; then
if test -e "${FILEPATH}"; then
printf '%s' "${FILEPATH}"
return
fi
readonly RUNFILES_DIR="${RUNFILES_DIR-${0}.runfiles}"
if test -x "${RUNFILES_DIR}/${FILEPATH#../}"; then
if test -e "${RUNFILES_DIR}/${FILEPATH#../}"; then
printf '%s' "${RUNFILES_DIR}/${FILEPATH#../}"
return
fi
if test -x "${RUNFILES_DIR}/"*"/${FILEPATH#../}"; then
if test -e "${RUNFILES_DIR}/"*"/${FILEPATH#../}"; then
printf '%s' "${RUNFILES_DIR}/"*"/${FILEPATH#../}"
return
fi
printf >&2 "No runfile found: %s\n" "${FILEPATH}"
exit 1
)
......
......@@ -9,7 +9,7 @@ while test "${#}" -ne 0; do
"--upload-file")
printf '%s\n' "${1}"
shift
if ! test -f "${1}"; then
if ! test -e "${1}"; then
printf >&2 'Not found: %s\n' "${1}"
exit 2
fi
......