Show More
@@ -17,6 +17,7 b' man: $(MAN)' | |||||
17 |
|
17 | |||
18 | html: $(HTML) |
|
18 | html: $(HTML) | |
19 |
|
19 | |||
|
20 | # This logic is duplicated in setup.py:hgbuilddoc() | |||
20 | common.txt $(SOURCES) $(SOURCES:%.txt=%.gendoc.txt): $(GENDOC) |
|
21 | common.txt $(SOURCES) $(SOURCES:%.txt=%.gendoc.txt): $(GENDOC) | |
21 | ${PYTHON} gendoc.py "$(basename $@)" > $@.tmp |
|
22 | ${PYTHON} gendoc.py "$(basename $@)" > $@.tmp | |
22 | mv $@.tmp $@ |
|
23 | mv $@.tmp $@ |
@@ -240,9 +240,9 b' try:' | |||||
240 | except ImportError: |
|
240 | except ImportError: | |
241 | py2exeloaded = False |
|
241 | py2exeloaded = False | |
242 |
|
242 | |||
243 | def runcmd(cmd, env): |
|
243 | def runcmd(cmd, env, cwd=None): | |
244 | p = subprocess.Popen(cmd, stdout=subprocess.PIPE, |
|
244 | p = subprocess.Popen(cmd, stdout=subprocess.PIPE, | |
245 | stderr=subprocess.PIPE, env=env) |
|
245 | stderr=subprocess.PIPE, env=env, cwd=cwd) | |
246 | out, err = p.communicate() |
|
246 | out, err = p.communicate() | |
247 | return p.returncode, out, err |
|
247 | return p.returncode, out, err | |
248 |
|
248 | |||
@@ -702,6 +702,117 b' class buildhgexe(build_ext):' | |||||
702 | dir = os.path.dirname(self.get_ext_fullpath('dummy')) |
|
702 | dir = os.path.dirname(self.get_ext_fullpath('dummy')) | |
703 | return os.path.join(self.build_temp, dir, 'hg.exe') |
|
703 | return os.path.join(self.build_temp, dir, 'hg.exe') | |
704 |
|
704 | |||
|
705 | class hgbuilddoc(Command): | |||
|
706 | description = 'build documentation' | |||
|
707 | user_options = [ | |||
|
708 | ('man', None, 'generate man pages'), | |||
|
709 | ('html', None, 'generate html pages'), | |||
|
710 | ] | |||
|
711 | ||||
|
712 | def initialize_options(self): | |||
|
713 | self.man = None | |||
|
714 | self.html = None | |||
|
715 | ||||
|
716 | def finalize_options(self): | |||
|
717 | # If --man or --html are set, only generate what we're told to. | |||
|
718 | # Otherwise generate everything. | |||
|
719 | have_subset = self.man is not None or self.html is not None | |||
|
720 | ||||
|
721 | if have_subset: | |||
|
722 | self.man = True if self.man else False | |||
|
723 | self.html = True if self.html else False | |||
|
724 | else: | |||
|
725 | self.man = True | |||
|
726 | self.html = True | |||
|
727 | ||||
|
728 | def run(self): | |||
|
729 | def normalizecrlf(p): | |||
|
730 | with open(p, 'rb') as fh: | |||
|
731 | orig = fh.read() | |||
|
732 | ||||
|
733 | if b'\r\n' not in orig: | |||
|
734 | return | |||
|
735 | ||||
|
736 | log.info('normalizing %s to LF line endings' % p) | |||
|
737 | with open(p, 'wb') as fh: | |||
|
738 | fh.write(orig.replace(b'\r\n', b'\n')) | |||
|
739 | ||||
|
740 | def gentxt(root): | |||
|
741 | txt = 'doc/%s.txt' % root | |||
|
742 | log.info('generating %s' % txt) | |||
|
743 | res, out, err = runcmd( | |||
|
744 | [sys.executable, 'gendoc.py', root], | |||
|
745 | os.environ, | |||
|
746 | cwd='doc') | |||
|
747 | if res: | |||
|
748 | raise SystemExit('error running gendoc.py: %s' % | |||
|
749 | '\n'.join([out, err])) | |||
|
750 | ||||
|
751 | with open(txt, 'wb') as fh: | |||
|
752 | fh.write(out) | |||
|
753 | ||||
|
754 | def gengendoc(root): | |||
|
755 | gendoc = 'doc/%s.gendoc.txt' % root | |||
|
756 | ||||
|
757 | log.info('generating %s' % gendoc) | |||
|
758 | res, out, err = runcmd( | |||
|
759 | [sys.executable, 'gendoc.py', '%s.gendoc' % root], | |||
|
760 | os.environ, | |||
|
761 | cwd='doc') | |||
|
762 | if res: | |||
|
763 | raise SystemExit('error running gendoc: %s' % | |||
|
764 | '\n'.join([out, err])) | |||
|
765 | ||||
|
766 | with open(gendoc, 'wb') as fh: | |||
|
767 | fh.write(out) | |||
|
768 | ||||
|
769 | def genman(root): | |||
|
770 | log.info('generating doc/%s' % root) | |||
|
771 | res, out, err = runcmd( | |||
|
772 | [sys.executable, 'runrst', 'hgmanpage', '--halt', 'warning', | |||
|
773 | '--strip-elements-with-class', 'htmlonly', | |||
|
774 | '%s.txt' % root, root], | |||
|
775 | os.environ, | |||
|
776 | cwd='doc') | |||
|
777 | if res: | |||
|
778 | raise SystemExit('error running runrst: %s' % | |||
|
779 | '\n'.join([out, err])) | |||
|
780 | ||||
|
781 | normalizecrlf('doc/%s' % root) | |||
|
782 | ||||
|
783 | def genhtml(root): | |||
|
784 | log.info('generating doc/%s.html' % root) | |||
|
785 | res, out, err = runcmd( | |||
|
786 | [sys.executable, 'runrst', 'html', '--halt', 'warning', | |||
|
787 | '--link-stylesheet', '--stylesheet-path', 'style.css', | |||
|
788 | '%s.txt' % root, '%s.html' % root], | |||
|
789 | os.environ, | |||
|
790 | cwd='doc') | |||
|
791 | if res: | |||
|
792 | raise SystemExit('error running runrst: %s' % | |||
|
793 | '\n'.join([out, err])) | |||
|
794 | ||||
|
795 | normalizecrlf('doc/%s.html' % root) | |||
|
796 | ||||
|
797 | # This logic is duplicated in doc/Makefile. | |||
|
798 | sources = {f for f in os.listdir('mercurial/help') | |||
|
799 | if re.search('[0-9]\.txt$', f)} | |||
|
800 | ||||
|
801 | # common.txt is a one-off. | |||
|
802 | gentxt('common') | |||
|
803 | ||||
|
804 | for source in sorted(sources): | |||
|
805 | assert source[-4:] == '.txt' | |||
|
806 | root = source[:-4] | |||
|
807 | ||||
|
808 | gentxt(root) | |||
|
809 | gengendoc(root) | |||
|
810 | ||||
|
811 | if self.man: | |||
|
812 | genman(root) | |||
|
813 | if self.html: | |||
|
814 | genhtml(root) | |||
|
815 | ||||
705 | class hginstall(install): |
|
816 | class hginstall(install): | |
706 |
|
817 | |||
707 | user_options = install.user_options + [ |
|
818 | user_options = install.user_options + [ | |
@@ -827,6 +938,7 b' class hginstallscripts(install_scripts):' | |||||
827 | fp.write(data) |
|
938 | fp.write(data) | |
828 |
|
939 | |||
829 | cmdclass = {'build': hgbuild, |
|
940 | cmdclass = {'build': hgbuild, | |
|
941 | 'build_doc': hgbuilddoc, | |||
830 | 'build_mo': hgbuildmo, |
|
942 | 'build_mo': hgbuildmo, | |
831 | 'build_ext': hgbuildext, |
|
943 | 'build_ext': hgbuildext, | |
832 | 'build_py': hgbuildpy, |
|
944 | 'build_py': hgbuildpy, |
General Comments 0
You need to be logged in to leave comments.
Login now