Skip to content
This repository
Browse code

update the openwebapps build from fx-share, allowing for better manag…

…ement of repo branches and tags
  • Loading branch information...
commit 28b7e05d787a560839c9dd57b7d51fda792f19ec 1 parent 9fc2a3b
Shane Caraveo mixedpuppy authored

Showing 3 changed files with 161 additions and 97 deletions. Show diff stats Hide diff stats

  1. +13 11 Makefile
  2. +125 86 build.py
  3. +23 0 dependencies.json
24 Makefile
... ... @@ -1,5 +1,3 @@
1   -APPNAME = fx-share-addon
2   -DEPS = github:addon-sdk,github:oauthorizer
3 1 PYTHON = python
4 2
5 3 MAKELAUNCHER =
@@ -21,20 +19,24 @@ ifneq ($(DEPSDIR),)
21 19 deps := $(DEPSDIR)
22 20 endif
23 21
  22 +binary :=
  23 +ifneq ($(MOZ_BINARY),)
  24 + binary := -b "$(MOZ_BINARY)"
  25 +endif
  26 +
24 27 addon_sdk := $(deps)/addon-sdk/bin
25 28 oauthorizer := $(deps)/oauthorizer
26 29 openwebapps := $(TOPSRCDIR)/addons/jetpack
27 30 activities := $(TOPSRCDIR)/addons/activities
28 31
29   -#cfx_args := --pkgdir=$(TOPSRCDIR) $(profile) --package-path=$(oauthorizer) --package-path=$(openwebapps) --binary-args="-console -purgecaches"
30 32 ifeq ($(TARGET),activities)
31   - cfx_args := --pkgdir=$(activities) $(profile) --package-path=$(oauthorizer) --package-path=$(openwebapps) --binary-args="-console -purgecaches $(BINARYARGS)"
  33 + pkgdir := $(activities)
  34 + cfx_args := --pkgdir=$(pkgdir) $(binary) $(profile) --package-path=$(oauthorizer) --package-path=$(openwebapps) --binary-args="-console -purgecaches $(BINARYARGS)"
32 35 else
33   - cfx_args := --pkgdir=$(openwebapps) $(profile) --binary-args="-console -purgecaches $(BINARYARGS)"
  36 + pkgdir := $(openwebapps)
  37 + cfx_args := --pkgdir=$(pkgdir) $(binary) $(profile) --binary-args="-console -purgecaches $(BINARYARGS)"
34 38 endif
35 39
36   -xpi_name := openwebapps.xpi
37   -
38 40 test_args :=
39 41 ifneq ($(TEST),)
40 42 test_args := -f $(TEST)
@@ -49,15 +51,15 @@ endif
49 51
50 52 all: xpi
51 53
52   -xpi: pull
53   - $(MAKELAUNCHER)
  54 +xpi: pull
54 55 $(addon_sdk)/cfx xpi $(cfx_args)
55 56
56 57 pull:
57   - $(PYTHON) build.py $(APPNAME) $(DEPS)
  58 + $(MAKELAUNCHER)
  59 + $(PYTHON) build.py -p $(pkgdir)/package.json
58 60
59 61 test:
60   - $(addon_sdk)/cfx test $(cfx_args) $(test_args)
  62 + $(addon_sdk)/cfx test -v $(cfx_args) $(test_args)
61 63
62 64 run:
63 65 $(MAKELAUNCHER)
211 build.py
@@ -19,6 +19,7 @@
19 19 #
20 20 # Contributor(s):
21 21 # Tarek Ziade (tarek@mozilla.com)
  22 +# Shane Caraveo (scaraveo@mozilla.com)
22 23 #
23 24 # Alternatively, the contents of this file may be used under the terms of
24 25 # either the GNU General Public License Version 2 or later (the "GPL"), or
@@ -36,11 +37,10 @@
36 37 import os
37 38 import sys
38 39 import subprocess
39   -
  40 +import json
  41 +from optparse import OptionParser
40 42
41 43 CURDIR = os.path.dirname(__file__)
42   -REPOS = {'github': ('git', 'https://github.com/mozilla/%s.git'),
43   - 'mozilla': ('hg', 'https://hg.mozilla.org/labs/%s')}
44 44 PYTHON = sys.executable
45 45
46 46
@@ -67,122 +67,161 @@ def get_latest_tag():
67 67
68 68
69 69 def _run(command):
70   - print(command)
71 70 os.system(command)
72 71
73 72
74   -def _envname(name):
75   - return name.upper().replace('-', '_')
76   -
77   -
78   -def _update_cmd(project, latest_tags=False, repo_type='git'):
79   - if latest_tags:
80   - if repo_type == 'hg':
81   - return 'hg up -r "%s"' % get_latest_tag()
  73 +def _update_cmd(tag, type='git'):
  74 + if type == 'git':
  75 + if tag and verify_tag(tag):
  76 + return 'git checkout %s' % tag
