A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/bazel-contrib/rules_distroless/commit/e43119e594a40bcb06243935cd1ff4084cd06224 below:

improve the lock copy.sh script (#92) · bazel-contrib/rules_distroless@e43119e · GitHub

File tree Expand file treeCollapse file tree 3 files changed

+68

-49

lines changed

Filter options

Expand file treeCollapse file tree 3 files changed

+68

-49

lines changed Original file line number Diff line number Diff line change

@@ -3,6 +3,7 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

3 3

exports_files([

4 4

"dpkg_statusd.sh",

5 5

"dpkg_status.sh",

6 +

"copy.sh.tmpl",

6 7

"package.BUILD.tmpl",

7 8

])

8 9 Original file line number Diff line number Diff line change

@@ -0,0 +1,51 @@

1 +

#!/usr/bin/env bash

2 + 3 +

set -o pipefail -o errexit -o nounset

4 + 5 +

lock=$(realpath "$1")

6 +

autofix=${{2:-}}

7 + 8 +

cd "$BUILD_WORKING_DIRECTORY"

9 + 10 +

echo

11 +

echo "Writing lockfile to {workspace_relative_path}"

12 +

cp "$lock" "{workspace_relative_path}"

13 + 14 +

# Detect which file we wish the user to edit

15 +

if [ -e "$BUILD_WORKSPACE_DIRECTORY/WORKSPACE" ]; then

16 +

wksp_file="WORKSPACE"

17 +

elif [ -e "$BUILD_WORKSPACE_DIRECTORY/WORKSPACE.bazel" ]; then

18 +

wksp_file="WORKSPACE.bazel"

19 +

elif [ -e "$BUILD_WORKSPACE_DIRECTORY/MODULE.bazel" ]; then

20 +

wksp_file="MODULE.bazel"

21 +

else

22 +

echo>&2 "Error: no MODULE.bazel or WORKSPACE file was found"

23 +

exit 1

24 +

fi

25 + 26 +

# Detect a vendored buildozer binary in canonical location (tools/buildozer)

27 +

if [ -e "$BUILD_WORKSPACE_DIRECTORY/tools/buildozer" ]; then

28 +

buildozer="tools/buildozer"

29 +

else

30 +

# Assume it's on the $PATH

31 +

buildozer="buildozer"

32 +

fi

33 + 34 +

echo

35 + 36 +

cmd="$buildozer 'set lock \"{lock_label}\"' $wksp_file:{repo_name}"

37 + 38 +

if [[ "$autofix" == "--autofix" ]]; then

39 +

eval "$cmd"

40 +

else

41 +

cat <<EOF

42 +

Run the following command to add the 'lock' attribute

43 +

to the "{repo_name}" repo in $wksp_file:

44 + 45 +

$cmd

46 + 47 +

or run the following command to do it automatically:

48 + 49 +

bazel run @{repo_name}//:lock -- --autofix

50 +

EOF

51 +

fi

Original file line number Diff line number Diff line change

@@ -83,50 +83,6 @@ def internal_resolve(rctx, yq_toolchain_prefix, manifest, include_transitive):

83 83

lockf.add_package_dependency(package, dep, arch)

84 84

return lockf

85 85 86 -

_COPY_SH_TMPL = """\

87 -

#!/usr/bin/env bash

88 -

set -o pipefail -o errexit -o nounset

89 - 90 -

lock=$(realpath $1)

91 - 92 -

cd $BUILD_WORKING_DIRECTORY

93 - 94 -

echo ''

95 -

echo 'Writing lockfile to {workspace_relative_path}'

96 -

cp $lock {workspace_relative_path}

97 - 98 -

# Detect which file we wish the user to edit

99 -

if [ -e $BUILD_WORKSPACE_DIRECTORY/WORKSPACE ]; then

100 -

wksp_file="WORKSPACE"

101 -

elif [ -e $BUILD_WORKSPACE_DIRECTORY/WORKSPACE.bazel ]; then

102 -

wksp_file="WORKSPACE.bazel"

103 -

elif [ -e $BUILD_WORKSPACE_DIRECTORY/MODULE.bazel ]; then

104 -

wksp_file="MODULE.bazel"

105 -

else

106 -

echo>&2 "Error: no MODULE.bazel or WORKSPACE file was found"

107 -

exit 1

108 -

fi

109 - 110 -

# Detect a vendored buildozer binary in canonical location (tools/buildozer)

111 -

if [ -e $BUILD_WORKSPACE_DIRECTORY/tools/buildozer ]; then

112 -

buildozer="tools/buildozer"

113 -

else

114 -

# Assume it's on the $PATH

115 -

buildozer="buildozer"

116 -

fi

117 - 118 -

if [[ "${{2:-}}" == "--autofix" ]]; then

119 -

echo ''

120 -

${{buildozer}} 'set lock \"{label}\"' ${{wksp_file}}:{name}

121 -

else

122 -

cat <<EOF

123 -

Run the following command to add the lockfile or pass --autofix flag to do it automatically.

124 - 125 -

${{buildozer}} 'set lock \"{label}\"' ${{wksp_file}}:{name}

126 -

EOF

127 -

fi

128 -

"""

129 - 130 86

_BUILD_TMPL = """

131 87

filegroup(

132 88

name = "lockfile",

@@ -149,16 +105,22 @@ def _deb_resolve_impl(rctx):

149 105

lockf = internal_resolve(rctx, rctx.attr.yq_toolchain_prefix, rctx.attr.manifest, rctx.attr.resolve_transitive)

150 106

lockf.write("lock.json")

151 107 152 -

locklabel = rctx.attr.manifest.relative(rctx.attr.manifest.name.replace(".yaml", ".lock.json"))

108 +

lock_filename = rctx.attr.manifest.name.replace(".yaml", ".lock.json")

109 +

lock_label = rctx.attr.manifest.relative(lock_filename)

110 +

workspace_relative_path = "{}{}".format(

111 +

("%s/" % lock_label.package) if lock_label.package else "",

112 +

lock_label.name,

113 +

)

114 + 153 115

rctx.file(

154 116

"copy.sh",

155 -

_COPY_SH_TMPL.format(

117 +

rctx.read(rctx.attr._copy_sh_tmpl).format(

156 118

# NOTE: the split("~") is needed when we run bazel from another

157 119

# directory, e.g. when running e2e tests we change dir to e2e/smoke

158 120

# and then rctx.name is 'rules_distroless~~apt~bullseye'

159 -

name = rctx.name.split("~")[-1].replace("_resolve", ""),

160 -

label = locklabel,

161 -

workspace_relative_path = (("%s/" % locklabel.package) if locklabel.package else "") + locklabel.name,

121 +

repo_name = rctx.name.split("~")[-1].replace("_resolve", ""),

122 +

lock_label = lock_label,

123 +

workspace_relative_path = workspace_relative_path,

162 124

),

163 125

executable = True,

164 126

)

@@ -171,5 +133,10 @@ deb_resolve = repository_rule(

171 133

"manifest": attr.label(),

172 134

"resolve_transitive": attr.bool(default = True),

173 135

"yq_toolchain_prefix": attr.string(default = "yq"),

136 +

"_copy_sh_tmpl": attr.label(

137 +

default = "//apt/private:copy.sh.tmpl",

138 +

doc = "INTERNAL, DO NOT USE - " +

139 +

"private attribute label to prevent repo restart",

140 +

),

174 141

},

175 142

)

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4