summaryrefslogtreecommitdiffstats
path: root/init-repository.py
diff options
context:
space:
mode:
authorZeno Albisser <zeno.albisser@digia.com>2013-08-07 12:49:57 +0200
committerZeno Albisser <zeno.albisser@digia.com>2013-08-16 16:21:58 +0200
commit285ba1642e82bcff245db0d07a0bfb212c08b7ef (patch)
tree6fb229261eccdf4e731ff2e7209f71114b09d9e5 /init-repository.py
parent28a638775d1bea997c0adfdb110763e6c14819ea (diff)
Add export_from_git.py to take snapshots from chromium and ninja.
Split out the Submodule class and related functions from init-repository.py into a separate python module git_submodule.py. This is necessary in order to reuse the code for the export script. The export_from_git.py script can be used to export files from a git repository into an arbitrary directory. It spiders submodules and applies some pattern matching to remove unwanted files. This script can be used to create flattened chromium snapshots to be used in our CI system. Change-Id: Iade8126fae6c28b5347c9d6e08941e28d3e0e7be Reviewed-by: Pierre Rossi <pierre.rossi@gmail.com>
Diffstat (limited to 'init-repository.py')
-rwxr-xr-xinit-repository.py109
1 files changed, 4 insertions, 105 deletions
diff --git a/init-repository.py b/init-repository.py
index 050fc4a21..7abacccb8 100755
--- a/init-repository.py
+++ b/init-repository.py
@@ -49,6 +49,9 @@ import string
qtwebengine_src = os.path.abspath(os.path.join(os.path.dirname(__file__)))
+sys.path.append(os.path.join(qtwebengine_src, 'tools'))
+import git_submodule as GitSubmodule
+
chrome_src = os.environ.get('CHROMIUM_SRC_DIR')
if chrome_src:
chrome_src = os.path.abspath(chrome_src)
@@ -64,110 +67,6 @@ def which(tool_name):
return entry
return ''
-
-class Submodule:
- def __init__(self):
- self.path = ''
- self.url = ''
- self.shasum = ''
- self.os = []
-
- def matchesOS(self):
- if not self.os:
- return True
- if 'all' in self.os:
- return True
- if sys.platform.startswith('win32') and 'win' in self.os:
- return True
- if sys.platform.startswith('linux') and 'unix' in self.os:
- return True
- if sys.platform.startswith('darwin') and ('unix' in self.os or 'mac' in self.os):
- return True
- return False
-
- def findSha(self):
- line = subprocess.check_output(['git', 'submodule', 'status', self.path])
- line = line.lstrip(' -')
- self.shasum = line.split(' ')[0]
-
- def findGitDir(self):
- try:
- return subprocess.check_output(['git', 'rev-parse', '--git-dir']).strip()
- except subprocess.CalledProcessError, e:
- sys.exit("git dir could not be determined! - Initialization failed!" + e.output)
-
- def reset(self):
- currentDir = os.getcwd()
- os.chdir(self.path)
- gitdir = self.findGitDir()
- if os.path.isdir(os.path.join(gitdir, 'rebase-merge')):
- if os.path.isfile(os.path.join(gitdir, 'MERGE_HEAD')):
- print 'merge in progress... aborting merge.'
- subprocess.call(['git', 'merge', '--abort'])
- else:
- print 'rebase in progress... aborting merge.'
- subprocess.call(['git', 'rebase', '--abort'])
- if os.path.isdir(os.path.join(gitdir, 'rebase-apply')):
- print 'am in progress... aborting am.'
- subprocess.call(['git', 'am', '--abort'])
- subprocess.call(['git', 'reset', '--hard'])
- os.chdir(currentDir)
-
- def initialize(self):
- if self.matchesOS():
- self.reset()
- print '-- initializing ' + self.path + ' --'
- subprocess.call(['git', 'submodule', 'init', self.path])
- subprocess.call(['git', 'submodule', 'update', self.path])
- self.findSha()
- currentDir = os.getcwd()
- os.chdir(self.path)
- # Make sure we have checked out the right shasum.
- # In case there were other patches applied before.
- val = subprocess.call(['git', 'checkout', self.shasum])
- if val != 0:
- sys.exit("!!! initialization failed !!!")
- initSubmodules()
- os.chdir(currentDir)
- else:
- print '-- skipping ' + self.path + ' for this operating system. --'
-
-
-def readSubmodules():
- currentDir = os.getcwd()
- if not os.path.isfile('.gitmodules'):
- return []
- gitmodules_file = open('.gitmodules')
- gitmodules_lines = gitmodules_file.readlines()
- gitmodules_file.close()
-
- submodules = []
- currentSubmodule = None
- for line in gitmodules_lines:
- if line.find('[submodule') == 0:
- if currentSubmodule:
- submodules.append(currentSubmodule)
- currentSubmodule = Submodule()
- tokens = line.split('=')
- if len(tokens) >= 2:
- key = tokens[0].strip()
- value = tokens[1].strip()
- if key == 'path':
- currentSubmodule.path = value
- elif key == 'url':
- currentSubmodule.url = value
- elif key == 'os':
- currentSubmodule.os = value.split(',')
- if currentSubmodule:
- submodules.append(currentSubmodule)
- return submodules
-
-def initSubmodules():
- submodules = readSubmodules()
- for submodule in submodules:
- submodule.initialize()
-
-
def updateLastChange():
currentDir = os.getcwd()
os.chdir(chrome_src)
@@ -205,7 +104,7 @@ def applyPatches():
os.chdir(qtwebengine_src)
addGerritRemote()
installGitHooks()
-initSubmodules()
+GitSubmodule.initSubmodules()
applyPatches()
updateLastChange()
buildNinja()