Skip to content

Commit ddb67ed

Browse files
authored
Migrate to use absl from gflags (#1534)
1 parent f7e6d6f commit ddb67ed

3 files changed

Lines changed: 62 additions & 26 deletions

File tree

container/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ py_library(
4343
srcs_version = "PY2AND3",
4444
visibility = ["//visibility:public"],
4545
deps = [
46-
"@bazel_tools//third_party/py/gflags",
46+
"@io_abseil_py//absl/flags",
4747
"@rules_pkg//:archive",
4848
],
4949
)

container/build_tar.py

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,85 +25,86 @@
2525
import tarfile
2626
import tempfile
2727

28+
from absl import flags
2829
from rules_pkg import archive
29-
from third_party.py import gflags
3030

31-
gflags.DEFINE_string('output', None, 'The output file, mandatory')
32-
gflags.MarkFlagAsRequired('output')
3331

34-
gflags.DEFINE_multistring('file', [], 'A file to add to the layer')
32+
flags.DEFINE_string('output', None, 'The output file, mandatory')
33+
flags.mark_flag_as_required('output')
3534

36-
gflags.DEFINE_string('manifest', None, 'JSON manifest of contents to add to the layer')
35+
flags.DEFINE_multi_string('file', [], 'A file to add to the layer')
3736

38-
gflags.DEFINE_multistring('empty_file', [], 'An empty file to add to the layer')
37+
flags.DEFINE_string('manifest', None, 'JSON manifest of contents to add to the layer')
3938

40-
gflags.DEFINE_multistring('empty_dir', [], 'An empty dir to add to the layer')
39+
flags.DEFINE_multi_string('empty_file', [], 'An empty file to add to the layer')
4140

42-
gflags.DEFINE_string(
41+
flags.DEFINE_multi_string('empty_dir', [], 'An empty dir to add to the layer')
42+
43+
flags.DEFINE_string(
4344
'mode', None, 'Force the mode on the added files (in octal).')
4445

45-
gflags.DEFINE_string(
46+
flags.DEFINE_string(
4647
'mtime', None, 'Set mtime on tar file entries. May be an integer or the'
4748
' value "portable", to get the value 2000-01-01, which is'
4849
' usable with non *nix OSes.')
4950

50-
gflags.DEFINE_bool(
51+
flags.DEFINE_bool(
5152
'enable_mtime_preservation', False, 'Preserve file mtimes from input tar file.')
5253

53-
gflags.DEFINE_multistring(
54+
flags.DEFINE_multi_string(
5455
'empty_root_dir',
5556
[],
5657
'An empty root directory to add to the layer. This will create a directory that'
5758
'is a peer of "root_directory". "empty_dir" creates an empty directory inside of'
5859
'"root_directory"')
5960

60-
gflags.DEFINE_multistring('tar', [], 'A tar file to add to the layer')
61+
flags.DEFINE_multi_string('tar', [], 'A tar file to add to the layer')
6162

62-
gflags.DEFINE_multistring('deb', [], 'A debian package to add to the layer')
63+
flags.DEFINE_multi_string('deb', [], 'A debian package to add to the layer')
6364

64-
gflags.DEFINE_multistring(
65+
flags.DEFINE_multi_string(
6566
'link', [],
6667
'Add a symlink a inside the layer ponting to b if a:b is specified')
67-
gflags.RegisterValidator(
68+
flags.register_validator(
6869
'link',
6970
lambda l: all(value.find(':') > 0 for value in l),
7071
message='--link value should contains a : separator')
7172

72-
gflags.DEFINE_string(
73+
flags.DEFINE_string(
7374
'directory', None, 'Directory in which to store the file inside the layer')
7475

75-
gflags.DEFINE_string(
76+
flags.DEFINE_string(
7677
'compression', None, 'Compression (`gz` or `bz2`), default is none.')
7778

78-
gflags.DEFINE_multistring(
79+
flags.DEFINE_multi_string(
7980
'modes', None,
8081
'Specific mode to apply to specific file (from the file argument),'
8182
' e.g., path/to/file=0o455.')
8283

83-
gflags.DEFINE_multistring('owners', None,
84+
flags.DEFINE_multi_string('owners', None,
8485
'Specify the numeric owners of individual files, '
8586
'e.g. path/to/file=0.0.')
8687

87-
gflags.DEFINE_string('owner', '0.0',
88+
flags.DEFINE_string('owner', '0.0',
8889
'Specify the numeric default owner of all files,'
8990
' e.g., 0.0')
9091

91-
gflags.DEFINE_string('owner_name', None,
92+
flags.DEFINE_string('owner_name', None,
9293
'Specify the owner name of all files, e.g. root.root.')
9394

94-
gflags.DEFINE_multistring('owner_names', None,
95+
flags.DEFINE_multi_string('owner_names', None,
9596
'Specify the owner names of individual files, e.g. '
9697
'path/to/file=root.root.')
9798

98-
gflags.DEFINE_string(
99+
flags.DEFINE_string(
99100
'root_directory', './', 'Default root directory is named "."'
100101
'Windows docker images require this be named "Files" instead of "."')
101102

102-
gflags.DEFINE_string('xz_path', None,
103+
flags.DEFINE_string('xz_path', None,
103104
'Specify the path to xz as a fallback when the Python '
104105
'lzma module is unavailable.')
105106

106-
FLAGS = gflags.FLAGS
107+
FLAGS = flags.FLAGS
107108

108109

109110
class TarFile(object):

repositories/repositories.bzl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,41 @@ def repositories():
150150
urls = ["https://github.com/bazelbuild/rules_pkg/releases/download/0.2.6-1/rules_pkg-0.2.6.tar.gz"],
151151
)
152152

153+
if "io_abseil_py" not in excludes:
154+
http_archive(
155+
name = "io_abseil_py",
156+
strip_prefix = "abseil-py-pypi-v0.9.0",
157+
sha256 = "603febc9b95a8f2979a7bdb77d2f5e4d9b30d4e0d59579f88eba67d4e4cc5462",
158+
urls = ["https://github.com/abseil/abseil-py/archive/pypi-v0.9.0.tar.gz"],
159+
)
160+
161+
# Abseil dependency https://github.com/abseil/abseil-py/blob/f24641ca72815e2643659cb7c8a966e5faa6e580/WORKSPACE#L18
162+
if "six_archive" not in excludes:
163+
http_archive(
164+
name = "six_archive",
165+
urls = [
166+
"http://mirror.bazel.build/pypi.python.org/packages/source/s/six/six-1.10.0.tar.gz",
167+
"https://pypi.python.org/packages/source/s/six/six-1.10.0.tar.gz",
168+
],
169+
sha256 = "105f8d68616f8248e24bf0e9372ef04d3cc10104f1980f54d57b2ce73a5ad56a",
170+
strip_prefix = "six-1.10.0",
171+
build_file_content = """# Description:
172+
# Six provides simple utilities for wrapping over differences between Python 2
173+
# and Python 3.
174+
175+
licenses(["notice"]) # MIT
176+
177+
exports_files(["LICENSE"])
178+
179+
py_library(
180+
name = "six",
181+
srcs = ["six.py"],
182+
srcs_version = "PY2AND3",
183+
visibility = ["//visibility:public"],
184+
)
185+
""",
186+
)
187+
153188
native.register_toolchains(
154189
# Register the default docker toolchain that expects the 'docker'
155190
# executable to be in the PATH

0 commit comments

Comments
 (0)