82 77 else:
83   - return 'git checkout -r "%s"' % get_latest_tag()
84   - else:
85   - # looking for an environ with a specific tag or rev
86   - rev = os.environ.get(_envname(project))
87   - if rev is not None:
88   - if not verify_tag(rev):
89   - print('Unknown tag or revision: %s' % rev)
90   - sys.exit(1)
91   - if repo_type == 'git':
92   - return 'git checkout -r "%s"' % rev
93   - else:
94   - return 'hg up -r "%s"' % rev
95   - if repo_type == 'git':
96   - return 'git checkout'
  78 + return 'git pull'
  79 + elif type == 'hg':
  80 + if tag:
  81 + return 'hg up -r "%s"' % tag
97 82 else:
98 83 return 'hg up'
99 84
100 85
101   -def build_app(name, latest_tags, deps):
102   - # building deps first
103   - build_deps(deps, latest_tags)
  86 +def get_deps_dir(dependencies):
  87 + deps_dir = dependencies.get('location')
  88 + if not os.path.isabs(deps_dir):
  89 + deps_dir = os.path.abspath(os.path.join(CURDIR, deps_dir))
  90 + if not os.path.exists(deps_dir):
  91 + os.mkdir(deps_dir)
  92 + return deps_dir
104 93
105   - # build the app now
106   - if not _has_spec():
107   - latest_tags = False
108 94
109   - _run(_update_cmd(name, latest_tags))
110   - #_run('%s setup.py develop' % PYTHON)
  95 +def pull_app(package, dependencies):
  96 + type, repo, branch, tag = dependencies.get('project')
  97 + name = os.path.basename(repo).split('.')[0]
  98 + update_cmd = _update_cmd("", type)
  99 + print "updating %s with: %s" % (name, update_cmd)
  100 + _run(update_cmd)
111 101
112 102
113   -def build_deps(deps, latest_tags):
  103 +def pull_deps(dependencies):
114 104 """Will make sure dependencies are up-to-date"""
115 105 location = os.getcwd()
116 106 # do we want the latest tags ?
117 107 try:
118   - deps_dir = os.path.abspath(os.environ.get('DEPSDIR', os.path.join(CURDIR, 'deps')))
119   - if not os.path.exists(deps_dir):
120   - os.mkdir(deps_dir)
121   -
122   - for dep in deps:
123   - root, name = dep.split(':')
124   - repo_type, repo_root = REPOS[root]
125   - repo = repo_root % name
  108 + deps_dir = get_deps_dir(dependencies)
  109 + for project in dependencies.get('projects', []):
  110 + type, repo, branch, tag = project
  111 + name = os.path.basename(repo).split('.')[0]
126 112 target = os.path.join(deps_dir, name)
127   - if os.path.exists(target):
128   - os.chdir(target)
129   - if repo_type == 'git':
130   - _run('git pull')
131   - else:
132   - _run('hg pull')
133   - else:
134   - if repo_type == 'git':
  113 + if not os.path.exists(target):
  114 + print "cloning ", name
  115 + if type == 'git':
135 116 _run('git clone %s %s' % (repo, target))
136 117 else:
137 118 _run('hg clone %s %s' % (repo, target))
138 119
139   - os.chdir(target)
140   - update_cmd = _update_cmd(dep, latest_tags, repo_type)
  120 + os.chdir(target)
  121 + if type == 'git' and branch:
  122 + print "checkout branch %s for %s" % (branch, name)
  123 + _run('git checkout %s' % branch)
  124 + update_cmd = _update_cmd(tag, type)
  125 + print "updating %s with: %s" % (name, update_cmd)
141 126 _run(update_cmd)
142   - #_run('%s setup.py develop' % PYTHON)
143 127 finally:
144 128 os.chdir(location)
145 129
146 130
147   -def _has_spec():
148   - specs = [file_ for file_ in os.listdir('.')
149   - if file_.endswith('.spec')]
150   - return len(specs)
  131 +def get_package(package):
  132 + return json.load(open(package))
151 133
152 134
153   -def main(project_name, deps):
154   - # check the provided values in the environ
155   - latest_tags = 'LATEST_TAGS' in os.environ
  135 +def get_dependencies(dependencies):
  136 + return json.load(open(dependencies))
156 137
157   - if not latest_tags:
158   - # if we have some tags in the environ, check that they are all defined
159   - projects = list(deps)
160 138
161   - # is the root a project itself or just a placeholder ?
162   - if _has_spec():
163   - projects.append(project_name)
  139 +def pull_release(options, package, dependencies):
  140 + project = dependencies.get('project', [])
  141 + project[3] = options.reltag
  142 + pull_app(package, dependencies)
  143 + # update dependencies now
  144 + dependencies = get_dependencies(options.dependencies)
  145 + pull_deps(dependencies)
