import-orig: expose unpacked sources dir to the postunpack hook
authorMarco Trevisan (Treviño) <mail@3v1n0.net>
Thu, 5 Mar 2020 15:04:49 +0000 (16:04 +0100)
committerGuido Günther <agx@sigxcpu.org>
Tue, 25 Aug 2020 16:19:45 +0000 (18:19 +0200)
Use an $GBP_SOURCES_DIR to expose the post-unpack sources dir to the hook.
Include a test that checks that all the expected env variables are set.

docs/manpages/gbp-import-orig.xml
gbp/scripts/import_orig.py
tests/component/deb/test_import_orig.py

index 79274d32379c4fcf3227f35601d96f54e395dd20..7581da6688666f73fe3a9d51e6934eae2cb86e05 100644 (file)
                The temporary directory the tarballs are unapcked into.
              </para></listitem>
            </varlistentry>
+           <varlistentry>
+             <term><envar>GBP_SOURCES_DIR</envar></term>
+             <listitem><para>
+               The temporary directory where the unpacked sources are.
+             </para></listitem>
+           </varlistentry>
            <varlistentry>
              <term><envar>GBP_GIT_DIR</envar></term>
              <listitem><para>
index 3a0d2d97fc696d7f3fb8a894ca0046a7fbe66fad..2947235a020ab3e1b6ef954ea3b5eacf42920dd9 100644 (file)
@@ -227,11 +227,12 @@ def postimport_hook(repo, tag, version, options):
              extra_env=env)()
 
 
-def postunpack_hook(repo, tmp_dir, options):
+def postunpack_hook(repo, tmp_dir, sources, options):
     if options.postunpack:
         Hook('Postunpack', options.postunpack,
              extra_env={'GBP_GIT_DIR': repo.git_dir,
-                        'GBP_TMP_DIR': tmp_dir}
+                        'GBP_TMP_DIR': tmp_dir,
+                        'GBP_SOURCES_DIR': sources[0].unpacked}
              )(dir=tmp_dir)
 
 
@@ -474,7 +475,7 @@ def main(argv):
 
         sources, tmpdir = unpack_tarballs(name, sources, version, options)
         try:
-            postunpack_hook(repo, tmpdir, options)
+            postunpack_hook(repo, tmpdir, sources, options)
         except gbpc.CommandExecFailed:
             raise GbpError()  # The hook already printed an error message
 
index b95b874dd78055807c669b13ddfe2ec9597103dc..ef75919e2f57b1ccbbb2d00098a66148943f955e 100644 (file)
@@ -401,3 +401,18 @@ class TestImportOrig(ComponentTestBase):
                                                ("GBP_TAG", "upstream/2.8"),
                                                ("GBP_UPSTREAM_VERSION", "2.8"),
                                                ("GBP_DEBIAN_VERSION", "2.8-1")])
+
+    def test_postunpack_env_vars(self):
+        """
+        Test that the expected environment variables are set during
+        postunpack hook.
+        """
+        repo = ComponentTestGitRepository.create(self.pkg)
+        os.chdir(self.pkg)
+        orig = self._orig('2.8')
+        ok_(import_orig(['arg0',
+                         '--postunpack=printenv > ../postunpack.out',
+                         '--no-interactive', '--pristine-tar', orig]) == 0)
+        self.check_hook_vars('../postunpack', ["GBP_GIT_DIR",
+                                               "GBP_TMP_DIR",
+                                               "GBP_SOURCES_DIR"])