]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/metaparse/tools/build_environment.py
3 # Copyright Abel Sinkovics (abel@sinkovics.hu) 2016.
4 # Distributed under the Boost Software License, Version 1.0.
5 # (See accompanying file LICENSE_1_0.txt or copy at
6 # http://www.boost.org/LICENSE_1_0.txt)
14 def load_json(filename
):
15 with
open(filename
, 'r') as f
:
20 def __init__(self
, cmd
, cwd
= os
.getcwd()):
25 cmd_string
= ' '.join(cmd
)
26 print 'Running {0}'.format(cmd_string
)
27 proc
= subprocess
.Popen(
30 stdout
= subprocess
.PIPE
32 out
= proc
.communicate()[0]
33 if proc
.returncode
== 0:
37 'Command {0} exited with {1}'.format(
43 def in_dir(self
, cwd
):
44 return ChildProcess(self
.cmd
, cwd
)
46 def in_subdir(self
, subdir
):
47 return self
.in_dir(os
.path
.join(self
.cwd
, subdir
))
50 def head_of_master(submodule
, git
, ref
):
52 return git
.run(['show-ref', ref
]).split()[0]
55 def build_environment(submodules_file
, out_dir
, git
, repo
, action
, ref
):
56 submodules
= load_json(submodules_file
)
57 git
.run(['clone', repo
, out_dir
])
58 git_in_boost
= git
.in_dir(out_dir
)
61 ['submodule', 'init', '--'] + [k
for k
in submodules
.keys() if k
!= '']
63 git_in_boost
.run(['submodule', 'update'])
64 if action
== 'update':
65 with
open(submodules_file
, 'w') as f
:
68 (k
, head_of_master(k
, git_in_boost
.in_subdir(k
), ref
))
69 for k
, v
in submodules
.iteritems()
74 elif action
== 'checkout':
75 for name
, commit
in submodules
.iteritems():
76 git_in_boost
.in_subdir(name
).run(['checkout', commit
])
78 raise Exception('Invalid action {0}'.format(action
))
82 """The main function of the utility"""
83 parser
= argparse
.ArgumentParser(
84 description
='Manage the build environment of Boost.Metaparse'
89 help='The json file describing the dependencies'
95 help='The git command to use'
101 help='The directory to clone into'
106 choices
=['update', 'checkout'],
107 help='The action to do with the dependencies'
110 '--boost_repository',
112 default
='https://github.com/boostorg/boost.git',
113 help='The Boost repository to clone'
118 default
='origin/master',
119 help='The reference to set to in update'
121 args
= parser
.parse_args()
126 ChildProcess([args
.git
]),
127 args
.boost_repository
,
133 if __name__
== '__main__':