github.com/hwaf/hwaf@v0.0.0-20140814122253-5465f73b20f1/py-hwaftools/orch/features/feature_vcs.py (about) 1 #!/usr/bin/env python 2 '''A "tarball"-like feature to which pulls from a VCS instead. It 3 provides the "seturl" and "unpack" steps. There is no "download" step 4 like "tarball" as the checkout/clone is direct to the source 5 directory. 6 7 ''' 8 import os.path as osp 9 from waflib.TaskGen import feature 10 import waflib.Logs as msg 11 12 from orch.util import urlopen, get_unpacker 13 from orch.wafutil import exec_command 14 15 import orch.features 16 orch.features.register_defaults( 17 'vcs', 18 source_urlfile = '{urlfile_dir}/{package}-{version}.url', 19 source_unpacked = '{package}-{version}', 20 source_unpacked_path = '{source_dir}/{source_unpacked}', 21 unpacked_target = 'README', 22 source_unpacked_target = '{source_unpacked_path}/{unpacked_target}', 23 24 vcs_flavor = 'git', # git,hg,svn,cvs 25 vcs_tag = '', 26 vcs_module = '', # used by cvs 27 ) 28 29 def single_cmd_rule(func): 30 def rule(tgen): 31 def task_func(task): 32 cmd = func(tgen) 33 return exec_command(task, cmd) 34 tgen.step('unpack', 35 rule = task_func, 36 source = tgen.worch.source_urlfile, 37 target = tgen.worch.source_unpacked_target) 38 return rule 39 40 @single_cmd_rule 41 def do_cvs(tgen): 42 tag = tgen.worch.get('vcs_tag', '') 43 if tag: 44 tag = '-r ' + tag 45 module = tgen.worch.get('vcs_module', '') 46 if not module: 47 module = tgen.worch.package 48 pat = 'cvs -d {source_url} checkout {vcs_tag_opt} -d {source_unpacked} {module}' 49 return tgen.worch.format(pat, vcs_tag_opt=tag, module=module) 50 51 @single_cmd_rule 52 def do_svn(tgen): 53 if tgen.worch.get('vcs_tag'): 54 err = tgen.worch.format('SVN has no concept of tags, can not honor: "{vcs_tag}"') 55 msg.error(err) 56 raise ValueError(err) 57 pat = "svn checkout {source_url} {source_unpacked}" 58 return tgen.worch.format(pat) 59 60 61 @single_cmd_rule 62 def do_hg(tgen): 63 tag = tgen.worch.get('vcs_tag', '') 64 if tag: 65 tag = '-b ' + tag 66 pat = "hg clone {vcs_tag_opt} {source_url} {source_unpacked}" 67 return tgen.worch.format(pat, vcs_tag_opt=tag) 68 69 70 71 def do_git(tgen): 72 73 git_dir = tgen.make_node(tgen.worch.format('{download_dir}/{package}.git')) 74 75 if osp.exists(git_dir.abspath()): 76 clone_or_update = 'git --git-dir={git_dir} fetch --all --tags' 77 else: 78 clone_or_update = 'git clone --bare {source_url} {git_dir}' 79 clone_or_update = tgen.worch.format(clone_or_update , git_dir=git_dir.abspath()) 80 tgen.step('download', 81 rule = clone_or_update, 82 source = tgen.worch.source_urlfile, 83 target = git_dir) 84 85 checkout = 'git --git-dir={git_dir} archive' 86 checkout += ' --format=tar --prefix={package}-{version}/ ' 87 checkout += ' ' + getattr(tgen.worch, 'vcs_tag', 'HEAD') # git tag, branch or hash 88 checkout += ' | tar -xvf -' 89 checkout = tgen.worch.format(checkout, git_dir=git_dir.abspath()) 90 tgen.step('unpack', 91 rule = checkout, 92 source = tgen.control_node('download'), 93 target = tgen.worch.source_unpacked_target) 94 95 96 97 @feature('vcs') 98 def feature_vcs(tgen): 99 100 tgen.step('seturl', 101 rule = "echo '%s' > %s" % (tgen.worch.source_url, tgen.worch.source_urlfile), 102 update_outputs = True, 103 target = tgen.worch.source_urlfile) 104 105 flavor = tgen.worch.vcs_flavor 106 doer = eval('do_%s' % flavor) 107 doer(tgen) 108 return 109 110