@@ -49,47 +49,54 @@ def add_file(bundle, src_file, zip_name):
4949
5050
5151def build_bundle (libs , bundle_version , output_filename ,
52- build_tools_version = "devel" , mpy_cross = None ):
52+ build_tools_version = "devel" , mpy_cross = None , example_bundle = False ):
5353 build_dir = "build-" + os .path .basename (output_filename )
54- build_lib_dir = os .path .join (build_dir , "lib" )
54+ build_lib_dir = os .path .join (build_dir , build_dir .replace (".zip" , "" ), "lib" )
55+ build_example_dir = os .path .join (build_dir , build_dir .replace (".zip" , "" ), "examples" )
5556 if os .path .isdir (build_dir ):
5657 print ("Deleting existing build." )
5758 shutil .rmtree (build_dir )
58- os .makedirs (build_lib_dir )
59+ total_size = 0
60+ if not example_bundle :
61+ os .makedirs (build_lib_dir )
62+ total_size += 512
63+ os .makedirs (build_example_dir )
64+ total_size += 512
5965
6066 multiple_libs = len (libs ) > 1
6167
6268 success = True
63- total_size = 512
6469 for library_path in libs :
6570 try :
66- build .library (library_path , build_lib_dir , mpy_cross = mpy_cross )
71+ build .library (library_path , build_lib_dir , mpy_cross = mpy_cross ,
72+ example_bundle = example_bundle )
6773 except ValueError as e :
68- print (library_path )
74+ print ("build.library failure:" , library_path )
6975 print (e )
7076 success = False
7177
7278 print ()
73- print ("Generating VERSIONS" )
74- if multiple_libs :
75- with open (os .path .join (build_lib_dir , "VERSIONS.txt" ), "w" ) as f :
76- f .write (bundle_version + "\r \n " )
77- versions = subprocess .run ('git submodule foreach \" git remote get-url origin && git describe --tags\" ' , shell = True , stdout = subprocess .PIPE )
78- if versions .returncode != 0 :
79- print ("Failed to generate versions file. Its likely a library hasn't been "
80- "released yet." )
81- success = False
82-
83- repo = None
84- for line in versions .stdout .split (b"\n " ):
85- if line .startswith (b"Entering" ) or not line :
86- continue
87- if line .startswith (b"git@" ):
88- repo = b"https://github.com/" + line .split (b":" )[1 ][:- len (".git" )]
89- elif line .startswith (b"https:" ):
90- repo = line .strip ()[:- len (".git" )]
91- else :
92- f .write (repo .decode ("utf-8" , "strict" ) + "/releases/tag/" + line .strip ().decode ("utf-8" , "strict" ) + "\r \n " )
79+ if not example_bundle :
80+ print ("Generating VERSIONS" )
81+ if multiple_libs :
82+ with open (os .path .join (build_lib_dir , "VERSIONS.txt" ), "w" ) as f :
83+ f .write (bundle_version + "\r \n " )
84+ versions = subprocess .run ('git submodule foreach \" git remote get-url origin && git describe --tags\" ' , shell = True , stdout = subprocess .PIPE )
85+ if versions .returncode != 0 :
86+ print ("Failed to generate versions file. Its likely a library hasn't been "
87+ "released yet." )
88+ success = False
89+
90+ repo = None
91+ for line in versions .stdout .split (b"\n " ):
92+ if line .startswith (b"Entering" ) or not line :
93+ continue
94+ if line .startswith (b"git@" ):
95+ repo = b"https://github.com/" + line .split (b":" )[1 ][:- len (".git" )]
96+ elif line .startswith (b"https:" ):
97+ repo = line .strip ()[:- len (".git" )]
98+ else :
99+ f .write (repo .decode ("utf-8" , "strict" ) + "/releases/tag/" + line .strip ().decode ("utf-8" , "strict" ) + "\r \n " )
93100
94101 if not success :
95102 print ("WARNING: some failures above" )
@@ -103,7 +110,7 @@ def build_bundle(libs, bundle_version, output_filename,
103110 bundle .comment = json .dumps (build_metadata ).encode ("utf-8" )
104111 if multiple_libs :
105112 total_size += add_file (bundle , "README.txt" , "lib/README.txt" )
106- for root , dirs , files in os .walk (build_lib_dir ):
113+ for root , dirs , files in os .walk (build_dir ):
107114 ziproot = root [len (build_dir + "/" ):].replace ("-" , "_" )
108115 for filename in files :
109116 total_size += add_file (bundle , os .path .join (root , filename ),
@@ -146,11 +153,14 @@ def build_bundles(filename_prefix, output_directory, library_location, library_d
146153 with open (build_tools_fn , "w" ) as f :
147154 f .write (build_tools_version )
148155
156+ # Build raw source .py bundle
149157 zip_filename = os .path .join (output_directory ,
150158 filename_prefix + '-py-{VERSION}.zip' .format (
151159 VERSION = bundle_version ))
152160 build_bundle (libs , bundle_version , zip_filename ,
153161 build_tools_version = build_tools_version )
162+
163+ # Build .mpy bundle(s)
154164 os .makedirs ("build_deps" , exist_ok = True )
155165 for version in target_versions .VERSIONS :
156166 # Use prebuilt mpy-cross on Travis, otherwise build our own.
@@ -166,3 +176,10 @@ def build_bundles(filename_prefix, output_directory, library_location, library_d
166176 VERSION = bundle_version ))
167177 build_bundle (libs , bundle_version , zip_filename , mpy_cross = mpy_cross ,
168178 build_tools_version = build_tools_version )
179+
180+ # Build example bundle
181+ zip_filename = os .path .join (output_directory ,
182+ filename_prefix + '-examples-{VERSION}.zip' .format (
183+ VERSION = bundle_version ))
184+ build_bundle (libs , bundle_version , zip_filename ,
185+ build_tools_version = build_tools_version , example_bundle = True )
0 commit comments