-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Codify how to remove TreeArtifact base directories in
pkg_files
(#330)
We often have TreeArtifacts (directory artifacts) that are built to be installed directly onto the filesystem in packages, but they sometimes need to be renamed. As of #319, there are two ways to accomplish this: 1) Rename the TreeArtifact to the destination 2) Rename the TreeArtifact to nothing I believe that (2) is clearer, as the `prefix` provided to `pkg_files` stands out more than an entry in `renames`. This change codifies a workaround we have tried out internally -- renaming to "nothing". While "nothing" itself could be a bit misleading, we can instead represent the desire for this via the constant `REMOVE_BASE_DIRECTORY`, represented as a non-printable string. (1) is still allowed. This change does not attempt to do anything related to updating paths inside TreeArtifacts. This will be attempted in a follow-on change. Tests and documentation updates are also provided. This change also moves the common analysis test boilerplate to its own location in `pkg/tests/util/defs.bzl`, where it will be more generally accessible in future changes. Partially resolves #269.
- Loading branch information
Andrew Psaltis
committed
Apr 27, 2021
1 parent
06a2a23
commit 7605368
Showing
9 changed files
with
241 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
pkg/experimental/tests/rpm/tree_artifacts/rpm_treeartifact_ops_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright 2021 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import unittest | ||
import csv | ||
import io | ||
import os | ||
import rpm_util | ||
from rules_python.python.runfiles import runfiles | ||
|
||
EXPECTED_RPM_MANIFEST_CSV = """ | ||
path,digest,user,group,mode,fflags,symlink | ||
/a,dc35e5df50b75e25610e1aaaa29edaa4,root,root,100644,, | ||
/b,dc35e5df50b75e25610e1aaaa29edaa4,root,root,100644,, | ||
/subdir/c,dc35e5df50b75e25610e1aaaa29edaa4,root,root,100644,, | ||
/subdir/d,dc35e5df50b75e25610e1aaaa29edaa4,root,root,100644,, | ||
""".strip() | ||
|
||
|
||
class PkgRpmCompManifest(unittest.TestCase): | ||
def setUp(self): | ||
self.runfiles = runfiles.Create() | ||
self.maxDiff = None | ||
# Allow for parameterization of this test based on the desired RPM to | ||
# test. | ||
self.rpm_path = self.runfiles.Rlocation(os.path.join( | ||
os.environ["TEST_WORKSPACE"], | ||
"experimental", "tests", "rpm", "tree_artifacts", | ||
# The object behind os.environ is not a dict, and thus doesn't have | ||
# the "getdefault()" we'd otherwise use here. | ||
os.environ["TEST_RPM"] if "TEST_RPM" in os.environ else "treeartifact_ops_rpm.rpm", | ||
)) | ||
|
||
def test_contents_match(self): | ||
sio = io.StringIO(EXPECTED_RPM_MANIFEST_CSV) | ||
manifest_reader = csv.DictReader(sio) | ||
manifest_specs = {r['path']: r for r in manifest_reader} | ||
|
||
rpm_specs = rpm_util.read_rpm_filedata(self.rpm_path) | ||
|
||
self.assertDictEqual(manifest_specs, rpm_specs) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.