Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: tools/publish_pkg.py

Issue 59513007: Revert "add versions and constraints for packages and samples" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/publish_all_pkgs.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #
11 # "pub" must be in PATH. 11 # "pub" must be in PATH.
12 12
13 13
14 import os 14 import os
15 import os.path 15 import os.path
16 import re 16 import re
17 import shutil 17 import shutil
18 import sys 18 import sys
19 import subprocess 19 import subprocess
20 import tempfile 20 import tempfile
21 21
22 def ReplaceInFiles(paths, subs):
23 '''Reads a series of files, applies a series of substitutions to each, and
24 saves them back out. subs should be a list of (pattern, replace) tuples.'''
25 for path in paths:
26 contents = open(path).read()
27 for pattern, replace in subs:
28 contents = re.sub(pattern, replace, contents)
29
30 dest = open(path, 'w')
31 dest.write(contents)
32 dest.close()
33
34 def ReadVersion(file, field):
35 for line in open(file).read().split('\n'):
36 [k, v] = re.split('\s+', line)
37 if field == k:
38 return int(v)
39
22 def Main(argv): 40 def Main(argv):
23 HOME = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) 41 HOME = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
24 42
43 versionFile = os.path.join(HOME, 'tools', 'VERSION')
44 major = ReadVersion(versionFile, 'MAJOR')
45 minor = ReadVersion(versionFile, 'MINOR')
46 build = ReadVersion(versionFile, 'BUILD')
47 patch = ReadVersion(versionFile, 'PATCH')
48
49 # bleeding_edge has a fixed version number of 0.1.x.y . Don't allow users
50 # to publish packages from bleeding_edge.
51 if major == 0 and minor <= 1:
52 print 'Error: Do not run this script from a bleeding_edge checkout.'
53 return -1
54
55 if patch != 0:
56 version = '%d.%d.%d+%d' % (major, minor, build, patch)
57 else:
58 version = '%d.%d.%d' % (major, minor, build)
59
60 tmpDir = tempfile.mkdtemp()
25 pkgName = os.path.basename(os.path.normpath(argv[1])) 61 pkgName = os.path.basename(os.path.normpath(argv[1]))
26 62
27 pubspec = os.path.join(HOME, argv[1], 'pubspec.yaml') 63 pubspec = os.path.join(tmpDir, pkgName, 'pubspec.yaml')
28 if not os.path.exists(pubspec):
29 print 'Error: did not find pubspec.yaml at ' + pubspec
30 return -1
31 64
32 with open(pubspec) as pubspecFile: 65 replaceInDart = []
33 lines = pubspecFile.readlines() 66 replaceInPubspec = []
34 67
35 version = None 68 if os.path.exists(os.path.join(HOME, argv[1], 'pubspec.yaml')):
36 foundSdkContraint = False 69 #
37 inDependencies = False 70 # If pubspec.yaml exists, add the SDK's version number if
38 for line in lines: 71 # no version number is present.
39 if line.startswith('dependencies:'): 72 #
40 inDependencies = True 73 shutil.copytree(os.path.join(HOME, argv[1]),
41 elif line.startswith('environment:'): 74 os.path.join(tmpDir, pkgName))
42 foundSdkContraint = True 75 with open(pubspec) as pubspecFile:
43 elif line[0].isalpha(): 76 lines = pubspecFile.readlines()
77 with open(pubspec, 'w') as pubspecFile:
78 foundVersion = False
44 inDependencies = False 79 inDependencies = False
45 if line.startswith('version:'): 80 for line in lines:
46 version = line[len('version:'):].strip() 81 if line.startswith('dependencies:'):
47 if inDependencies: 82 inDependencies = True
48 if line.endswith(': any'): 83 elif line[0].isalpha():
49 print 'Error in %s: should not use "any" version constraint: %s' % ( 84 inDependencies = False
50 pubspec, line) 85 if line.startswith('version:'):
51 return -1 86 foundVersion = True
87 if inDependencies:
88 #
89 # Within dependencies, don't print line that start with " sdk:"
90 # and strip out "{ sdk: package_name }".
91 #
92 if not line.startswith(' sdk:'):
93 line = re.sub(r'{(\s*)sdk:(\s+)([a-z0-9_]+)(\s*)}', '', line)
94 pubspecFile.write(line)
95 else:
96 pubspecFile.write(line)
97 if not foundVersion:
98 pubspecFile.write('\nversion: ' + version + '\n')
99 pubspecFile.write('environment:\n')
100 pubspecFile.write(' sdk: ">=' + version + '"\n')
52 101
53 if not version: 102 else:
54 print 'Error in %s: did not find package version.' % pubspec 103 #
55 return -1 104 # If there's a lib/ directory in the package, copy the package.
105 # Otherwise, move the package's contents to lib/.
106 #
107 if os.path.exists(os.path.join(HOME, argv[1], 'lib')):
108 shutil.copytree(os.path.join(HOME, argv[1]),
109 os.path.join(tmpDir, pkgName))
110 else:
111 os.makedirs(os.path.join(tmpDir, pkgName))
112 shutil.copytree(os.path.join(HOME, argv[1]),
113 os.path.join(tmpDir, pkgName, 'lib'))
56 114
57 if not foundSdkContraint: 115 # Create pubspec.yaml .
58 print 'Error in %s: did not find SDK version constraint.' % pubspec 116 with open(pubspec, 'w') as pubspecFile:
59 return -1 117 pubspecFile.write('name: ' + pkgName + '_unsupported\n')
118 pubspecFile.write('author: None\n')
119 pubspecFile.write('homepage: http://None\n')
120 pubspecFile.write('version: ' + version + '\n')
121 pubspecFile.write("description: >\n")
122 pubspecFile.write(' A completely unsupported clone of Dart SDK library\n' )
123 pubspecFile.write(' ' + argv[1] + ' . This package will change in\n')
124 pubspecFile.write(' unpredictable/incompatible ways without warning.\n')
125 pubspecFile.write('dependencies:\n')
126 pubspecFile.write('environment:\n')
127 pubspecFile.write(' sdk: ">=' + version + '"\n')
60 128
61 tmpDir = tempfile.mkdtemp() 129 libpath = os.path.join(HOME, argv[1], '../libraries.dart')
130 if os.path.exists(libpath):
131 # Copy libraries.dart into the package source code
132 shutil.copy(libpath, os.path.join(tmpDir, pkgName, 'lib/libraries.dart'))
62 133
63 # 134 # Replace '../../libraries.dart' with '../libraries.dart'
64 # If pubspec.yaml exists, check that the SDK's version constraint is valid 135 replaceInDart.append(
65 # 136 (r'(import|part)(\s+)(\'|")\.\./(\.\./)*libraries.dart',
66 shutil.copytree(os.path.join(HOME, argv[1]), 137 r'\1\2\3\4libraries.dart'))
67 os.path.join(tmpDir, pkgName))
68 138
69 if not os.path.exists(os.path.join(tmpDir, pkgName, 'LICENSE')): 139 if not os.path.exists(os.path.join(tmpDir, pkgName, 'LICENSE')):
70 with open(os.path.join(tmpDir, pkgName, 'LICENSE'), 'w') as licenseFile: 140 with open(os.path.join(tmpDir, pkgName, 'LICENSE'), 'w') as licenseFile:
71 licenseFile.write( 141 licenseFile.write(
72 '''Copyright 2013, the Dart project authors. All rights reserved. 142 '''Copyright 2013, the Dart project authors. All rights reserved.
73 Redistribution and use in source and binary forms, with or without 143 Redistribution and use in source and binary forms, with or without
74 modification, are permitted provided that the following conditions are 144 modification, are permitted provided that the following conditions are
75 met: 145 met:
76 146
77 * Redistributions of source code must retain the above copyright 147 * Redistributions of source code must retain the above copyright
(...skipping 12 matching lines...) Expand all
90 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 160 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
91 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 161 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
92 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 162 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
93 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 163 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
94 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 164 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
95 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 165 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
96 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 166 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
97 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 167 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
98 '''); 168 ''');
99 169
170 replaceInDart.append(
171 (r'(import|part)(\s+)(\'|")(\.\./)+pkg/([^/]+/)lib/', r'\1\2\3package:\5'))
172
173 # Replace '../*/pkg' imports and parts.
174 for root, dirs, files in os.walk(os.path.join(tmpDir, pkgName)):
175 # TODO(dgrove): Remove this when dartbug.com/7487 is fixed.
176 if '.svn' in dirs:
177 shutil.rmtree(os.path.join(root, '.svn'))
178 for name in files:
179 if name.endswith('.dart'):
180 ReplaceInFiles([os.path.join(root, name)], replaceInDart)
181 elif name == 'pubspec.yaml':
182 ReplaceInFiles([os.path.join(root, name)], replaceInPubspec)
183
100 print 'publishing version ' + version + ' of ' + argv[1] + ' to pub.\n' 184 print 'publishing version ' + version + ' of ' + argv[1] + ' to pub.\n'
101
102 # TODO(jmesserly): this code puts things in the pub cache. Useful for testing
103 # without actually uploading.
104 #cacheDir = os.path.join(
105 # os.path.expanduser('~/.pub-cache/hosted/pub.dartlang.org'),
106 # pkgName + '-' + version)
107 #print 'Moving to ' + cacheDir
108 #shutil.move(os.path.join(tmpDir, pkgName), cacheDir)
109
110 subprocess.call(['pub', 'publish'], cwd=os.path.join(tmpDir, pkgName)) 185 subprocess.call(['pub', 'publish'], cwd=os.path.join(tmpDir, pkgName))
111 shutil.rmtree(tmpDir) 186 shutil.rmtree(tmpDir)
112 187
113 if __name__ == '__main__': 188 if __name__ == '__main__':
114 sys.exit(Main(sys.argv)) 189 sys.exit(Main(sys.argv))
OLDNEW
« no previous file with comments | « tools/publish_all_pkgs.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698