Mercurial > hg > truffle
comparison mxtool/mx.py @ 13620:fa56f5a49270
improved format checking and error reporting when parsing a projects file
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 13 Jan 2014 21:40:47 +0100 |
parents | d3bd7a3bbb2b |
children | c4ff08d2aa0d |
comparison
equal
deleted
inserted
replaced
13619:5a076e52220a | 13620:fa56f5a49270 |
---|---|
699 if not exists(projectsFile): | 699 if not exists(projectsFile): |
700 return | 700 return |
701 | 701 |
702 with open(projectsFile) as f: | 702 with open(projectsFile) as f: |
703 prefix = '' | 703 prefix = '' |
704 lineNum = 0 | |
705 | |
706 def error(message): | |
707 abort(projectsFile + ':' + str(lineNum) + ': ' + message) | |
708 | |
704 for line in f: | 709 for line in f: |
710 lineNum = lineNum + 1 | |
705 line = line.strip() | 711 line = line.strip() |
706 if line.endswith('\\'): | 712 if line.endswith('\\'): |
707 prefix = prefix + line[:-1] | 713 prefix = prefix + line[:-1] |
708 continue | 714 continue |
709 if len(prefix) != 0: | 715 if len(prefix) != 0: |
710 line = prefix + line | 716 line = prefix + line |
711 prefix = '' | 717 prefix = '' |
712 if len(line) != 0 and line[0] != '#': | 718 if len(line) != 0 and line[0] != '#': |
719 if '=' not in line: | |
720 error('non-comment line does not contain an "=" character') | |
713 key, value = line.split('=', 1) | 721 key, value = line.split('=', 1) |
714 | 722 |
715 parts = key.split('@') | 723 parts = key.split('@') |
716 | 724 |
717 if len(parts) == 1: | 725 if len(parts) == 1: |
718 if parts[0] == 'suite': | 726 if parts[0] == 'suite': |
719 if self.name != value: | 727 if self.name != value: |
720 abort('suite name in project file does not match ' + _suitename(self.mxDir)) | 728 error('suite name in project file does not match ' + _suitename(self.mxDir)) |
721 elif parts[0] == 'mxversion': | 729 elif parts[0] == 'mxversion': |
722 try: | 730 try: |
723 self.requiredMxVersion = VersionSpec(value) | 731 self.requiredMxVersion = VersionSpec(value) |
724 except AssertionError as ae: | 732 except AssertionError as ae: |
725 abort('Exception while parsing "mxversion" in project file: ' + str(ae)) | 733 error('Exception while parsing "mxversion" in project file: ' + str(ae)) |
726 else: | 734 else: |
727 abort('Single part property must be "suite": ' + key) | 735 error('Single part property must be "suite": ' + key) |
728 | 736 |
729 continue | 737 continue |
730 if len(parts) != 3: | 738 if len(parts) != 3: |
731 abort('Property name does not have 3 parts separated by "@": ' + key) | 739 error('Property name does not have 3 parts separated by "@": ' + key) |
732 kind, name, attr = parts | 740 kind, name, attr = parts |
733 if kind == 'project': | 741 if kind == 'project': |
734 m = projsMap | 742 m = projsMap |
735 elif kind == 'library': | 743 elif kind == 'library': |
736 m = libsMap | 744 m = libsMap |
737 elif kind == 'distribution': | 745 elif kind == 'distribution': |
738 m = distsMap | 746 m = distsMap |
739 else: | 747 else: |
740 abort('Property name does not start with "project@", "library@" or "distribution@": ' + key) | 748 error('Property name does not start with "project@", "library@" or "distribution@": ' + key) |
741 | 749 |
742 attrs = m.get(name) | 750 attrs = m.get(name) |
743 if attrs is None: | 751 if attrs is None: |
744 attrs = dict() | 752 attrs = dict() |
745 m[name] = attrs | 753 m[name] = attrs |
766 workingSets = attrs.pop('workingSets', None) | 774 workingSets = attrs.pop('workingSets', None) |
767 p = Project(self, name, srcDirs, deps, javaCompliance, workingSets, d) | 775 p = Project(self, name, srcDirs, deps, javaCompliance, workingSets, d) |
768 p.checkstyleProj = attrs.pop('checkstyle', name) | 776 p.checkstyleProj = attrs.pop('checkstyle', name) |
769 p.native = attrs.pop('native', '') == 'true' | 777 p.native = attrs.pop('native', '') == 'true' |
770 if not p.native and p.javaCompliance is None: | 778 if not p.native and p.javaCompliance is None: |
771 abort('javaCompliance property required for non-native project ' + name) | 779 error('javaCompliance property required for non-native project ' + name) |
772 if len(ap) > 0: | 780 if len(ap) > 0: |
773 p._declaredAnnotationProcessors = ap | 781 p._declaredAnnotationProcessors = ap |
774 p.__dict__.update(attrs) | 782 p.__dict__.update(attrs) |
775 self.projects.append(p) | 783 self.projects.append(p) |
776 | 784 |