164 146
165   - tags = {}
166   - missing = 0
167   - for project in projects:
168   - tag = _envname(project)
169   - if tag in os.environ:
170   - tags[tag] = os.environ[tag]
171   - else:
172   - tags[tag] = 'Not provided'
173   - missing += 1
174 147
175   - # we want all tag or no tag
176   - if missing > 0 and missing < len(projects):
177   - print("You did not specify all tags: ")
178   - for project, tag in tags.items():
179   - print(' %s: %s' % (project, tag))
180   - sys.exit(1)
  148 +def tag_release(package, dependencies):
  149 + rel_tag = "v%(version)s" % package
  150 + if verify_tag(rel_tag):
  151 + raise Exception("repository already tagged for release")
181 152
182   - build_app(project_name, latest_tags, deps)
  153 + location = os.getcwd()
  154 + # get the current revision and branch we're working with, update
  155 + # dependencies.json, then tag the repository we're in
  156 + import copy
  157 + old_deps = copy.copy(dependencies)
  158 + try:
  159 + deps_dir = get_deps_dir(dependencies)
  160 + for project in dependencies.get('projects', []):
  161 + type, repo, branch, tag = project
  162 + name = os.path.basename(repo).split('.')[0]
  163 + target = os.path.join(deps_dir, name)
  164 + os.chdir(target)
  165 + # tag the repo
  166 + if type == 'git':
  167 + # lightweight tags for dependency repos
  168 + p = os.popen("git log --pretty=format:'%h' -n 1")
  169 + project[3] = p.read()
  170 + else:
  171 + raise Exception("tagging not implemented for ", type)
  172 + print "tagging %s with %s" % (name, project[3])
  173 + print dependencies
  174 + finally:
  175 + os.chdir(location)
  176 +
  177 + dependencies_file = os.path.abspath(os.path.join(CURDIR, 'dependencies.json'))
  178 + json.dump(dependencies, open(dependencies_file, mode="w"), indent=2)
  179 +
  180 + # now, tag our project
  181 + rel_tag = "v%(version)s" % package
  182 + tag_msg = "release version %(version)s" % package
  183 + print "tagging %s with %s" % (package.get('name'), rel_tag)
  184 + # tag the repo
  185 + if type == 'git':
  186 + # lightweight tags for dependency repos
  187 + _run('git commit %s -m "update dependency tags"' % dependencies_file)
  188 + _run('git tag -a %s -m "%s" && git push origin --tags' % (rel_tag, tag_msg))
  189 + else:
  190 + raise Exception("tagging not implemented for ", type)
183 191
184 192
185 193 if __name__ == '__main__':
186   - project_name = sys.argv[1]
187   - deps = [dep.strip() for dep in sys.argv[2].split(',')]
188   - main(project_name, deps)
  194 + # defaults
  195 + dependencies_file = os.path.abspath(os.path.join(CURDIR, 'dependencies.json'))
  196 + package_file = os.path.abspath(os.path.join(CURDIR, 'package.json'))
  197 +
  198 + # options
  199 + parser = OptionParser()
  200 + parser.add_option("-v", "--version", dest="version",
  201 + action="store_true", default=False,
  202 + help="version from package.json")
  203 + parser.add_option("-r", "--pull-release", dest="reltag",
  204 + help="pull a specific release from the repositories")
  205 + parser.add_option("-t", "--tag", dest="tag",
  206 + action="store_true", default=False,
  207 + help="tag repositories with the release version from package.json")
  208 + parser.add_option("-p", "--package", dest="package",
  209 + default=package_file,
  210 + help="Addon SDK package.json file", metavar="FILE")
  211 + parser.add_option("-d", "--dependencies", dest="dependencies",
  212 + default=dependencies_file, metavar="FILE",
  213 + help="repository dependencies.json file")
  214 + (options, args) = parser.parse_args()
  215 + package = get_package(options.package)
  216 + dependencies = get_dependencies(options.dependencies)
  217 +
  218 + if options.version:
  219 + print package.get('version')
  220 + sys.exit(0)
  221 + if options.reltag:
  222 + pull_release(options, package, dependencies)
  223 + else:
  224 + pull_app(package, dependencies)
  225 + pull_deps(dependencies)
  226 + if options.tag:
  227 + tag_release(package, dependencies)
23 dependencies.json
... ... @@ -0,0 +1,23 @@
  1 +{
  2 + "project": [
  3 + "git",
  4 + "https://github.com/mozilla/openwebapps.git",
  5 + "develop",
  6 + ""
  7 + ],
  8 + "location": "deps",
  9 + "projects": [
  10 + [
  11 + "git",
  12 + "https://github.com/mozilla/addon-sdk.git",
  13 + "master",
  14 + ""
  15 + ],
  16 + [
  17 + "git",
  18 + "https://github.com/mozilla/oauthorizer.git",
  19 + "develop",
  20 + ""
  21 + ]
  22 + ]
  23 +}

0 comments on commit 28b7e05

Please sign in to comment.
Something went wrong with that request. Please try again.