mirror of
https://github.com/google/blockly.git
synced 2026-01-09 01:50:11 +01:00
Merge pull request #2661 from alschmiedt/build_script_merge
Adds ability to pick renderer at build time
This commit is contained in:
106
build.py
106
build.py
@@ -34,7 +34,6 @@
|
||||
# been renamed. The uncompressed file also allows for a faster development
|
||||
# cycle since there is no need to rebuild or recompile, just reload.
|
||||
#
|
||||
#
|
||||
# This script also generates:
|
||||
# blocks_compressed.js: The compressed Blockly language blocks.
|
||||
# javascript_compressed.js: The compressed JavaScript generator.
|
||||
@@ -46,15 +45,8 @@
|
||||
|
||||
import sys
|
||||
|
||||
for arg in sys.argv[1:len(sys.argv)]:
|
||||
if (arg != 'core' and
|
||||
arg != 'accessible' and
|
||||
arg != 'generators' and
|
||||
arg != 'langfiles'):
|
||||
raise Exception("Invalid argument: \"" + arg + "\". Usage: build.py "
|
||||
"<0 or more of core, generators, langfiles>")
|
||||
|
||||
import errno, glob, json, os, re, subprocess, threading, codecs
|
||||
import errno, glob, json, os, re, subprocess, threading, codecs, argparse
|
||||
from cStringIO import StringIO
|
||||
|
||||
if sys.version_info[0] == 2:
|
||||
import httplib
|
||||
@@ -186,23 +178,20 @@ class Gen_compressed(threading.Thread):
|
||||
Uses the Closure Compiler's online API.
|
||||
Runs in a separate thread.
|
||||
"""
|
||||
def __init__(self, search_paths, bundles):
|
||||
def __init__(self, search_paths, bundles, use_default):
|
||||
threading.Thread.__init__(self)
|
||||
self.search_paths = search_paths
|
||||
self.bundles = bundles
|
||||
self.use_default = use_default
|
||||
|
||||
def run(self):
|
||||
if ('core' in self.bundles):
|
||||
if (self.bundles.core or self.use_default):
|
||||
self.gen_core()
|
||||
|
||||
if ('accessible' in self.bundles):
|
||||
print("The Blockly accessibility demo has moved to https://github.com/google/blockly-experimental")
|
||||
return
|
||||
|
||||
if ('core' in self.bundles):
|
||||
if (self.bundles.core or self.use_default):
|
||||
self.gen_blocks()
|
||||
|
||||
if ('generators' in self.bundles):
|
||||
if (self.bundles.generators or self.use_default):
|
||||
self.gen_generator("javascript")
|
||||
self.gen_generator("python")
|
||||
self.gen_generator("php")
|
||||
@@ -489,9 +478,66 @@ class Gen_langfiles(threading.Thread):
|
||||
else:
|
||||
print("FAILED to create " + f)
|
||||
|
||||
# Class to hold arguments if user passes in old argument style.
|
||||
class Arguments:
|
||||
def __init__(self):
|
||||
self.core = False
|
||||
self.generators = False
|
||||
self.langfiles = False
|
||||
self.render_name = "block_rendering_rewrite"
|
||||
|
||||
# Add all directories to the path list except for any extra renderers.
|
||||
def find_path(args, directories):
|
||||
new_list = []
|
||||
render_path = 'core/renderers/' + args.render_name
|
||||
core_search_paths = calcdeps.ExpandDirectories(directories)
|
||||
for path in core_search_paths:
|
||||
# If it is the desired renderer
|
||||
if path.find('core/renderers') > -1 and path.find(render_path) > -1:
|
||||
new_list.append(path)
|
||||
# If it is not a renderer
|
||||
elif (path.find('core/renderers') == -1):
|
||||
new_list.append(path)
|
||||
return sorted(new_list)
|
||||
|
||||
# Setup the argument parser.
|
||||
def setup_parser():
|
||||
parser = argparse.ArgumentParser(description="Decide which files to build with what renderer.")
|
||||
parser.add_argument('-renderer', dest="render_name", default="block_rendering_rewrite", help="The name of the desired renderer. The name should corresspond to the name of a folder in core/renderers")
|
||||
parser.add_argument('-core', action="store_true", default=False, help="Build core")
|
||||
parser.add_argument('-generators', action="store_true", default=False, help="Build the generators")
|
||||
parser.add_argument('-langfiles', action="store_true", default=False, help="Build all the language files")
|
||||
return parser
|
||||
|
||||
# Gets the command line arguments.
|
||||
# If the user passes in the old style or arguments we create the arguments object
|
||||
# otherwise the argument object is created from the ArgumentParser.
|
||||
def get_args():
|
||||
parser = setup_parser()
|
||||
try:
|
||||
args = parser.parse_args()
|
||||
except SystemExit:
|
||||
args = Arguments()
|
||||
args.core = 'core' in sys.argv
|
||||
args.generators = 'generators' in sys.argv
|
||||
args.langfiles = 'langfiles' in sys.argv
|
||||
if 'accessible' in sys.argv:
|
||||
print("The Blockly accessibility demo has moved to https://github.com/google/blockly-experimental")
|
||||
if '-renderer' in sys.argv:
|
||||
print ("Please use the new arguments -core, -generators, -langfiles")
|
||||
sys.exit()
|
||||
verify_render_name(args.render_name)
|
||||
return args
|
||||
|
||||
# Verify that the passed in renderer name can be found in the renderers directory.
|
||||
def verify_render_name(render_name):
|
||||
if (not render_name in next(os.walk('core/renderers'))[1]):
|
||||
print (render_name + " is not a valid renderer.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
args = get_args()
|
||||
use_default = not args.core and not args.generators and not args.langfiles
|
||||
calcdeps = import_path(os.path.join(
|
||||
os.path.pardir, "closure-library", "closure", "bin", "calcdeps.py"))
|
||||
except ImportError:
|
||||
@@ -512,28 +558,18 @@ if __name__ == "__main__":
|
||||
developers.google.com/blockly/guides/modify/web/closure""")
|
||||
sys.exit(1)
|
||||
|
||||
core_search_paths = calcdeps.ExpandDirectories(
|
||||
["core", os.path.join(os.path.pardir, "closure-library")])
|
||||
core_search_paths = sorted(core_search_paths) # Deterministic build.
|
||||
full_search_paths = calcdeps.ExpandDirectories(
|
||||
["core", os.path.join(os.path.pardir, "closure-library")])
|
||||
full_search_paths = sorted(full_search_paths) # Deterministic build.
|
||||
|
||||
if (len(sys.argv) == 1):
|
||||
args = ['core', 'generators', 'defaultlangfiles']
|
||||
else:
|
||||
args = sys.argv
|
||||
full_search_paths = find_path(args, ["core", os.path.join(os.path.pardir, "closure-library")])
|
||||
|
||||
# Uncompressed and compressed are run in parallel threads.
|
||||
# Uncompressed is limited by processor speed.
|
||||
if ('core' in args):
|
||||
Gen_uncompressed(core_search_paths, 'blockly_uncompressed.js').start()
|
||||
if (args.core or use_default):
|
||||
Gen_uncompressed(full_search_paths, 'blockly_uncompressed.js').start()
|
||||
|
||||
# Compressed is limited by network and server speed.
|
||||
Gen_compressed(full_search_paths, args).start()
|
||||
Gen_compressed(full_search_paths, args, use_default).start()
|
||||
|
||||
# This is run locally in a separate thread
|
||||
# defaultlangfiles checks for changes in the msg files, while manually asking
|
||||
# to build langfiles will force the messages to be rebuilt.
|
||||
if ('langfiles' in args or 'defaultlangfiles' in args):
|
||||
Gen_langfiles('langfiles' in args).start()
|
||||
# to build langfiles will force the messages to be rebuilt
|
||||
if (args.langfiles or use_default):
|
||||
Gen_langfiles(args.langfiles).start()
|
||||
|
||||
Reference in New Issue
Block a user