summaryrefslogtreecommitdiffstats
path: root/meta/classes/sanity.bbclass
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2013-05-09 17:05:58 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-05-09 22:28:04 +0100
commit566628d8cd674a964d5824391cfd1585a1a22a87 (patch)
tree670366ee1492ff8bb18b9261dfab9d06c06b0a2d /meta/classes/sanity.bbclass
parentd2ef952851d9ef16875fdbbbc6ae6eb6cfc10cc0 (diff)
downloadpoky-566628d8cd674a964d5824391cfd1585a1a22a87.tar.gz
class/lib: Fix up various file access methods
There are various bits of cruft that have built up around our file accesses. This patch cleans some of them up, specifically: * Remove pointless "from __builtin__ import file" * Use open(), not file() * Wrap file usage in a with container to ensure files are closed * Add missing .close() calls in some cases (From OE-Core rev: a43e0a8ecd0441131e929daf998c3cd454d9c8f3) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/sanity.bbclass')
-rw-r--r--meta/classes/sanity.bbclass63
1 files changed, 30 insertions, 33 deletions
diff --git a/meta/classes/sanity.bbclass b/meta/classes/sanity.bbclass
index 1fb4a6c629..62fe7e4ef7 100644
--- a/meta/classes/sanity.bbclass
+++ b/meta/classes/sanity.bbclass
@@ -561,14 +561,14 @@ def check_sanity(sanity_data):
561 last_sstate_dir = "" 561 last_sstate_dir = ""
562 sanityverfile = 'conf/sanity_info' 562 sanityverfile = 'conf/sanity_info'
563 if os.path.exists(sanityverfile): 563 if os.path.exists(sanityverfile):
564 f = open(sanityverfile, 'r') 564 with open(sanityverfile, 'r') as f:
565 for line in f: 565 for line in f:
566 if line.startswith('SANITY_VERSION'): 566 if line.startswith('SANITY_VERSION'):
567 last_sanity_version = int(line.split()[1]) 567 last_sanity_version = int(line.split()[1])
568 if line.startswith('TMPDIR'): 568 if line.startswith('TMPDIR'):
569 last_tmpdir = line.split()[1] 569 last_tmpdir = line.split()[1]
570 if line.startswith('SSTATE_DIR'): 570 if line.startswith('SSTATE_DIR'):
571 last_sstate_dir = line.split()[1] 571 last_sstate_dir = line.split()[1]
572 572
573 sanity_version = int(sanity_data.getVar('SANITY_VERSION', True) or 1) 573 sanity_version = int(sanity_data.getVar('SANITY_VERSION', True) or 1)
574 network_error = False 574 network_error = False
@@ -584,25 +584,24 @@ def check_sanity(sanity_data):
584 if last_sstate_dir != sstate_dir: 584 if last_sstate_dir != sstate_dir:
585 messages = messages + check_sanity_sstate_dir_change(sstate_dir, sanity_data) 585 messages = messages + check_sanity_sstate_dir_change(sstate_dir, sanity_data)
586 if os.path.exists("conf") and not messages: 586 if os.path.exists("conf") and not messages:
587 f = open(sanityverfile, 'w') 587 with open(sanityverfile, 'w') as f:
588 f.write("SANITY_VERSION %s\n" % sanity_version) 588 f.write("SANITY_VERSION %s\n" % sanity_version)
589 f.write("TMPDIR %s\n" % tmpdir) 589 f.write("TMPDIR %s\n" % tmpdir)
590 f.write("SSTATE_DIR %s\n" % sstate_dir) 590 f.write("SSTATE_DIR %s\n" % sstate_dir)
591 591
592 # 592 #
593 # Check that TMPDIR hasn't changed location since the last time we were run 593 # Check that TMPDIR hasn't changed location since the last time we were run
594 # 594 #
595 checkfile = os.path.join(tmpdir, "saved_tmpdir") 595 checkfile = os.path.join(tmpdir, "saved_tmpdir")
596 if os.path.exists(checkfile): 596 if os.path.exists(checkfile):
597 f = open(checkfile, "r") 597 with open(checkfile, "r") as f:
598 saved_tmpdir = f.read().strip() 598 saved_tmpdir = f.read().strip()
599 if (saved_tmpdir != tmpdir): 599 if (saved_tmpdir != tmpdir):
600 messages = messages + "Error, TMPDIR has changed location. You need to either move it back to %s or rebuild\n" % saved_tmpdir 600 messages = messages + "Error, TMPDIR has changed location. You need to either move it back to %s or rebuild\n" % saved_tmpdir
601 else: 601 else:
602 bb.utils.mkdirhier(tmpdir) 602 bb.utils.mkdirhier(tmpdir)
603 f = open(checkfile, "w") 603 with open(checkfile, "w") as f:
604 f.write(tmpdir) 604 f.write(tmpdir)
605 f.close()
606 605
607 # 606 #
608 # Check the 'ABI' of TMPDIR 607 # Check the 'ABI' of TMPDIR
@@ -610,33 +609,32 @@ def check_sanity(sanity_data):
610 current_abi = sanity_data.getVar('OELAYOUT_ABI', True) 609 current_abi = sanity_data.getVar('OELAYOUT_ABI', True)
611 abifile = sanity_data.getVar('SANITY_ABIFILE', True) 610 abifile = sanity_data.getVar('SANITY_ABIFILE', True)
612 if os.path.exists(abifile): 611 if os.path.exists(abifile):
613 f = open(abifile, "r") 612 with open(abifile, "r") as f:
614 abi = f.read().strip() 613 abi = f.read().strip()
615 if not abi.isdigit(): 614 if not abi.isdigit():
616 f = open(abifile, "w") 615 with open(abifile, "w") as f:
617 f.write(current_abi) 616 f.write(current_abi)
618 elif abi == "2" and current_abi == "3": 617 elif abi == "2" and current_abi == "3":
619 bb.note("Converting staging from layout version 2 to layout version 3") 618 bb.note("Converting staging from layout version 2 to layout version 3")
620 subprocess.call(sanity_data.expand("mv ${TMPDIR}/staging ${TMPDIR}/sysroots"), shell=True) 619 subprocess.call(sanity_data.expand("mv ${TMPDIR}/staging ${TMPDIR}/sysroots"), shell=True)
621 subprocess.call(sanity_data.expand("ln -s sysroots ${TMPDIR}/staging"), shell=True) 620 subprocess.call(sanity_data.expand("ln -s sysroots ${TMPDIR}/staging"), shell=True)
622 subprocess.call(sanity_data.expand("cd ${TMPDIR}/stamps; for i in */*do_populate_staging; do new=`echo $i | sed -e 's/do_populate_staging/do_populate_sysroot/'`; mv $i $new; done"), shell=True) 621 subprocess.call(sanity_data.expand("cd ${TMPDIR}/stamps; for i in */*do_populate_staging; do new=`echo $i | sed -e 's/do_populate_staging/do_populate_sysroot/'`; mv $i $new; done"), shell=True)
623 f = open(abifile, "w") 622 with open(abifile, "w") as f:
624 f.write(current_abi) 623 f.write(current_abi)
625 elif abi == "3" and current_abi == "4": 624 elif abi == "3" and current_abi == "4":
626 bb.note("Converting staging layout from version 3 to layout version 4") 625 bb.note("Converting staging layout from version 3 to layout version 4")
627 if os.path.exists(sanity_data.expand("${STAGING_DIR_NATIVE}${bindir_native}/${MULTIMACH_HOST_SYS}")): 626 if os.path.exists(sanity_data.expand("${STAGING_DIR_NATIVE}${bindir_native}/${MULTIMACH_HOST_SYS}")):
628 subprocess.call(sanity_data.expand("mv ${STAGING_DIR_NATIVE}${bindir_native}/${MULTIMACH_HOST_SYS} ${STAGING_BINDIR_CROSS}"), shell=True) 627 subprocess.call(sanity_data.expand("mv ${STAGING_DIR_NATIVE}${bindir_native}/${MULTIMACH_HOST_SYS} ${STAGING_BINDIR_CROSS}"), shell=True)
629 subprocess.call(sanity_data.expand("ln -s ${STAGING_BINDIR_CROSS} ${STAGING_DIR_NATIVE}${bindir_native}/${MULTIMACH_HOST_SYS}"), shell=True) 628 subprocess.call(sanity_data.expand("ln -s ${STAGING_BINDIR_CROSS} ${STAGING_DIR_NATIVE}${bindir_native}/${MULTIMACH_HOST_SYS}"), shell=True)
630 629 with open(abifile, "w") as f:
631 f = open(abifile, "w") 630 f.write(current_abi)
632 f.write(current_abi)
633 elif abi == "4": 631 elif abi == "4":
634 messages = messages + "Staging layout has changed. The cross directory has been deprecated and cross packages are now built under the native sysroot.\nThis requires a rebuild.\n" 632 messages = messages + "Staging layout has changed. The cross directory has been deprecated and cross packages are now built under the native sysroot.\nThis requires a rebuild.\n"
635 elif abi == "5" and current_abi == "6": 633 elif abi == "5" and current_abi == "6":
636 bb.note("Converting staging layout from version 5 to layout version 6") 634 bb.note("Converting staging layout from version 5 to layout version 6")
637 subprocess.call(sanity_data.expand("mv ${TMPDIR}/pstagelogs ${SSTATE_MANIFESTS}"), shell=True) 635 subprocess.call(sanity_data.expand("mv ${TMPDIR}/pstagelogs ${SSTATE_MANIFESTS}"), shell=True)
638 f = open(abifile, "w") 636 with open(abifile, "w") as f:
639 f.write(current_abi) 637 f.write(current_abi)
640 elif abi == "7" and current_abi == "8": 638 elif abi == "7" and current_abi == "8":
641 messages = messages + "Your configuration is using stamp files including the sstate hash but your build directory was built with stamp files that do not include this.\nTo continue, either rebuild or switch back to the OEBasic signature handler with BB_SIGNATURE_HANDLER = 'OEBasic'.\n" 639 messages = messages + "Your configuration is using stamp files including the sstate hash but your build directory was built with stamp files that do not include this.\nTo continue, either rebuild or switch back to the OEBasic signature handler with BB_SIGNATURE_HANDLER = 'OEBasic'.\n"
642 elif (abi != current_abi and current_abi == "9"): 640 elif (abi != current_abi and current_abi == "9"):
@@ -645,9 +643,8 @@ def check_sanity(sanity_data):
645 # Code to convert from one ABI to another could go here if possible. 643 # Code to convert from one ABI to another could go here if possible.
646 messages = messages + "Error, TMPDIR has changed its layout version number (%s to %s) and you need to either rebuild, revert or adjust it at your own risk.\n" % (abi, current_abi) 644 messages = messages + "Error, TMPDIR has changed its layout version number (%s to %s) and you need to either rebuild, revert or adjust it at your own risk.\n" % (abi, current_abi)
647 else: 645 else:
648 f = open(abifile, "w") 646 with open(abifile, "w") as f:
649 f.write(current_abi) 647 f.write(current_abi)
650 f.close()
651 648
652 oeroot = sanity_data.getVar('COREBASE') 649 oeroot = sanity_data.getVar('COREBASE')
653 if oeroot.find ('+') != -1: 650 if oeroot.find ('+') != -1: