Browse Source

Add run_buildkit_cli.py

This is a CWD-independent Python script to launch buildkit to workaround
the clunkiness of Python's import system for this particular use-case.
Eloston 5 years ago
parent
commit
ef7354d05a

+ 3 - 0
.cirrus.yml

@@ -15,6 +15,9 @@ code_check_task:
     get_package_script:
         - python3 -m yapf --style '.style.yapf' -pd get_package.py
         - ./devutils/pylint_devutils.py --hide-fixme get_package.py
+    run_buildkit_cli_script:
+        - python3 -m yapf --style '.style.yapf' -pd run_buildkit_cli.py
+        - ./devutils/pylint_devutils.py --hide-fixme run_buildkit_cli.py
 
 validate_config_task:
     validate_config_script: ./devutils/validate_config.py

+ 8 - 11
packaging/archlinux/PKGBUILD.ungoogin

@@ -66,17 +66,15 @@ depends+=(${_system_libs[@]})
 
 prepare() {
   local _tree="$srcdir/chromium-$pkgver"
-
-  cd "$srcdir/$pkgname-$ungoog{current_commit}"
+  local _buildkit_cli="$srcdir/$pkgname-$ungoog{current_commit}/run_buildkit_cli.py"
+  local _config_bundle="$srcdir/$pkgname-$ungoog{current_commit}/config_bundles/archlinux"
 
   msg2 'Pruning binaries'
-  python -m buildkit prune -b config_bundles/archlinux "$_tree"
+  python "$_buildkit_cli" prune -b "$_config_bundle" "$_tree"
   msg2 'Applying patches'
-  python -m buildkit patches apply -b config_bundles/archlinux "$_tree"
+  python "$_buildkit_cli" patches apply -b "$_config_bundle" "$_tree"
   msg2 'Applying domain substitution'
-  python -m buildkit domains apply -b config_bundles/archlinux -c domainsubcache.tar.gz "$_tree"
-
-  cd "$_tree"
+  python "$_buildkit_cli" domains apply -b "$_config_bundle" -c domainsubcache.tar.gz "$_tree"
 
   # Force script incompatible with Python 3 to use /usr/bin/python2
   sed -i '1s|python$|&2|' third_party/dom_distiller_js/protoc_plugins/*.py
@@ -118,13 +116,12 @@ build() {
 
   mkdir -p out/Default
 
-  cd "$srcdir/$pkgname-$ungoog{current_commit}"
+  local _buildkit_cli="$srcdir/$pkgname-$ungoog{current_commit}/run_buildkit_cli.py"
+  local _config_bundle="$srcdir/$pkgname-$ungoog{current_commit}/config_bundles/archlinux"
 
-  python -m buildkit gnargs print -b config_bundles/archlinux \
+  python "$_buildkit_cli" gnargs print -b "$_config_bundle" \
     > "$srcdir/chromium-$pkgver/out/Default/args.gn"
 
-  cd "$srcdir/chromium-$pkgver"
-
   # Facilitate deterministic builds (taken from build/config/compiler/BUILD.gn)
   CFLAGS+='   -Wno-builtin-macro-redefined'
   CXXFLAGS+=' -Wno-builtin-macro-redefined'

+ 12 - 10
packaging/debian_buster/rules

@@ -41,10 +41,10 @@ ifeq (armhf,$(DEB_HOST_ARCH))
 defines+=host_cpu=\"arm\" arm_use_neon=false
 endif
 
-config_bundle=$(shell cat debian/ungoogled-config-bundle)
+config_bundle=debian/scripts/ungoogled-chromium/config_bundles/$(shell cat debian/ungoogled-config-bundle)
 
 # add gn flags from config bundle
-defines+=$(shell debian/scripts/get-gnargs-shell debian/scripts/ungoogled-chromium/config_bundles/$(config_bundle))
+defines+=$(shell debian/scripts/get-gnargs-shell $(config_bundle))
 
 # some notes about embedded libraries
 #  can't use system nss since net/third_party/nss is heavily patched
@@ -60,6 +60,8 @@ endif
 flotpaths=/usr/share/javascript/jquery/*min.js \
           /usr/share/javascript/jquery-flot/*min.js \
 
+buildkit_cli=debian/scripts/ungoogled-chromium/run_buildkit_cli.py
+
 %:
 	dh $@
 
@@ -77,7 +79,7 @@ override_dh_auto_configure:
 	# strip out system third_party libraries
 	./debian/scripts/unbundle
 	# apply domain substitution
-	if [ ! -e debian/scripts/ungoogled-chromium/domsubcache.tar.gz ]; then cd debian/scripts/ungoogled-chromium; python3 -m buildkit domains apply -b config_bundles/$(config_bundle) -c domsubcache.tar.gz ../../../; fi
+	if [ ! -e debian/scripts/ungoogled-chromium/domsubcache.tar.gz ]; then python3 $(buildkit_cli) domains apply -b $(config_bundle) -c domsubcache.tar.gz ../../../; fi
 
 override_dh_auto_build-arch: out/Default/gn
 	./out/Default/gn gen out/Default --args="$(defines)" --fail-on-unused-args
@@ -89,7 +91,7 @@ override_dh_auto_build-indep: out/Default/gn
 
 override_dh_prep:
 	# building is done by this step; remove domain substitution
-	if [ -e debian/scripts/ungoogled-chromium/domsubcache.tar.gz ]; then cd debian/scripts/ungoogled-chromium; python3 -m buildkit domains revert -c domsubcache.tar.gz ../../../; fi
+	if [ -e debian/scripts/ungoogled-chromium/domsubcache.tar.gz ]; then python3 $(buildkit_cli) domains revert -c domsubcache.tar.gz ../../../; fi
 	dh_prep
 
 override_dh_auto_install-arch:
@@ -141,7 +143,7 @@ removed=$(debvers).files-removed
 seconds=$(debvers).seconds
 
 get-orig-source:
-	if [ ! -e debian/patches ]; then cd debian/scripts/ungoogled-chromium; python3 -m buildkit patches export -b config_bundles/$(config_bundle) ../../patches/; fi
+	if [ ! -e debian/patches ]; then python3 $(buildkit_cli) patches export -b $(config_bundle) ../../patches/; fi
 	wget -nv --show-progress -c $(url)/$(tarball) -O ../$(tarball)
 	cp /usr/bin/mk-origtargz debian/scripts
 	patch -p1 < debian/scripts/mk-origtargz.patch
@@ -150,7 +152,7 @@ get-orig-source:
 	echo $$(($$(date +%s) - $$(cat $(seconds)))) seconds
 	test ! -e $(extract) || rm -rf $(extract)
 	tar xf ../$(tarball)
-	cd debian/scripts/ungoogled-chromium; python3 -m buildkit prune -b config_bundles/$(config_bundle) ../../../$(extract)
+	python3 $(buildkit_cli) prune -b $(config_bundle) ../../../$(extract)
 	echo $$(($$(date +%s) - $$(cat $(seconds)))) seconds
 	while read line; do rm -rf $$line; done < $(removed)
 	cd $(extract) && ../debian/scripts/check-upstream
@@ -165,7 +167,7 @@ get-orig-source:
 
 setup-local-src:
 	mkdir ../download_cache || true
-	cd debian/scripts/ungoogled-chromium; python3 -m buildkit downloads retrieve -b config_bundles/$(config_bundle) -c ../../../../download_cache
-	cd debian/scripts/ungoogled-chromium; python3 -m buildkit downloads unpack -b config_bundles/$(config_bundle) -c ../../../../download_cache ../../../
-	cd debian/scripts/ungoogled-chromium; python3 -m buildkit prune -b config_bundles/$(config_bundle) ../../../
-	cd debian/scripts/ungoogled-chromium; python3 -m buildkit patches export -b config_bundles/$(config_bundle) ../../patches/; fi
+	python3 $(buildkit_cli) downloads retrieve -b $(config_bundle) -c ../../../../download_cache
+	python3 $(buildkit_cli) downloads unpack -b $(config_bundle) -c ../../../../download_cache ../../../
+	python3 $(buildkit_cli) prune -b $(config_bundle) ../../../
+	python3 $(buildkit_cli) patches export -b $(config_bundle) ../../patches/; fi

+ 6 - 3
packaging/macos/build.sh.ungoogin

@@ -18,10 +18,13 @@ rm -rf out || true
 mkdir out
 mkdir out/Default
 
+# Place download_cache next the source tree, which is usually build/src
+DOWNLOAD_CACHE="$packaging_dir/../../download_cache"
+
 pushd ungoogled_packaging
-mkdir download_cache 
-python3 -m buildkit downloads retrieve -b config_bundles/macos -c download_cache
-python3 -m buildkit downloads unpack -b config_bundles/macos -c download_cache ../
+mkdir "$DOWNLOAD_CACHE" 
+python3 -m buildkit downloads retrieve -b config_bundles/macos -c "$DOWNLOAD_CACHE"
+python3 -m buildkit downloads unpack -b config_bundles/macos -c "$DOWNLOAD_CACHE" ../
 python3 -m buildkit prune -b config_bundles/macos ../
 python3 -m buildkit patches apply -b config_bundles/macos ../
 python3 -m buildkit domains apply -b config_bundles/macos -c domainsubcache.tar.gz ../

+ 23 - 0
run_buildkit_cli.py

@@ -0,0 +1,23 @@
+#!/usr/bin/env python3
+
+# Copyright (c) 2018 The ungoogled-chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+"""
+A "current working directory"-independent script to launch the buildkit CLI.
+
+This is an alternative to using "python3 -m buildkit" after ensuring
+that buildkit (the directory, which is also also a Python module) is in
+a location accessible by the Python import system (e.g. by being in
+the containing directory or adding the containing directory to PYTHONPATH)
+"""
+
+import sys
+from pathlib import Path
+
+sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
+from buildkit import cli
+sys.path.pop(0)
+
+if __name__ == '__main__':
+    cli.main()