Flutter Engine
The Flutter Engine
Functions
publish_pkg Namespace Reference

Functions

def Main (argv)
 

Function Documentation

◆ Main()

def publish_pkg.Main (   argv)

Definition at line 21 of file publish_pkg.py.

21def Main(argv):
22 HOME = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
23
24 pkgName = os.path.basename(os.path.normpath(argv[1]))
25
26 pubspec = os.path.join(HOME, argv[1], 'pubspec.yaml')
27 if not os.path.exists(pubspec):
28 print('Error: did not find pubspec.yaml at ' + pubspec)
29 return -1
30
31 with open(pubspec) as pubspecFile:
32 lines = pubspecFile.readlines()
33
34 version = None
35 foundSdkConstraint = False
36 inDependencies = False
37 for line in lines:
38 if line.startswith('dependencies:'):
39 inDependencies = True
40 elif line.startswith('environment:'):
41 foundSdkConstraint = True
42 elif line[0].isalpha():
43 inDependencies = False
44 if line.startswith('version:'):
45 version = line[len('version:'):].strip()
46 if inDependencies:
47 if line.endswith(': any'):
48 print(
49 'Error in %s: should not use "any" version constraint: %s' %
50 (pubspec, line))
51 return -1
52
53 if not version:
54 print('Error in %s: did not find package version.' % pubspec)
55 return -1
56
57 if not foundSdkConstraint:
58 print('Error in %s: did not find SDK version constraint.' % pubspec)
59 return -1
60
61 tmpDir = tempfile.mkdtemp()
62
63 #
64 # If pubspec.yaml exists, check that the SDK's version constraint is valid
65 #
66 shutil.copytree(os.path.join(HOME, argv[1]), os.path.join(tmpDir, pkgName))
67
68 if not os.path.exists(os.path.join(tmpDir, pkgName, 'LICENSE')):
69 with open(os.path.join(tmpDir, pkgName, 'LICENSE'), 'w') as licenseFile:
70 licenseFile.write(
71 '''Copyright 2014, the Dart project authors. All rights reserved.
72Redistribution and use in source and binary forms, with or without
73modification, are permitted provided that the following conditions are
74met:
75
76 * Redistributions of source code must retain the above copyright
77 notice, this list of conditions and the following disclaimer.
78 * Redistributions in binary form must reproduce the above
79 copyright notice, this list of conditions and the following
80 disclaimer in the documentation and/or other materials provided
81 with the distribution.
82 * Neither the name of Google Inc. nor the names of its
83 contributors may be used to endorse or promote products derived
84 from this software without specific prior written permission.
85
86THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
87"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
88LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
89A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
90OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
91SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
92LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
93DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
94THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
95(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
96OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
97''')
98
99 print('publishing version ' + version + ' of ' + argv[1] + ' to pub.\n')
100
101 # TODO(jmesserly): this code puts things in the pub cache. Useful for testing
102 # without actually uploading.
103 #cacheDir = os.path.join(
104 # os.path.expanduser('~/.pub-cache/hosted/pub.dartlang.org'),
105 # pkgName + '-' + version)
106 #print 'Moving to ' + cacheDir
107 #shutil.move(os.path.join(tmpDir, pkgName), cacheDir)
108
109 subprocess.call(['pub', 'publish'], cwd=os.path.join(tmpDir, pkgName))
110 shutil.rmtree(tmpDir)
111
112
def Main(argv)
Definition: publish_pkg.py:21
def print(*args, **kwargs)
Definition: run_tests.py:49