Browse Source

Fix get_package.py usage outside of git repos

Fixes #503
Eloston 5 years ago
parent
commit
3e990cf67d

+ 10 - 3
get_package.py

@@ -74,14 +74,21 @@ def _process_templates(template_files, build_file_subs):
             new_file.truncate()
 
 
-def _get_current_commit():
+def _get_current_commit_or_tag():
     """
-    Returns a string of the current commit hash.
+    Returns a string of the current commit hash, or the tag name based
+    on version.ini if the script is not in a git repo.
 
     It assumes "git" is in PATH, and that buildkit is run within a git repository.
 
     Raises BuildkitAbort if invoking git fails.
     """
+    # Use presence of .git directory to determine if using git or not
+    # since git will be aggressive in finding a git repository otherwise
+    if not (Path(__file__).parent / '.git').exists(): #pylint: disable=no-member
+        # Probably not in a git checkout; extrapolate tag name based on
+        # version.ini
+        return '{}-{}'.format(get_chromium_version(), get_release_revision())
     result = subprocess.run(['git', 'rev-parse', '--verify', 'HEAD'],
                             stdout=subprocess.PIPE,
                             universal_newlines=True,
@@ -207,7 +214,7 @@ def main():
     packaging_subs = dict(
         chromium_version=get_chromium_version(),
         release_revision=get_release_revision(),
-        current_commit=_get_current_commit(),
+        current_commit_or_tag=_get_current_commit_or_tag(),
     )
     _process_templates(template_files, packaging_subs)
 

+ 5 - 5
packaging/archlinux/PKGBUILD.ungoogin

@@ -30,7 +30,7 @@ provides=('chromium')
 conflicts=('chromium')
 source=(https://commondatastorage.googleapis.com/chromium-browser-official/chromium-$pkgver.tar.xz
         chromium-launcher-$_launcher_ver.tar.gz::https://github.com/foutrelis/chromium-launcher/archive/v$_launcher_ver.tar.gz
-        'https://github.com/Eloston/ungoogled-chromium/archive/$ungoog{current_commit}.tar.gz')
+        'https://github.com/Eloston/ungoogled-chromium/archive/$ungoog{current_commit_or_tag}.tar.gz')
 sha256sums=($(curl -sL https://commondatastorage.googleapis.com/chromium-browser-official/chromium-${pkgver}.tar.xz.hashes | grep sha256 | cut -d ' ' -f3)
             '04917e3cd4307d8e31bfb0027a5dce6d086edb10ff8a716024fbb8bb0c7dccf1'
             'SKIP')
@@ -65,8 +65,8 @@ _unwanted_bundled_libs=(
 depends+=(${_system_libs[@]})
 
 prepare() {
-  local _buildkit_cli="$srcdir/$pkgname-$ungoog{current_commit}/run_buildkit_cli.py"
-  local _config_bundle="$srcdir/$pkgname-$ungoog{current_commit}/config_bundles/archlinux"
+  local _buildkit_cli="$srcdir/$pkgname-$ungoog{current_commit_or_tag}/run_buildkit_cli.py"
+  local _config_bundle="$srcdir/$pkgname-$ungoog{current_commit_or_tag}/config_bundles/archlinux"
 
   cd "$srcdir/chromium-$pkgver"
 
@@ -117,8 +117,8 @@ build() {
 
   mkdir -p out/Default
 
-  local _buildkit_cli="$srcdir/$pkgname-$ungoog{current_commit}/run_buildkit_cli.py"
-  local _config_bundle="$srcdir/$pkgname-$ungoog{current_commit}/config_bundles/archlinux"
+  local _buildkit_cli="$srcdir/$pkgname-$ungoog{current_commit_or_tag}/run_buildkit_cli.py"
+  local _config_bundle="$srcdir/$pkgname-$ungoog{current_commit_or_tag}/config_bundles/archlinux"
 
   python "$_buildkit_cli" gnargs print -b "$_config_bundle" \
     > "$srcdir/chromium-$pkgver/out/Default/args.gn"

+ 1 - 1
packaging/debian_buster/changelog.ungoogin

@@ -1,5 +1,5 @@
 ungoogled-chromium-browser ($ungoog{chromium_version}-$ungoog{release_revision}~buster) buster; urgency=medium
 
-  * Built against commit $ungoog{current_commit}
+  * Built against $ungoog{current_commit_or_tag}
 
  -- ungoogled-chromium Authors <maintainer@null>  Sun, 29 Jul 2018 00:00:00 +0000

+ 1 - 1
packaging/debian_minimal/changelog.ungoogin

@@ -1,5 +1,5 @@
 ungoogled-chromium-browser ($ungoog{chromium_version}-$ungoog{release_revision}~portable) stable; urgency=medium
 
-  * Built against commit $ungoog{current_commit}
+  * Built against $ungoog{current_commit_or_tag}
 
  -- ungoogled-chromium Authors <maintainer@null>  Sun, 29 Jul 2018 00:00:00 +0000

+ 1 - 1
packaging/debian_stretch/changelog.ungoogin

@@ -1,5 +1,5 @@
 ungoogled-chromium-browser ($ungoog{chromium_version}-$ungoog{release_revision}~stretch) stretch; urgency=medium
 
-  * Built against commit $ungoog{current_commit}
+  * Built against $ungoog{current_commit_or_tag}
 
  -- ungoogled-chromium Authors <maintainer@null>  Sun, 29 Jul 2018 00:00:00 +0000

+ 1 - 1
packaging/ubuntu_bionic/changelog.ungoogin

@@ -1,5 +1,5 @@
 ungoogled-chromium-browser ($ungoog{chromium_version}-$ungoog{release_revision}~bionic) bionic; urgency=medium
 
-  * Built against commit $ungoog{current_commit}
+  * Built against $ungoog{current_commit_or_tag}
 
  -- ungoogled-chromium Authors <maintainer@null>  Sun, 29 Jul 2018 00:00:00 +0000