@@ -49,37 +49,43 @@ 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 ()
7379 print ("Generating VERSIONS" )
7480 if multiple_libs :
75- with open (os .path .join (build_lib_dir , "VERSIONS.txt" ), "w" ) as f :
81+ with open (os .path .join (build_dir , build_dir . replace ( ".zip" , "" ) , "VERSIONS.txt" ), "w" ) as f :
7682 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 )
83+ versions = subprocess .run ('git submodule foreach \" git remote get-url origin && git describe --tags\" ' , shell = True , stdout = subprocess .PIPE , cwd = os . path . commonpath ( libs ) )
7884 if versions .returncode != 0 :
7985 print ("Failed to generate versions file. Its likely a library hasn't been "
8086 "released yet." )
8187 success = False
82-
88+
8389 repo = None
8490 for line in versions .stdout .split (b"\n " ):
8591 if line .startswith (b"Entering" ) or not line :
@@ -103,7 +109,7 @@ def build_bundle(libs, bundle_version, output_filename,
103109 bundle .comment = json .dumps (build_metadata ).encode ("utf-8" )
104110 if multiple_libs :
105111 total_size += add_file (bundle , "README.txt" , "lib/README.txt" )
106- for root , dirs , files in os .walk (build_lib_dir ):
112+ for root , dirs , files in os .walk (build_dir ):
107113 ziproot = root [len (build_dir + "/" ):].replace ("-" , "_" )
108114 for filename in files :
109115 total_size += add_file (bundle , os .path .join (root , filename ),
@@ -146,11 +152,14 @@ def build_bundles(filename_prefix, output_directory, library_location, library_d
146152 with open (build_tools_fn , "w" ) as f :
147153 f .write (build_tools_version )
148154
155+ # Build raw source .py bundle
149156 zip_filename = os .path .join (output_directory ,
150157 filename_prefix + '-py-{VERSION}.zip' .format (
151158 VERSION = bundle_version ))
152159 build_bundle (libs , bundle_version , zip_filename ,
153160 build_tools_version = build_tools_version )
161+
162+ # Build .mpy bundle(s)
154163 os .makedirs ("build_deps" , exist_ok = True )
155164 for version in target_versions .VERSIONS :
156165 # Use prebuilt mpy-cross on Travis, otherwise build our own.
@@ -166,3 +175,10 @@ def build_bundles(filename_prefix, output_directory, library_location, library_d
166175 VERSION = bundle_version ))
167176 build_bundle (libs , bundle_version , zip_filename , mpy_cross = mpy_cross ,
168177 build_tools_version = build_tools_version )
178+
179+ # Build example bundle
180+ zip_filename = os .path .join (output_directory ,
181+ filename_prefix + '-examples-{VERSION}.zip' .format (
182+ VERSION = bundle_version ))
183+ build_bundle (libs , bundle_version , zip_filename ,
184+ build_tools_version = build_tools_version , example_bundle = True )
0 commit comments