aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Roos <roosa@google.com>2024-05-17 12:06:43 +0200
committerAdrian Roos <roosa@google.com>2024-06-04 12:04:45 +0000
commit669d9839bcc5dcaffad72ccab65d0f2844661a9f (patch)
tree42347a4a03e3e687ab0af388c1de8071036fb739
parente106ee3301113116bdc4e11cdb9af60ea946d12b (diff)
downloadrepohooks-669d9839bcc5dcaffad72ccab65d0f2844661a9f.tar.gz
repohooks: pass through REPO_PROJECT
Bug: 340801952 Test: python rh/hooks_unittest.py Change-Id: I483aaf4b8458b915089cd436b3b5ef1edb30e448
-rw-r--r--README.md3
-rw-r--r--rh/hooks.py5
-rwxr-xr-xrh/hooks_unittest.py7
3 files changed, 15 insertions, 0 deletions
diff --git a/README.md b/README.md
index 5b8ffce..3741fd9 100644
--- a/README.md
+++ b/README.md
@@ -114,6 +114,9 @@ Some variables are available to make it easier to handle OS differences. These
are automatically expanded for you:
* `${REPO_PATH}`: The path to the project relative to the root.
+ e.g. `tools/repohooks`
+* `${REPO_PROJECT}`: The name of the project.
+ e.g. `platform/tools/repohooks`
* `${REPO_ROOT}`: The absolute path of the root of the repo checkout. If the
project is in a submanifest, this points to the root of the submanifest.
* `${REPO_OUTER_ROOT}`: The absolute path of the root of the repo checkout.
diff --git a/rh/hooks.py b/rh/hooks.py
index 6cb92a0..c798298 100644
--- a/rh/hooks.py
+++ b/rh/hooks.py
@@ -134,6 +134,11 @@ class Placeholders(object):
return os.environ.get('REPO_PATH', '')
@property
+ def var_REPO_PROJECT(self):
+ """The name of the project"""
+ return os.environ.get('REPO_PROJECT', '')
+
+ @property
def var_REPO_ROOT(self):
"""The root of the repo (sub-manifest) checkout."""
return rh.git.find_repo_root()
diff --git a/rh/hooks_unittest.py b/rh/hooks_unittest.py
index 003057e..c261967 100755
--- a/rh/hooks_unittest.py
+++ b/rh/hooks_unittest.py
@@ -197,6 +197,13 @@ class PlaceholderTests(unittest.TestCase):
os.environ['REPO_PATH'] = 'foo/bar'
self.assertEqual(self.replacer.get('REPO_PATH'), 'foo/bar')
+ def testREPO_PROJECT(self):
+ """Verify handling of REPO_PROJECT."""
+ os.environ['REPO_PROJECT'] = ''
+ self.assertEqual(self.replacer.get('REPO_PROJECT'), '')
+ os.environ['REPO_PROJECT'] = 'platform/foo/bar'
+ self.assertEqual(self.replacer.get('REPO_PROJECT'), 'platform/foo/bar')
+
@mock.patch.object(rh.hooks, '_get_build_os_name', return_value='vapier os')
def testBUILD_OS(self, m):
"""Verify handling of BUILD_OS."""