Skip to content

Commit 01c66c9

Browse files
committed
Merge branch 'main' into fix-install-stanza
2 parents 004e3ae + de6159d commit 01c66c9

File tree

30 files changed

+623
-236
lines changed

30 files changed

+623
-236
lines changed

.bazelci/tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ default_tests_with_rpm: &default_tests_with_rpm
3333
- "//toolchains/..."
3434

3535
win_tests: &win_tests
36+
test_flags:
37+
- "--test_tag_filters=-nowindows"
38+
build_flags:
39+
- "--build_tag_filters=-nowindows"
3640
test_targets:
3741
- "//pkg/..."
3842
- "//tests/..."

distro/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ py_test(
8484
"packaging_test.py",
8585
":release_version.py",
8686
],
87+
imports = [".."],
8788
data = [
8889
"testdata/BUILD.tpl",
8990
":distro",

docs/latest.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ Rules for making .tar files.
259259
## pkg_tar
260260

261261
<pre>
262-
pkg_tar(<a href="#pkg_tar-name">name</a>, <a href="#pkg_tar-build_tar">build_tar</a>, <a href="#pkg_tar-compressor">compressor</a>, <a href="#pkg_tar-compressor_args">compressor_args</a>, <a href="#pkg_tar-deps">deps</a>, <a href="#pkg_tar-empty_dirs">empty_dirs</a>, <a href="#pkg_tar-empty_files">empty_files</a>, <a href="#pkg_tar-extension">extension</a>,
263-
<a href="#pkg_tar-files">files</a>, <a href="#pkg_tar-include_runfiles">include_runfiles</a>, <a href="#pkg_tar-mode">mode</a>, <a href="#pkg_tar-modes">modes</a>, <a href="#pkg_tar-mtime">mtime</a>, <a href="#pkg_tar-out">out</a>, <a href="#pkg_tar-owner">owner</a>, <a href="#pkg_tar-ownername">ownername</a>, <a href="#pkg_tar-ownernames">ownernames</a>, <a href="#pkg_tar-owners">owners</a>,
262+
pkg_tar(<a href="#pkg_tar-name">name</a>, <a href="#pkg_tar-compressor">compressor</a>, <a href="#pkg_tar-compressor_args">compressor_args</a>, <a href="#pkg_tar-deps">deps</a>, <a href="#pkg_tar-empty_dirs">empty_dirs</a>, <a href="#pkg_tar-empty_files">empty_files</a>, <a href="#pkg_tar-extension">extension</a>, <a href="#pkg_tar-files">files</a>,
263+
<a href="#pkg_tar-include_runfiles">include_runfiles</a>, <a href="#pkg_tar-mode">mode</a>, <a href="#pkg_tar-modes">modes</a>, <a href="#pkg_tar-mtime">mtime</a>, <a href="#pkg_tar-out">out</a>, <a href="#pkg_tar-owner">owner</a>, <a href="#pkg_tar-ownername">ownername</a>, <a href="#pkg_tar-ownernames">ownernames</a>, <a href="#pkg_tar-owners">owners</a>,
264264
<a href="#pkg_tar-package_dir">package_dir</a>, <a href="#pkg_tar-package_dir_file">package_dir_file</a>, <a href="#pkg_tar-package_file_name">package_file_name</a>, <a href="#pkg_tar-package_variables">package_variables</a>, <a href="#pkg_tar-portable_mtime">portable_mtime</a>,
265265
<a href="#pkg_tar-private_stamp_detect">private_stamp_detect</a>, <a href="#pkg_tar-remap_paths">remap_paths</a>, <a href="#pkg_tar-srcs">srcs</a>, <a href="#pkg_tar-stamp">stamp</a>, <a href="#pkg_tar-strip_prefix">strip_prefix</a>, <a href="#pkg_tar-symlinks">symlinks</a>)
266266
</pre>
@@ -273,31 +273,30 @@ pkg_tar(<a href="#pkg_tar-name">name</a>, <a href="#pkg_tar-build_tar">build_tar
273273
| Name | Description | Type | Mandatory | Default |
274274
| :------------- | :------------- | :------------- | :------------- | :------------- |
275275
| <a id="pkg_tar-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
276-
| <a id="pkg_tar-build_tar"></a>build_tar | - | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | //pkg/private/tar:build_tar |
277-
| <a id="pkg_tar-compressor"></a>compressor | - | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
278-
| <a id="pkg_tar-compressor_args"></a>compressor_args | - | String | optional | "" |
279-
| <a id="pkg_tar-deps"></a>deps | - | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
276+
| <a id="pkg_tar-compressor"></a>compressor | External tool which can compress the archive. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
277+
| <a id="pkg_tar-compressor_args"></a>compressor_args | Arg list for <code>compressor</code>. | String | optional | "" |
278+
| <a id="pkg_tar-deps"></a>deps | tar files which will be unpacked and repacked into the archive. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
280279
| <a id="pkg_tar-empty_dirs"></a>empty_dirs | - | List of strings | optional | [] |
281280
| <a id="pkg_tar-empty_files"></a>empty_files | - | List of strings | optional | [] |
282281
| <a id="pkg_tar-extension"></a>extension | - | String | optional | "tar" |
283-
| <a id="pkg_tar-files"></a>files | - | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: Label -> String</a> | optional | {} |
282+
| <a id="pkg_tar-files"></a>files | Obsolete. Do not use. | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: Label -> String</a> | optional | {} |
284283
| <a id="pkg_tar-include_runfiles"></a>include_runfiles | - | Boolean | optional | False |
285284
| <a id="pkg_tar-mode"></a>mode | - | String | optional | "0555" |
286285
| <a id="pkg_tar-modes"></a>modes | - | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
287286
| <a id="pkg_tar-mtime"></a>mtime | - | Integer | optional | -1 |
288287
| <a id="pkg_tar-out"></a>out | - | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
289-
| <a id="pkg_tar-owner"></a>owner | - | String | optional | "0.0" |
288+
| <a id="pkg_tar-owner"></a>owner | Default numeric owner.group to apply to files when not set via pkg_attribures. | String | optional | "0.0" |
290289
| <a id="pkg_tar-ownername"></a>ownername | - | String | optional | "." |
291290
| <a id="pkg_tar-ownernames"></a>ownernames | - | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
292291
| <a id="pkg_tar-owners"></a>owners | - | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
293-
| <a id="pkg_tar-package_dir"></a>package_dir | Prefix to be prepend to all paths written. The name may contain variables, same as [package_file_name](#package_file_name) | String | optional | "" |
292+
| <a id="pkg_tar-package_dir"></a>package_dir | Prefix to be prepend to all paths written.<br><br> This is applied as a final step, while writing to the archive. Any other attributes (e.g. symlinks) which specify a path, must do so relative to package_dir. The value may contain variables. See [package_file_name](#package_file_name) for examples. | String | optional | "" |
294293
| <a id="pkg_tar-package_dir_file"></a>package_dir_file | - | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
295294
| <a id="pkg_tar-package_file_name"></a>package_file_name | See [Common Attributes](#package_file_name) | String | optional | "" |
296295
| <a id="pkg_tar-package_variables"></a>package_variables | See [Common Attributes](#package_variables) | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
297296
| <a id="pkg_tar-portable_mtime"></a>portable_mtime | - | Boolean | optional | True |
298297
| <a id="pkg_tar-private_stamp_detect"></a>private_stamp_detect | - | Boolean | optional | False |
299298
| <a id="pkg_tar-remap_paths"></a>remap_paths | - | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
300-
| <a id="pkg_tar-srcs"></a>srcs | - | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
299+
| <a id="pkg_tar-srcs"></a>srcs | Inputs which will become part of the tar archive. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
301300
| <a id="pkg_tar-stamp"></a>stamp | Enable file time stamping. Possible values: <li>stamp = 1: Use the time of the build as the modification time of each file in the archive. <li>stamp = 0: Use an "epoch" time for the modification time of each file. This gives good build result caching. <li>stamp = -1: Control the chosen modification time using the --[no]stamp flag. <div class="since"><i>Since 0.5.0</i></div> | Integer | optional | 0 |
302301
| <a id="pkg_tar-strip_prefix"></a>strip_prefix | (note: Use strip_prefix = "." to strip path to the package but preserve relative paths of sub directories beneath the package.) | String | optional | "" |
303302
| <a id="pkg_tar-symlinks"></a>symlinks | - | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
@@ -583,6 +582,9 @@ pkg_mklink(<a href="#pkg_mklink-name">name</a>, <a href="#pkg_mklink-link_name">
583582

584583
Create a symlink.
585584

585+
Wraps [pkg_mklink_impl](#pkg_mklink_impl)
586+
587+
586588
**PARAMETERS**
587589

588590

pkg/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ starlark_library(
6868
py_binary(
6969
name = "make_rpm",
7070
srcs = ["make_rpm.py"],
71+
imports = [".."],
7172
python_version = "PY3",
7273
srcs_version = "PY3",
7374
target_compatible_with = select({
@@ -84,6 +85,7 @@ py_binary(
8485
py_library(
8586
name = "make_rpm_lib",
8687
srcs = ["make_rpm.py"],
88+
imports = [".."],
8789
srcs_version = "PY3",
8890
visibility = [
8991
"//experimental:__subpackages__",

pkg/make_rpm.py

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ def Tempdir():
7070
dirpath = tempfile.mkdtemp()
7171

7272
def Cleanup():
73-
shutil.rmtree(dirpath)
73+
# shutil.rmtree(dirpath)
74+
pass
7475

7576
with Cd(dirpath, Cleanup):
7677
yield dirpath
@@ -81,10 +82,9 @@ def Cleanup():
8182

8283
def FindOutputFile(log):
8384
"""Find the written file from the log information."""
84-
85-
m = WROTE_FILE_RE.search(log)
85+
m = WROTE_FILE_RE.findall(log)
8686
if m:
87-
return m.group('rpm_path')
87+
return m
8888
return None
8989

9090
def SlurpFile(input_path):
@@ -187,7 +187,7 @@ def __init__(self, name, version, release, arch, rpmbuild_path,
187187
self.arch = arch
188188
self.files = []
189189
self.rpmbuild_path = FindRpmbuild(rpmbuild_path)
190-
self.rpm_path = None
190+
self.rpm_paths = None
191191
self.source_date_epoch = helpers.GetFlagValue(source_date_epoch)
192192
self.debug = debug
193193

@@ -204,6 +204,7 @@ def __init__(self, name, version, release, arch, rpmbuild_path,
204204
self.post_scriptlet = None
205205
self.preun_scriptlet = None
206206
self.postun_scriptlet = None
207+
self.subpackages = None
207208

208209
def AddFiles(self, paths, root=''):
209210
"""Add a set of files to the current RPM.
@@ -227,6 +228,7 @@ def SetupWorkdir(self,
227228
preamble_file=None,
228229
description_file=None,
229230
install_script_file=None,
231+
subpackages_file=None,
230232
pre_scriptlet_path=None,
231233
post_scriptlet_path=None,
232234
preun_scriptlet_path=None,
@@ -240,6 +242,10 @@ def SetupWorkdir(self,
240242
if not os.path.exists(name):
241243
os.makedirs(name, 0o777)
242244

245+
# create the bld directory structure
246+
package_bld_dir = "bld-%s/%s" % ( self.arch, self.name )
247+
os.makedirs(package_bld_dir, 0o777)
248+
243249
# Copy the to-be-packaged files into the BUILD directory
244250
for f in self.files:
245251
dst_dir = os.path.join(RpmBuilder.BUILD_DIR, os.path.dirname(f))
@@ -264,14 +270,17 @@ def SetupWorkdir(self,
264270
SlurpFile(os.path.join(original_dir, preun_scriptlet_path)) if preun_scriptlet_path is not None else ''
265271
self.postun_scriptlet = \
266272
SlurpFile(os.path.join(original_dir, postun_scriptlet_path)) if postun_scriptlet_path is not None else ''
273+
self.subpackages = \
274+
SlurpFile(os.path.join(original_dir, subpackages_file)) if subpackages_file is not None else ''
267275

268276
# Then prepare for textual substitution. This is typically only the case for the
269277
# experimental `pkg_rpm`.
270278
tpl_replacements = {
271-
'PRE_SCRIPTLET': "%pre\n" + self.pre_scriptlet,
272-
'POST_SCRIPTLET': "%post\n" + self.post_scriptlet,
273-
'PREUN_SCRIPTLET': "%preun\n" + self.preun_scriptlet,
274-
'POSTUN_SCRIPTLET': "%postun\n" + self.postun_scriptlet,
279+
'PRE_SCRIPTLET': ("%pre\n" + self.pre_scriptlet) if self.pre_scriptlet else "",
280+
'POST_SCRIPTLET': ("%post\n" + self.post_scriptlet) if self.post_scriptlet else "",
281+
'PREUN_SCRIPTLET': ("%preun\n" + self.preun_scriptlet) if self.preun_scriptlet else "",
282+
'POSTUN_SCRIPTLET': ("%postun\n" + self.postun_scriptlet) if self.postun_scriptlet else "",
283+
'SUBPACKAGES' : (self.subpackages if self.subpackages else ""),
275284
'CHANGELOG': ""
276285
}
277286

@@ -334,8 +343,8 @@ def SetupWorkdir(self,
334343

335344
# Used in %files -f
336345
if file_list_path:
337-
shutil.copy(os.path.join(original_dir, file_list_path), RpmBuilder.BUILD_DIR)
338-
self.file_list_path = os.path.join(RpmBuilder.BUILD_DIR, os.path.basename(file_list_path))
346+
shutil.copy(os.path.join(original_dir, file_list_path), package_bld_dir)
347+
self.file_list_path = os.path.join(package_bld_dir, os.path.basename(file_list_path))
339348

340349
def CallRpmBuild(self, dirname, rpmbuild_args):
341350
"""Call rpmbuild with the correct arguments."""
@@ -391,6 +400,7 @@ def CallRpmBuild(self, dirname, rpmbuild_args):
391400
print('With environment:')
392401
pprint.pprint(env)
393402

403+
args += [ '--verbose' ]
394404
p = subprocess.Popen(
395405
args,
396406
stdout=subprocess.PIPE,
@@ -400,9 +410,9 @@ def CallRpmBuild(self, dirname, rpmbuild_args):
400410

401411
if p.returncode == 0:
402412
# Find the created file.
403-
self.rpm_path = FindOutputFile(output)
413+
self.rpm_paths = FindOutputFile(output)
404414

405-
if p.returncode != 0 or not self.rpm_path:
415+
if p.returncode != 0 or not self.rpm_paths:
406416
print('Error calling rpmbuild:')
407417
print(output)
408418
elif self.debug:
@@ -411,20 +421,33 @@ def CallRpmBuild(self, dirname, rpmbuild_args):
411421
# Return the status.
412422
return p.returncode
413423

414-
def SaveResult(self, out_file):
424+
def SaveResult(self, out_file, subpackage_out_files):
415425
"""Save the result RPM out of the temporary working directory."""
416426

417-
if self.rpm_path:
418-
shutil.copy(self.rpm_path, out_file)
427+
if self.rpm_paths:
428+
rpm_path = self.rpm_paths[0]
429+
shutil.copy(rpm_path, out_file)
419430
if self.debug:
420431
print('Saved RPM file to %s' % out_file)
432+
433+
subrpm_paths = self.rpm_paths[1:]
434+
for s_name, s_out_file in subpackage_out_files:
435+
s_prefix = self.name + '-' + s_name
436+
437+
for p in subrpm_paths:
438+
if os.path.basename(p).startswith(s_prefix):
439+
shutil.copy(p, s_out_file)
440+
if self.debug:
441+
print('Saved %s sub RPM file to %s' % (s_name, s_out_file))
442+
break
421443
else:
422444
print('No RPM file created.')
423445

424-
def Build(self, spec_file, out_file,
446+
def Build(self, spec_file, out_file, subpackage_out_files,
425447
preamble_file=None,
426448
description_file=None,
427449
install_script_file=None,
450+
subpackages_file=None,
428451
pre_scriptlet_path=None,
429452
post_scriptlet_path=None,
430453
preun_scriptlet_path=None,
@@ -440,20 +463,24 @@ def Build(self, spec_file, out_file,
440463
original_dir = os.getcwd()
441464
spec_file = os.path.join(original_dir, spec_file)
442465
out_file = os.path.join(original_dir, out_file)
466+
subpackage_out_files = (s.split(':') for s in subpackage_out_files)
467+
subpackage_out_files = [
468+
(s[0], os.path.join(original_dir, s[1])) for s in subpackage_out_files]
443469
with Tempdir() as dirname:
444470
self.SetupWorkdir(spec_file,
445471
original_dir,
446472
preamble_file=preamble_file,
447473
description_file=description_file,
448474
install_script_file=install_script_file,
475+
subpackages_file=subpackages_file,
449476
file_list_path=file_list_path,
450477
pre_scriptlet_path=pre_scriptlet_path,
451478
post_scriptlet_path=post_scriptlet_path,
452479
preun_scriptlet_path=preun_scriptlet_path,
453480
postun_scriptlet_path=postun_scriptlet_path,
454481
changelog_file=changelog_file)
455482
status = self.CallRpmBuild(dirname, rpmbuild_args or [])
456-
self.SaveResult(out_file)
483+
self.SaveResult(out_file, subpackage_out_files)
457484

458485
return status
459486

@@ -476,6 +503,9 @@ def main(argv):
476503
help='The file containing the RPM specification.')
477504
parser.add_argument('--out_file', required=True,
478505
help='The destination to save the resulting RPM file to.')
506+
parser.add_argument('--subpackage_out_file', action='append',
507+
help='List of destinations to save resulting ' +
508+
'subpackage RPMs to in the form of name:destination')
479509
parser.add_argument('--rpmbuild', help='Path to rpmbuild executable.')
480510
parser.add_argument('--source_date_epoch',
481511
help='Value for the SOURCE_DATE_EPOCH rpmbuild '
@@ -492,6 +522,8 @@ def main(argv):
492522
help='File containing the RPM Preamble')
493523
parser.add_argument('--description',
494524
help='File containing the RPM %description text')
525+
parser.add_argument('--subpackages',
526+
help='File containing the RPM subpackage details')
495527
parser.add_argument('--pre_scriptlet',
496528
help='File containing the RPM %pre scriptlet, if to be substituted')
497529
parser.add_argument('--post_scriptlet',
@@ -510,16 +542,23 @@ def main(argv):
510542
options = parser.parse_args(argv or ())
511543

512544
try:
545+
arch = options.arch
546+
if not arch:
547+
import platform
548+
arch = platform.machine()
549+
513550
builder = RpmBuilder(options.name,
514551
options.version, options.release,
515552
options.arch, options.rpmbuild,
516553
source_date_epoch=options.source_date_epoch,
517554
debug=options.debug)
518555
builder.AddFiles(options.files)
519556
return builder.Build(options.spec_file, options.out_file,
557+
options.subpackage_out_file,
520558
preamble_file=options.preamble,
521559
description_file=options.description,
522560
install_script_file=options.install_script,
561+
subpackages_file=options.subpackages,
523562
file_list_path=options.file_list,
524563
pre_scriptlet_path=options.pre_scriptlet,
525564
post_scriptlet_path=options.post_scriptlet,

pkg/private/BUILD

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ py_library(
6565
srcs = [
6666
"build_info.py",
6767
],
68+
imports = ["../.."],
6869
srcs_version = "PY3",
6970
visibility = [
7071
"//:__subpackages__",
@@ -78,6 +79,7 @@ py_library(
7879
"__init__.py",
7980
"archive.py",
8081
],
82+
imports = ["../.."],
8183
srcs_version = "PY3",
8284
visibility = [
8385
"//:__subpackages__",
@@ -91,6 +93,7 @@ py_library(
9193
"__init__.py",
9294
"helpers.py",
9395
],
96+
imports = ["../.."],
9497
srcs_version = "PY3",
9598
visibility = [
9699
"//:__subpackages__",
@@ -101,6 +104,7 @@ py_library(
101104
py_library(
102105
name = "manifest",
103106
srcs = ["manifest.py"],
107+
imports = ["../.."],
104108
srcs_version = "PY3",
105109
visibility = ["//visibility:public"],
106110
)

pkg/private/deb/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ exports_files(
4848
py_binary(
4949
name = "make_deb",
5050
srcs = ["make_deb.py"],
51+
imports = ["../../.."],
5152
python_version = "PY3",
5253
visibility = ["//visibility:public"],
5354
deps = [
@@ -58,6 +59,7 @@ py_binary(
5859
py_library(
5960
name = "make_deb_lib",
6061
srcs = ["make_deb.py"],
62+
imports = ["../../.."],
6163
srcs_version = "PY3",
6264
visibility = ["//tests/deb:__pkg__"],
6365
deps = [

pkg/private/deb/deb.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
load("//pkg:providers.bzl", "PackageVariablesInfo")
1717
load("//pkg/private:util.bzl", "setup_output_files")
1818

19-
_tar_filetype = [".tar", ".tar.gz", ".tgz", ".tar.bz2", "tar.xz"]
19+
_tar_filetype = [".tar", ".tar.gz", ".tgz", ".tar.bz2", "tar.xz", "tar.zst"]
2020

2121
def _pkg_deb_impl(ctx):
2222
"""The implementation for the pkg_deb rule."""

pkg/private/deb/make_deb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def CreateDeb(output,
237237
ext = 'tar.bz2'
238238
else:
239239
ext = '.'.join(ext)
240-
if ext not in ['tar.bz2', 'tar.gz', 'tar.xz', 'tar.lzma']:
240+
if ext not in ['tar.bz2', 'tar.gz', 'tar.xz', 'tar.lzma', 'tar.zst']:
241241
ext = 'tar'
242242
data_size = os.stat(data).st_size
243243
with open(data, 'rb') as datafile:

0 commit comments

Comments
 (0)