Close #94: Always rebuild apks when aports change

...even if the pkgver and pkgrel have *not* changed. This should
make development much more intuitive. The detection works by looking
at the last modified timestamps, just like `make` does it.
This commit is contained in:
Oliver Smith 2017-06-19 20:33:56 +02:00
parent 328bed4ba2
commit 6751b2e8cb
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
2 changed files with 37 additions and 4 deletions

View File

@ -22,6 +22,7 @@ import glob
import pmb.chroot
import pmb.helpers.run
import pmb.helpers.file
import pmb.parse.apkindex
@ -67,8 +68,10 @@ def copy_to_buildpath(args, package, suffix="native"):
def is_necessary(args, arch, apkbuild, apkindex_path=None):
"""
Check if the package has already been built (because abuild's check
only works, if it is the same architecture!)
Check if the package has already been built. Compared to abuild's check,
this check also works for different architectures, and it recognizes
changed files in an aport folder, even if the pkgver and pkgrel did not
change.
:param arch: package target architecture
:param apkbuild: from pmb.parse.apkbuild()
@ -90,8 +93,6 @@ def is_necessary(args, arch, apkbuild, apkindex_path=None):
if index_data:
version_old = index_data["version"]
if version_new == version_old:
return False
if pmb.parse.apkindex.compare_version(version_old,
version_new) == 1:
logging.warning("WARNING: Package " + package + "-" + version_old +
@ -99,6 +100,16 @@ def is_necessary(args, arch, apkbuild, apkindex_path=None):
" in the APKBUILD. Consider cleaning your package cache" +
" (pmbootstrap zap -p) or removing that file and running" +
" 'pmbootstrap index'!")
if version_new != version_old:
return True
# Check if all files in the aport folder have an older timestamp,
# than the package.
path_target = (os.path.dirname(apkindex_path) + "/" + package + "-" +
version_new + ".apk")
path_sources = glob.glob(args.aports + "/" + package + "/*")
if pmb.helpers.file.is_up_to_date(path_target, path_sources):
return False
return True

View File

@ -17,6 +17,8 @@ You should have received a copy of the GNU General Public License
along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
"""
import os
def replace(path, old, new):
text = ""
@ -27,3 +29,23 @@ def replace(path, old, new):
with open(path, 'w') as handle:
handle.write(text)
def is_up_to_date(path_target, path_sources):
"""
Check if a file is up-to-date by comparing the last modified timestamps
(just like make does it).
:param path_target: full path to the target file
:param path_sources: list of full paths to the source files
"""
lastmod_source = None
for path_source in path_sources:
lastmod = os.path.getmtime(path_source)
if not lastmod_source or lastmod > lastmod_source:
lastmod_source = lastmod
lastmod_target = os.path.getmtime(path_target)
return lastmod_target >= lastmod_source