OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
4 # for details. All rights reserved. Use of this source code is governed by a | 4 # for details. All rights reserved. Use of this source code is governed by a |
5 # BSD-style license that can be found in the LICENSE file. | 5 # BSD-style license that can be found in the LICENSE file. |
6 # | 6 # |
7 # Script to push a package to pub. | 7 # Script to push a package to pub. |
8 # | 8 # |
9 # Usage: publish_pkg.py pkg_dir | 9 # Usage: publish_pkg.py pkg_dir |
10 # | 10 # |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 if major == 0 and minor <= 1: | 51 if major == 0 and minor <= 1: |
52 print 'Error: Do not run this script from a bleeding_edge checkout.' | 52 print 'Error: Do not run this script from a bleeding_edge checkout.' |
53 return -1 | 53 return -1 |
54 | 54 |
55 if patch != 0: | 55 if patch != 0: |
56 version = '%d.%d.%d+%d' % (major, minor, build, patch) | 56 version = '%d.%d.%d+%d' % (major, minor, build, patch) |
57 else: | 57 else: |
58 version = '%d.%d.%d' % (major, minor, build) | 58 version = '%d.%d.%d' % (major, minor, build) |
59 | 59 |
60 tmpDir = tempfile.mkdtemp() | 60 tmpDir = tempfile.mkdtemp() |
61 pkgName = argv[1].split('/').pop() | 61 pkgName = os.path.basename(os.path.normpath(argv[1])) |
62 | 62 |
63 pubspec = os.path.join(tmpDir, pkgName, 'pubspec.yaml') | 63 pubspec = os.path.join(tmpDir, pkgName, 'pubspec.yaml') |
64 | 64 |
65 replaceInFiles = [] | 65 replaceInDart = [] |
| 66 replaceInPubspec = [] |
66 | 67 |
67 if os.path.exists(os.path.join(HOME, argv[1], 'pubspec.yaml')): | 68 if os.path.exists(os.path.join(HOME, argv[1], 'pubspec.yaml')): |
68 # | 69 # |
69 # If pubspec.yaml exists, add the SDK's version number if | 70 # If pubspec.yaml exists, add the SDK's version number if |
70 # no version number is present. | 71 # no version number is present. |
71 # | 72 # |
72 shutil.copytree(os.path.join(HOME, argv[1]), | 73 shutil.copytree(os.path.join(HOME, argv[1]), |
73 os.path.join(tmpDir, pkgName)) | 74 os.path.join(tmpDir, pkgName)) |
74 with open(pubspec) as pubspecFile: | 75 with open(pubspec) as pubspecFile: |
75 lines = pubspecFile.readlines() | 76 lines = pubspecFile.readlines() |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 pubspecFile.write(' ' + argv[1] + ' . This package will change in\n') | 120 pubspecFile.write(' ' + argv[1] + ' . This package will change in\n') |
120 pubspecFile.write(' unpredictable/incompatible ways without warning.\n') | 121 pubspecFile.write(' unpredictable/incompatible ways without warning.\n') |
121 pubspecFile.write('dependencies:\n') | 122 pubspecFile.write('dependencies:\n') |
122 | 123 |
123 libpath = os.path.join(HOME, argv[1], '../libraries.dart') | 124 libpath = os.path.join(HOME, argv[1], '../libraries.dart') |
124 if os.path.exists(libpath): | 125 if os.path.exists(libpath): |
125 # Copy libraries.dart into the package source code | 126 # Copy libraries.dart into the package source code |
126 shutil.copy(libpath, os.path.join(tmpDir, pkgName, 'lib/libraries.dart')) | 127 shutil.copy(libpath, os.path.join(tmpDir, pkgName, 'lib/libraries.dart')) |
127 | 128 |
128 # Replace '../../libraries.dart' with '../libraries.dart' | 129 # Replace '../../libraries.dart' with '../libraries.dart' |
129 replaceInFiles.append( | 130 replaceInDart.append( |
130 (r'(import|part)(\s+)(\'|")\.\./(\.\./)*libraries.dart', | 131 (r'(import|part)(\s+)(\'|")\.\./(\.\./)*libraries.dart', |
131 r'\1\2\3\4libraries.dart')) | 132 r'\1\2\3\4libraries.dart')) |
132 | 133 |
133 if not os.path.exists(os.path.join(tmpDir, pkgName, 'LICENSE')): | 134 if not os.path.exists(os.path.join(tmpDir, pkgName, 'LICENSE')): |
134 with open(os.path.join(tmpDir, pkgName, 'LICENSE'), 'w') as licenseFile: | 135 with open(os.path.join(tmpDir, pkgName, 'LICENSE'), 'w') as licenseFile: |
135 licenseFile.write(''' | 136 licenseFile.write(''' |
136 Copyright 2012, the Dart project authors. All rights reserved. | 137 Copyright 2012, the Dart project authors. All rights reserved. |
137 Redistribution and use in source and binary forms, with or without | 138 Redistribution and use in source and binary forms, with or without |
138 modification, are permitted provided that the following conditions are | 139 modification, are permitted provided that the following conditions are |
139 met: | 140 met: |
(...skipping 12 matching lines...) Expand all Loading... |
152 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 153 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
153 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 154 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
154 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 155 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
155 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 156 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
156 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 157 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
157 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 158 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
158 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 159 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
159 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 160 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
160 '''); | 161 '''); |
161 | 162 |
162 replaceInFiles.append( | 163 # TODO(jmesserly): this is a hack to make analyzer-experimental work. |
| 164 if pkgName.endswith('-experimental'): |
| 165 pkgReplace = (pkgName, pkgName.replace('-', '_')) |
| 166 replaceInDart.append(pkgReplace) |
| 167 replaceInPubspec.append(pkgReplace) |
| 168 |
| 169 replaceInDart.append( |
163 (r'(import|part)(\s+)(\'|")(\.\./)+pkg/([^/]+/)lib/', r'\1\2\3package:\5')) | 170 (r'(import|part)(\s+)(\'|")(\.\./)+pkg/([^/]+/)lib/', r'\1\2\3package:\5')) |
164 | 171 |
165 # Replace '../*/pkg' imports and parts. | 172 # Replace '../*/pkg' imports and parts. |
166 for root, dirs, files in os.walk(os.path.join(tmpDir, pkgName)): | 173 for root, dirs, files in os.walk(os.path.join(tmpDir, pkgName)): |
167 # TODO(dgrove): Remove this when dartbug.com/7487 is fixed. | 174 # TODO(dgrove): Remove this when dartbug.com/7487 is fixed. |
168 if '.svn' in dirs: | 175 if '.svn' in dirs: |
169 shutil.rmtree(os.path.join(root, '.svn')) | 176 shutil.rmtree(os.path.join(root, '.svn')) |
170 for name in files: | 177 for name in files: |
171 if name.endswith('.dart'): | 178 if name.endswith('.dart'): |
172 ReplaceInFiles([os.path.join(root, name)], replaceInFiles) | 179 ReplaceInFiles([os.path.join(root, name)], replaceInDart) |
| 180 elif name == 'pubspec.yaml': |
| 181 ReplaceInFiles([os.path.join(root, name)], replaceInPubspec) |
173 | 182 |
174 print 'publishing version ' + version + ' of ' + argv[1] + ' to pub.\n' | 183 print 'publishing version ' + version + ' of ' + argv[1] + ' to pub.\n' |
175 subprocess.call(['pub', 'publish'], cwd=os.path.join(tmpDir, pkgName)) | 184 subprocess.call(['pub', 'publish'], cwd=os.path.join(tmpDir, pkgName)) |
176 shutil.rmtree(tmpDir) | 185 shutil.rmtree(tmpDir) |
177 | 186 |
178 if __name__ == '__main__': | 187 if __name__ == '__main__': |
179 sys.exit(Main(sys.argv)) | 188 sys.exit(Main(sys.argv)) |
OLD | NEW |