~ubuntu-branches/ubuntu/trusty/emscripten/trusty-proposed

« back to all changes in this revision

Viewing changes to .pc/pythonpath.diff/emcc

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2014-01-19 14:12:40 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20140119141240-jg1l42cc158j59tn
Tags: 1.9.0~20140119~7dc8c2f-1
* New snapshot release (Closes: #733714)
* Provide sources for javascript and flash. Done in orig-tar.sh
  Available in third_party/websockify/include/web-socket-js/src/
  (Closes: #735903)

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
import os, sys, shutil, tempfile, subprocess, shlex, time, re, logging
51
51
from subprocess import PIPE, STDOUT
52
52
from tools import shared, jsrun
53
 
from tools.shared import Compression, execute, suffix, unsuffixed, unsuffixed_basename
 
53
from tools.shared import Compression, execute, suffix, unsuffixed, unsuffixed_basename, WINDOWS
54
54
from tools.response_file import read_response_file
55
55
 
56
 
CXX_SUFFIXES = ('.cpp', '.cxx', '.cc')
57
 
SOURCE_SUFFIXES = ('.c', '.cpp', '.cxx', '.cc', '.m', '.mm')
58
 
BITCODE_SUFFIXES = ('.bc', '.o', '.obj')
59
 
DYNAMICLIB_SUFFIXES = ('.dylib', '.so', '.dll')
60
 
STATICLIB_SUFFIXES = ('.a',)
61
 
ASSEMBLY_SUFFIXES = ('.ll',)
 
56
# endings = dot + a suffix, safe to test by  filename.endswith(endings)
 
57
C_ENDINGS = ('.c', '.C')
 
58
CXX_ENDINGS = ('.cpp', '.cxx', '.cc', '.CPP', '.CXX', '.CC')
 
59
SOURCE_ENDINGS = C_ENDINGS + CXX_ENDINGS + ('.m', '.mm')
 
60
BITCODE_ENDINGS = ('.bc', '.o', '.obj')
 
61
DYNAMICLIB_ENDINGS = ('.dylib', '.so', '.dll')
 
62
STATICLIB_ENDINGS = ('.a',)
 
63
ASSEMBLY_ENDINGS = ('.ll',)
 
64
 
62
65
LIB_PREFIXES = ('', 'lib')
 
66
 
63
67
JS_CONTAINING_SUFFIXES = ('js', 'html')
64
68
 
65
69
# Mapping of emcc opt levels to llvm opt levels. We use llvm opt level 3 in emcc opt
127
131
  --version                Display compiler version information
128
132
 
129
133
Options that are modified or new in %s include:
130
 
  -O0                      No optimizations (default)
 
134
 
 
135
  -O0                      No optimizations (default). This is the recommended
 
136
                           setting for starting to port a project, as it
 
137
                           includes various assertions.
 
138
 
131
139
  -O1                      Simple optimizations, including asm.js, LLVM -O1
132
 
                           optimizations, and no runtime assertions
 
140
                           optimizations, relooping, and no runtime assertions
133
141
                           or C++ exception catching (to re-enable
134
142
                           C++ exception catching, use
135
 
                           -s DISABLE_EXCEPTION_CATCHING=0 ).
136
 
                           (For details on the affects of different
 
143
                           -s DISABLE_EXCEPTION_CATCHING=0 ), and enables
 
144
 
 
145
                              -s ALIASING_FUNCTION_POINTERS=1
 
146
 
 
147
                           This is the recommended setting when you want a
 
148
                           reasonably optimized build that is generated as
 
149
                           quickly as possible (it is much faster than -O2).
 
150
 
 
151
                           (Note: for details on the affects of different
137
152
                           opt levels, see apply_opt_level() in
138
153
                           tools/shared.py and also src/settings.js.)
139
 
  -O2                      As -O1, plus the relooper (loop recreation),
140
 
                           LLVM -O3 optimizations, and
141
154
 
142
 
                              -s ALIASING_FUNCTION_POINTERS=1
 
155
  -O2                      As -O1, plus various js-level optimizations and
 
156
                           LLVM -O3 optimizations. This is the recommended
 
157
                           setting for a release build: slower compilation
 
158
                           time in return for the smallest and fastest
 
159
                           output.
143
160
 
144
161
  -O3                      As -O2, plus dangerous optimizations that may
145
162
                           break the generated code! This adds
227
244
                           2: -O2 LLVM optimizations
228
245
                           3: -O3 LLVM optimizations (default in -O2+)
229
246
 
 
247
                           You can also specify arbitrary LLVM options, e.g.
 
248
 
 
249
                             --llvm-opts "['-O3', '-somethingelse']"
 
250
 
230
251
  --llvm-lto <level>       0: No LLVM LTO (default)
231
252
                           1: LLVM LTO is performed
232
253
                           2: We combine all the bitcode and run LLVM opt -O3
238
259
                           (see --llvm-opts), setting this has no
239
260
                           effect.
240
261
 
 
262
                           Note that LLVM LTO is not perfectly stable yet,
 
263
                           and can can cause code to behave incorrectly.
 
264
 
241
265
  --closure <on>           0: No closure compiler (default in -O2 and below)
242
266
                           1: Run closure compiler. This greatly reduces
243
267
                           code size and may in some cases increase
255
279
                           try adjusting JAVA_HEAP_SIZE in the environment
256
280
                           (for example, to 4096m for 4GB).
257
281
 
 
282
                           Note: Closure is only run if js opts are being
 
283
                           done (-O2 or above, or --js-opts 1).
 
284
 
258
285
  --js-transform <cmd>     <cmd> will be called on the generated code
259
286
                           before it is optimized. This lets you modify
260
287
                           the JavaScript, for example adding some code
317
344
                           For more docs on the options --preload-file
318
345
                           accepts, see  https://github.com/kripken/emscripten/wiki/Filesystem-Guide
319
346
 
320
 
  --compression <codec>    Compress both the compiled code and embedded/
 
347
  --exclude-file <name>   Files and directories to be excluded from 
 
348
                           --embed-file and --preload-file
 
349
                           wildcard is supported
 
350
 
 
351
  --compression <codec>    **THIS OPTION IS DEPRECATED**
 
352
 
 
353
                           Compress both the compiled code and embedded/
321
354
                           preloaded files. <codec> should be a triple,
322
355
 
323
356
                              <native_encoder>,<js_decoder>,<js_name>
374
407
  --shell-file <path>      The path name to a skeleton HTML file used
375
408
                           when generating HTML output. The shell file
376
409
                           used needs to have this token inside it:
377
 
                           {{{ SCRIPT_CODE }}}
 
410
                           {{{ SCRIPT }}}
 
411
                           (see src/shell.html for an example)
378
412
                           Note that this argument is ignored if a
379
413
                           target other than HTML is specified using
380
414
                           the -o option.
474
508
  --proxy-to-worker        Generates both html and js files. The main
475
509
                           program is in js, and the html proxies to/from it.
476
510
 
 
511
  --emrun                  Enables the generated output to be aware of the
 
512
                           emrun command line tool. This allows stdout, stderr
 
513
                           and exit(returncode) capture when running the
 
514
                           generated application through emrun.
 
515
 
 
516
  --em-config              Specifies the location of the .emscripten configuration
 
517
                           file for the current compiler run. If not specified,
 
518
                           the environment variable EM_CONFIG is read for this
 
519
                           file, and if that is not set, the default location
 
520
                           ~/.emscripten is assumed.
 
521
 
 
522
  --default-obj-ext .ext   Specifies the file suffix to generate if the location
 
523
                           of a directory name is passed to -o directive, e.g.
 
524
                             emcc -c a.c -o dir/
 
525
                           will by default generate an output name 'dir/a.o', 
 
526
                           but this cmdline param can be passed to generate a
 
527
                           file with a custom suffix 'dir/a.ext'. 
 
528
 
477
529
The target file, if specified (-o <target>), defines what will
478
530
be generated:
479
531
 
480
532
  <name>.js                JavaScript
481
 
  <name>.html              HTML with embedded JavaScript
 
533
  <name>.html              HTML + side JavaScript file (<name>.js)
 
534
                             (JS on the side improves page load time)
482
535
  <name>.bc                LLVM bitcode (default)
483
536
  <name>.o                 LLVM bitcode (same as .bc)
484
537
 
519
572
  exit(0)  
520
573
 
521
574
elif len(sys.argv) == 2 and sys.argv[1] == '-v': # -v with no inputs
522
 
  print 'emcc (Emscripten GCC-like replacement + linker emulating GNU ld ) 2.0'
 
575
  print 'emcc (Emscripten GCC-like replacement + linker emulating GNU ld ) %s' % shared.EMSCRIPTEN_VERSION
523
576
  exit(subprocess.call([shared.CLANG, '-v']))
524
577
 
525
578
def is_minus_s_for_emcc(newargs,i):
556
609
    elif arg.endswith('.s'):
557
610
      if debug_configure: open(tempout, 'a').write('(compiling .s assembly, must use clang\n')
558
611
      use_js = 0
 
612
    elif arg == '-E':
 
613
      use_js = 0
559
614
 
560
615
  if src:
561
616
    if 'fopen' in src and '"w"' in src:
632
687
CC_ADDITIONAL_ARGS = shared.COMPILER_OPTS
633
688
 
634
689
EMMAKEN_CFLAGS = os.environ.get('EMMAKEN_CFLAGS')
635
 
if EMMAKEN_CFLAGS: CC_ADDITIONAL_ARGS += shlex.split(EMMAKEN_CFLAGS)
 
690
if EMMAKEN_CFLAGS: sys.argv += shlex.split(EMMAKEN_CFLAGS)
636
691
 
637
692
# ---------------- Utilities ---------------
638
693
 
669
724
if '-E' in sys.argv:
670
725
  # Just run the preprocessor
671
726
  cmd = [CC] + sys.argv[1:]
672
 
  logging.debug('just preprocssor ' + ' '.join(cmd))
 
727
  logging.debug('just preprocessor ' + ' '.join(cmd))
673
728
  exit(subprocess.call(cmd))
674
729
 
675
730
# Check if a target is specified
715
770
def in_temp(name):
716
771
  return os.path.join(temp_dir, os.path.basename(name))
717
772
 
 
773
# Parses the essential suffix of a filename, discarding Unix-style version numbers in the name. For example for 'libz.so.1.2.8' returns '.so'
 
774
def filename_type_suffix(filename):
 
775
  for i in reversed(filename.split('.')[1:]):
 
776
    if not i.isdigit():
 
777
      return i
 
778
  return ''
 
779
 
 
780
def filename_type_ending(filename):
 
781
  suffix = filename_type_suffix(filename)
 
782
  return '' if not suffix else ('.' + suffix)
 
783
 
718
784
try:
719
785
  call = CXX if use_cxx else CC
720
786
 
734
800
  split_js_file = None
735
801
  preload_files = []
736
802
  embed_files = []
 
803
  exclude_files = []
737
804
  compression = None
738
805
  ignore_dynamic_linking = False
739
806
  shell_path = shared.path_from_root('src', 'shell.html')
740
807
  js_libraries = []
741
808
  bind = False
 
809
  emrun = False
742
810
  jcache = False
743
811
  save_bc = False
744
812
  memory_init_file = False
745
813
  use_preload_cache = False
 
814
  no_heap_copy = False
746
815
  proxy_to_worker = False
 
816
  default_object_extension = '.o'
747
817
 
748
818
  if use_cxx:
749
819
    default_cxx_std = '-std=c++03' # Enforce a consistent C++ standard when compiling .cpp files, if user does not specify one on the cmdline.
848
918
      preload_files.append(newargs[i+1])
849
919
      newargs[i] = ''
850
920
      newargs[i+1] = ''
 
921
    elif newargs[i].startswith('--exclude-file'):
 
922
      check_bad_eq(newargs[i])
 
923
      exclude_files.append(newargs[i+1])
 
924
      newargs[i] = ''
 
925
      newargs[i+1] = ''
851
926
    elif newargs[i].startswith('--compression'):
 
927
      logging.warning('--compression is deprecated. Instead, it is recommended you use native gzip compression in your webserver')
852
928
      check_bad_eq(newargs[i])
853
929
      parts = newargs[i+1].split(',')
854
930
      assert len(parts) == 3, '--compression requires specifying    native_encoder,js_decoder,js_name  - see emcc --help. got: %s' % newargs[i+1]
855
 
      Compression.encoder = parts[0]
856
 
      Compression.decoder = parts[1]
 
931
      def locate(tool):
 
932
        if WINDOWS:
 
933
          if os.path.exists(tool+'.exe'):
 
934
            return tool+'.exe'
 
935
          if os.path.exists(tool+'.bat'):
 
936
            return tool+'.bat'
 
937
          if os.path.exists(tool+'.cmd'):
 
938
            return tool+'.cmd'
 
939
        return tool
 
940
      Compression.encoder = locate(parts[0])
 
941
      Compression.decoder = locate(parts[1])
857
942
      Compression.js_name = parts[2]
858
943
      assert os.path.exists(Compression.encoder), 'native encoder %s does not exist' % Compression.encoder
859
944
      assert os.path.exists(Compression.decoder), 'js decoder %s does not exist' % Compression.decoder
863
948
    elif newargs[i].startswith('--use-preload-cache'):
864
949
      use_preload_cache = True
865
950
      newargs[i] = ''
 
951
    elif newargs[i].startswith('--no-heap-copy'):
 
952
      no_heap_copy = True
 
953
      newargs[i] = ''
866
954
    elif newargs[i] == '--ignore-dynamic-linking':
867
955
      ignore_dynamic_linking = True
868
956
      newargs[i] = ''
915
1003
      if not absolute_warning_shown and os.path.isabs(path_name):
916
1004
        logging.warning ('-I or -L of an absolute path "' + newargs[i] + '" encountered. If this is to a local system header/library, it may cause problems (local system files make sense for compiling natively on your system, but not necessarily to JavaScript). Pass \'-Wno-warn-absolute-paths\' to emcc to hide this warning.') # Of course an absolute path to a non-system-specific library or header is fine, and you can ignore this warning. The danger are system headers that are e.g. x86 specific and nonportable. The emscripten bundled headers are modified to be portable, local system ones are generally not
917
1005
        absolute_warning_shown = True
 
1006
    elif newargs[i] == '--emrun':
 
1007
      emrun = True
 
1008
      newargs[i] = ''
 
1009
    elif newargs[i] == '--em-config':
 
1010
      # This option is parsed in tools/shared.py, here only clean it up from being passed to clang.
 
1011
      newargs[i] = ''
 
1012
      newargs[i+1] = ''
 
1013
    elif newargs[i] == '--default-obj-ext':
 
1014
      newargs[i] = ''
 
1015
      default_object_extension = newargs[i+1]
 
1016
      if not default_object_extension.startswith('.'):
 
1017
        default_object_extension = '.' + default_object_extension
 
1018
      newargs[i+1] = ''
 
1019
 
918
1020
  newargs = [ arg for arg in newargs if arg is not '' ]
919
1021
 
920
1022
  # If user did not specify a default -std for C++ code, specify the emscripten default.
921
1023
  if default_cxx_std:
922
1024
    newargs = newargs + [default_cxx_std]
923
1025
 
924
 
  if js_opts is None: js_opts = True
 
1026
  if emrun:
 
1027
    pre_js += open(shared.path_from_root('src', 'emrun_prejs.js')).read() + '\n'
 
1028
    post_js += open(shared.path_from_root('src', 'emrun_postjs.js')).read() + '\n'
 
1029
 
 
1030
  if js_opts is None: js_opts = opt_level >= 2
925
1031
  if llvm_opts is None: llvm_opts = LLVM_OPT_LEVEL[opt_level]
926
1032
  if llvm_lto is None and opt_level >= 3: llvm_lto = 3
927
1033
  if opt_level == 0: debug_level = 4
969
1075
 
970
1076
    if i > 0:
971
1077
      prev = newargs[i-1]
972
 
      if prev in ['-MT', '-MF', '-MQ', '-D', '-U', '-o', '-x', '-Xpreprocessor', '-include', '-imacros', '-idirafter', '-iprefix', '-iwithprefix', '-iwithprefixbefore', '-isysroot', '-imultilib', '-A', '-isystem', '-iquote', '-install_name', '-I', '-L']: continue # ignore this gcc-style argument
 
1078
      if prev in ['-MT', '-MF', '-MQ', '-D', '-U', '-o', '-x', '-Xpreprocessor', '-include', '-imacros', '-idirafter', '-iprefix', '-iwithprefix', '-iwithprefixbefore', '-isysroot', '-imultilib', '-A', '-isystem', '-iquote', '-install_name', '-compatibility_version', '-current_version', '-I', '-L']: continue # ignore this gcc-style argument
973
1079
 
974
 
    if (os.path.islink(arg) and os.path.realpath(arg).endswith(SOURCE_SUFFIXES + BITCODE_SUFFIXES + DYNAMICLIB_SUFFIXES + ASSEMBLY_SUFFIXES)):
 
1080
    if (os.path.islink(arg) and os.path.realpath(arg).endswith(SOURCE_ENDINGS + BITCODE_ENDINGS + DYNAMICLIB_ENDINGS + ASSEMBLY_ENDINGS)):
975
1081
      arg = os.path.realpath(arg)
976
1082
 
977
 
    if not arg.startswith('-') and (arg.endswith(SOURCE_SUFFIXES + BITCODE_SUFFIXES + DYNAMICLIB_SUFFIXES + ASSEMBLY_SUFFIXES) or shared.Building.is_ar(arg)): # we already removed -o <target>, so all these should be inputs
978
 
      newargs[i] = ''
979
 
      if os.path.exists(arg):
980
 
        if arg.endswith(SOURCE_SUFFIXES):
 
1083
    if not arg.startswith('-'):
 
1084
      if not os.path.exists(arg):
 
1085
        logging.error('%s: No such file or directory ("%s" was expected to be an input file, based on the commandline arguments provided)' % (arg, arg))
 
1086
        exit(1)
 
1087
 
 
1088
      arg_ending = filename_type_ending(arg)
 
1089
      if arg_ending.endswith(SOURCE_ENDINGS + BITCODE_ENDINGS + DYNAMICLIB_ENDINGS + ASSEMBLY_ENDINGS) or shared.Building.is_ar(arg): # we already removed -o <target>, so all these should be inputs
 
1090
        newargs[i] = ''
 
1091
        if arg_ending.endswith(SOURCE_ENDINGS):
981
1092
          input_files.append(arg)
982
1093
          has_source_inputs = True
 
1094
        elif arg_ending.endswith(ASSEMBLY_ENDINGS) or shared.Building.is_bitcode(arg): # this should be bitcode, make sure it is valid
 
1095
          input_files.append(arg)
 
1096
        elif arg_ending.endswith(STATICLIB_ENDINGS + DYNAMICLIB_ENDINGS):
 
1097
          # if it's not, and it's a library, just add it to libs to find later
 
1098
          l = unsuffixed_basename(arg)
 
1099
          for prefix in LIB_PREFIXES:
 
1100
            if not prefix: continue
 
1101
            if l.startswith(prefix):
 
1102
              l = l[len(prefix):]
 
1103
              break
 
1104
          libs.append(l)
 
1105
          newargs[i] = ''
983
1106
        else:
984
 
          # this should be bitcode, make sure it is valid
985
 
          if arg.endswith(ASSEMBLY_SUFFIXES) or shared.Building.is_bitcode(arg):
986
 
            input_files.append(arg)
987
 
          elif arg.endswith(STATICLIB_SUFFIXES + DYNAMICLIB_SUFFIXES):
988
 
            # if it's not, and it's a library, just add it to libs to find later
989
 
            l = unsuffixed_basename(arg)
990
 
            for prefix in LIB_PREFIXES:
991
 
              if not prefix: continue
992
 
              if l.startswith(prefix):
993
 
                l = l[len(prefix):]
994
 
                break
995
 
            libs.append(l)
996
 
            newargs[i] = ''
 
1107
          logging.warning(arg + ' is not valid LLVM bitcode')
 
1108
      elif arg_ending.endswith(STATICLIB_ENDINGS):
 
1109
        if not shared.Building.is_ar(arg):
 
1110
          if shared.Building.is_bitcode(arg):
 
1111
            logging.error(arg + ': File has a suffix of a static library ' + str(STATICLIB_ENDINGS) + ', but instead is an LLVM bitcode file! When linking LLVM bitcode files, use one of the suffixes ' + str(BITCODE_ENDINGS))
997
1112
          else:
998
 
            logging.warning(arg + ' is not valid LLVM bitcode')
 
1113
            logging.error(arg + ': Unknown format, not a static library!')
 
1114
          exit(1)
999
1115
      else:
1000
 
        logging.error(arg + ': No such file or directory')
 
1116
        logging.error(arg + ": Input file has an unknown suffix, don't know what to do with it!")
1001
1117
        exit(1)
1002
1118
    elif arg.startswith('-L'):
1003
1119
      lib_dirs.append(arg[2:])
1017
1133
    target = target_basename + '.o'
1018
1134
    final_suffix = 'o'
1019
1135
 
1020
 
  # do not link in libs when just generating object code (not an 'executable', i.e. JS, or a library)
1021
 
  if ('.' + final_suffix) in BITCODE_SUFFIXES and len(libs) > 0:
1022
 
    logging.warning('not linking against libraries since only compiling to bitcode')
1023
 
    libs = []
1024
 
 
1025
1136
  # Find library files
1026
1137
  for lib in libs:
1027
1138
    logging.debug('looking for library "%s"' % lib)
1028
1139
    found = False
1029
1140
    for prefix in LIB_PREFIXES:
1030
 
      for suff in STATICLIB_SUFFIXES + DYNAMICLIB_SUFFIXES:
 
1141
      for suff in STATICLIB_ENDINGS + DYNAMICLIB_ENDINGS:
1031
1142
        name = prefix + lib + suff
1032
1143
        for lib_dir in lib_dirs:
1033
1144
          path = os.path.join(lib_dir, name)
1038
1149
            break
1039
1150
        if found: break
1040
1151
      if found: break
 
1152
    if not found: logging.warning('emcc: cannot find library "%s"' % lib)
1041
1153
 
1042
 
  if ignore_dynamic_linking:
1043
 
    input_files = filter(lambda input_file: not input_file.endswith(DYNAMICLIB_SUFFIXES), input_files)
 
1154
  # If not compiling to JS, then we are compiling to an intermediate bitcode objects or library, so
 
1155
  # ignore dynamic linking, since multiple dynamic linkings can interfere with each other
 
1156
  if not filename_type_suffix(target) in JS_CONTAINING_SUFFIXES or ignore_dynamic_linking:
 
1157
    def check(input_file):
 
1158
      if filename_type_ending(input_file) in DYNAMICLIB_ENDINGS:
 
1159
        if not ignore_dynamic_linking: logging.warning('ignoring dynamic library %s because not compiling to JS or HTML, remember to link it when compiling to JS or HTML at the end' % os.path.basename(input_file))
 
1160
        return False
 
1161
      else:
 
1162
        return True
 
1163
    input_files = filter(lambda input_file: check(input_file), input_files)
1044
1164
 
1045
1165
  if len(input_files) == 0:
1046
 
    logging.error('no input files\nnote that input files without a known suffix are ignored, make sure your input files end with one of: ' + str(SOURCE_SUFFIXES + BITCODE_SUFFIXES + DYNAMICLIB_SUFFIXES + STATICLIB_SUFFIXES + ASSEMBLY_SUFFIXES))
 
1166
    logging.error('no input files\nnote that input files without a known suffix are ignored, make sure your input files end with one of: ' + str(SOURCE_ENDINGS + BITCODE_ENDINGS + DYNAMICLIB_ENDINGS + STATICLIB_ENDINGS + ASSEMBLY_ENDINGS))
1047
1167
    exit(0)
1048
1168
 
1049
1169
  newargs = CC_ADDITIONAL_ARGS + newargs
1070
1190
    logging.warning('disabling asm.js since embind is not ready for it yet')
1071
1191
    shared.Settings.ASM_JS = 0
1072
1192
 
 
1193
  fastcomp = os.environ.get('EMCC_FAST_COMPILER') == '1'
 
1194
 
 
1195
  if fastcomp:
 
1196
    shared.Settings.ASM_JS = 1
 
1197
    assert shared.Settings.ALLOW_MEMORY_GROWTH == 0, 'memory growth not supported in fastcomp yet'
 
1198
    assert shared.Settings.UNALIGNED_MEMORY == 0, 'forced unaligned memory not supported in fastcomp'
 
1199
    assert shared.Settings.SAFE_HEAP == 0, 'safe heap not supported in fastcomp yet'
 
1200
    assert shared.Settings.CHECK_HEAP_ALIGN == 0, 'check heap align not supported in fastcomp yet'
 
1201
    assert shared.Settings.SAFE_DYNCALLS == 0, 'safe dyncalls not supported in fastcomp'
 
1202
    assert shared.Settings.RESERVED_FUNCTION_POINTERS == 0, 'reserved function pointers not supported in fastcomp'
 
1203
    assert shared.Settings.ASM_HEAP_LOG == 0, 'asm heap log not supported in fastcomp'
 
1204
    assert shared.Settings.LABEL_DEBUG == 0, 'label debug not supported in fastcomp'
 
1205
    assert shared.Settings.LEGACY_GL_EMULATION == 0, 'legacy gl emulation not supported in fastcomp'
 
1206
    assert shared.Settings.EXECUTION_TIMEOUT == -1, 'execution timeout not supported in fastcomp'
 
1207
    assert shared.Settings.NAMED_GLOBALS == 0, 'named globals not supported in fastcomp'
 
1208
    assert shared.Settings.PGO == 0, 'pgo not supported in fastcomp'
 
1209
    assert shared.Settings.TARGET_LE32 == 1, 'fastcomp requires le32'
 
1210
    assert shared.Settings.USE_TYPED_ARRAYS == 2, 'fastcomp assumes ta2'
 
1211
    assert not bind, 'embind not supported in fastcomp yet'
 
1212
    if jcache:
 
1213
      logging.warning('jcache is not supported in fastcomp (you should not need it anyhow), disabling')
 
1214
      jcache = False
 
1215
 
 
1216
    fastcomp_opts = ['-pnacl-abi-simplify-preopt', '-pnacl-abi-simplify-postopt']
 
1217
    if not shared.Settings.DISABLE_EXCEPTION_CATCHING:
 
1218
      fastcomp_opts += ['-enable-emscripten-cxx-exceptions']
 
1219
 
1073
1220
  if shared.Settings.ASM_JS:
1074
 
    assert opt_level >= 1, 'asm.js requires -O1 or above'
 
1221
    assert opt_level >= 1 or fastcomp, 'asm.js requires -O1 or above'
1075
1222
 
1076
1223
    if bind:
1077
1224
      shared.Settings.RESERVED_FUNCTION_POINTERS = max(shared.Settings.RESERVED_FUNCTION_POINTERS, 10)
1114
1261
 
1115
1262
  if shared.Settings.MAIN_MODULE or shared.Settings.SIDE_MODULE:
1116
1263
    assert not memory_init_file, 'memory init file is not supported with module linking'
 
1264
    assert shared.Settings.ASM_JS, 'module linking requires asm.js output (-s ASM_JS=1)'
1117
1265
    shared.Settings.LINKABLE = 1 # TODO: add FORCE_DCE option for the brave people that do want to dce here and in side modules
1118
1266
    debug_level = max(debug_level, 2)
1119
1267
 
1138
1286
  if proxy_to_worker:
1139
1287
    shared.Settings.PROXY_TO_WORKER = 1
1140
1288
 
 
1289
  if js_opts:
 
1290
    shared.Settings.RUNNING_JS_OPTS = 1
 
1291
 
1141
1292
  ## Compile source code to bitcode
1142
1293
 
1143
1294
  logging.debug('compiling to bitcode')
1146
1297
 
1147
1298
  # First, generate LLVM bitcode. For each input file, we get base.o with bitcode
1148
1299
  for input_file in input_files:
1149
 
    if input_file.endswith(SOURCE_SUFFIXES):
 
1300
    file_ending = filename_type_ending(input_file)
 
1301
    if file_ending.endswith(SOURCE_ENDINGS):
1150
1302
      logging.debug('compiling source file: ' + input_file)
1151
1303
      input_file = shared.Building.preprocess(input_file, in_temp(uniquename(input_file)))
1152
1304
      output_file = in_temp(unsuffixed(uniquename(input_file)) + '.o')
1153
1305
      temp_files.append(output_file)
1154
1306
      args = newargs + ['-emit-llvm', '-c', input_file, '-o', output_file]
1155
 
      if input_file.endswith(CXX_SUFFIXES):
 
1307
      if file_ending.endswith(CXX_ENDINGS):
1156
1308
        args += shared.EMSDK_CXX_OPTS
1157
1309
      logging.debug("running: " + call + ' ' + ' '.join(args))
1158
1310
      execute([call] + args) # let compiler frontend print directly, so colors are saved (PIPE kills that)
1160
1312
        logging.error('compiler frontend failed to generate LLVM bitcode, halting')
1161
1313
        sys.exit(1)
1162
1314
    else: # bitcode
1163
 
      if input_file.endswith(BITCODE_SUFFIXES):
 
1315
      if file_ending.endswith(BITCODE_ENDINGS):
1164
1316
        logging.debug('copying bitcode file: ' + input_file)
1165
1317
        temp_file = in_temp(unsuffixed(uniquename(input_file)) + '.o')
1166
1318
        shutil.copyfile(input_file, temp_file)
1167
1319
        temp_files.append(temp_file)
1168
 
      elif input_file.endswith(DYNAMICLIB_SUFFIXES) or shared.Building.is_ar(input_file):
 
1320
      elif file_ending.endswith(DYNAMICLIB_ENDINGS) or shared.Building.is_ar(input_file):
1169
1321
        logging.debug('copying library file: ' + input_file)
1170
1322
        temp_file = in_temp(uniquename(input_file))
1171
1323
        shutil.copyfile(input_file, temp_file)
1172
1324
        temp_files.append(temp_file)
1173
 
      else: #.ll
 
1325
      elif file_ending.endswith(ASSEMBLY_ENDINGS):
1174
1326
        if not LEAVE_INPUTS_RAW:
1175
1327
          # Note that by assembling the .ll file, then disassembling it later, we will
1176
1328
          # remove annotations which is a good thing for compilation time
1178
1330
          temp_file = in_temp(unsuffixed(uniquename(input_file)) + '.o')
1179
1331
          shared.Building.llvm_as(input_file, temp_file)
1180
1332
          temp_files.append(temp_file)
 
1333
      else:
 
1334
        logging.error(input_file + ': Unknown file suffix when compiling to LLVM bitcode!')
 
1335
        sys.exit(1)
1181
1336
 
1182
1337
  if not LEAVE_INPUTS_RAW:
1183
1338
    assert len(temp_files) == len(input_files)
1185
1340
    # Optimize source files
1186
1341
    if llvm_opts > 0:
1187
1342
      for i, input_file in enumerate(input_files):
1188
 
        if input_file.endswith(SOURCE_SUFFIXES):
 
1343
        file_ending = filename_type_ending(input_file)
 
1344
        if file_ending.endswith(SOURCE_ENDINGS):
1189
1345
          temp_file = temp_files[i]
1190
 
          logging.debug('optimizing %s with -O%d' % (input_file, llvm_opts))
 
1346
          logging.debug('optimizing %s with -O%s' % (input_file, llvm_opts))
1191
1347
          shared.Building.llvm_opt(temp_file, llvm_opts)
1192
1348
 
1193
1349
  # If we were just asked to generate bitcode, stop there
1197
1353
        shutil.move(in_temp(unsuffixed(uniquename(input_file)) + '.o'), unsuffixed_basename(input_file) + '.' + final_suffix)
1198
1354
    else:
1199
1355
      if len(input_files) == 1:
1200
 
        shutil.move(in_temp(unsuffixed(uniquename(input_files[0])) + '.o'), specified_target)
 
1356
        temp_output_base = in_temp(unsuffixed(uniquename(input_files[0])))
 
1357
        if specified_target.endswith('/') or specified_target.endswith('\\') or os.path.isdir(specified_target): # User passed '-o <directory' as the location to output to.
 
1358
          obj_output_name = os.path.join(specified_target, os.path.splitext(os.path.basename(input_file))[0] + default_object_extension)
 
1359
          logging.debug('User specified -o <directoryname> as the location of the output. Generating output file ' + obj_output_name)
 
1360
          try:
 
1361
            shutil.move(temp_output_base + '.o', obj_output_name)
 
1362
          except IOError, e:
 
1363
            logging.error('Could not write to output file ' + obj_output_name + '. Perhaps the output directory does not exist?')
 
1364
            exit(1)
 
1365
        else: # User passed '-o <filename>' as the location to output to.
 
1366
          shutil.move(temp_output_base + '.o', specified_target)
 
1367
        if os.path.exists(temp_output_base + '.d'):
 
1368
          # There was a .d file generated, from -MD or -MMD and friends, save a copy of it to where the output resides,
 
1369
          # adjusting the target name away from the temporary file name to the specified target.
 
1370
          # It will be deleted with the rest of the temporary directory.
 
1371
          deps = open(temp_output_base + '.d').read()
 
1372
          deps = deps.replace(temp_output_base + '.o', specified_target)
 
1373
          with open(os.path.join(os.path.dirname(specified_target), os.path.basename(unsuffixed(input_files[0]) + '.d')), "w") as out_dep:
 
1374
            out_dep.write(deps)
1201
1375
      else:
1202
1376
        assert len(original_input_files) == 1 or not has_dash_c, 'fatal error: cannot specify -o with -c with multiple files' + str(sys.argv) + ':' + str(original_input_files)
1203
1377
        # We have a specified target (-o <target>), which is not JavaScript or HTML, and
1212
1386
 
1213
1387
  extra_files_to_link = []
1214
1388
 
1215
 
  if not LEAVE_INPUTS_RAW and not AUTODEBUG and \
 
1389
  if not LEAVE_INPUTS_RAW and \
1216
1390
     not shared.Settings.BUILD_AS_SHARED_LIB == 2 and \
1217
1391
     not shared.Settings.SIDE_MODULE: # shared libraries/side modules link no C libraries, need them in parent
1218
1392
 
1266
1440
      libc_files = [
1267
1441
        'dlmalloc.c',
1268
1442
        os.path.join('libcxx', 'new.cpp'),
1269
 
        os.path.join('libc', 'stdlib', 'getopt_long.c'),
1270
 
        os.path.join('libc', 'gen', 'err.c'),
1271
 
        os.path.join('libc', 'gen', 'errx.c'),
1272
 
        os.path.join('libc', 'gen', 'warn.c'),
1273
 
        os.path.join('libc', 'gen', 'warnx.c'),
1274
 
        os.path.join('libc', 'gen', 'verr.c'),
1275
 
        os.path.join('libc', 'gen', 'verrx.c'),
1276
 
        os.path.join('libc', 'gen', 'vwarn.c'),
1277
 
        os.path.join('libc', 'gen', 'vwarnx.c'),
1278
 
        os.path.join('libc', 'stdlib', 'strtod.c'),
1279
 
      ]
 
1443
      ]
 
1444
      musl_files = [
 
1445
        ['internal', [
 
1446
         'floatscan.c',
 
1447
         'shgetc.c',
 
1448
        ]],
 
1449
        ['math', [
 
1450
         'scalbn.c',
 
1451
         'scalbnl.c',
 
1452
        ]],
 
1453
        ['stdio', [
 
1454
         '__overflow.c',
 
1455
         '__toread.c',
 
1456
         '__towrite.c',
 
1457
         '__uflow.c',
 
1458
        ]],
 
1459
        ['stdlib', [
 
1460
         'atof.c',
 
1461
         'strtod.c',
 
1462
        ]]
 
1463
      ]
 
1464
      for directory, sources in musl_files:
 
1465
        libc_files += [os.path.join('libc', 'musl', 'src', directory, source) for source in sources]
1280
1466
      return build_libc('libc.bc', libc_files)
1281
1467
 
1282
1468
    def apply_libc(need):
1314
1500
          'wctrans.c',
1315
1501
          'wcwidth.c',
1316
1502
         ]],
 
1503
         ['internal', [
 
1504
          'intscan.c',
 
1505
         ]],
 
1506
         ['legacy', [
 
1507
          'err.c',
 
1508
         ]],
 
1509
         ['locale', [
 
1510
          'iconv.c',
 
1511
          'iswalnum_l.c',
 
1512
          'iswalpha_l.c',
 
1513
          'iswblank_l.c',
 
1514
          'iswcntrl_l.c',
 
1515
          'iswctype_l.c',
 
1516
          'iswdigit_l.c',
 
1517
          'iswgraph_l.c',
 
1518
          'iswlower_l.c',
 
1519
          'iswprint_l.c',
 
1520
          'iswpunct_l.c',
 
1521
          'iswspace_l.c',
 
1522
          'iswupper_l.c',
 
1523
          'iswxdigit_l.c',
 
1524
          'strcasecmp_l.c',
 
1525
          'strfmon.c',
 
1526
          'strncasecmp_l.c',
 
1527
          'strxfrm.c',
 
1528
          'towctrans_l.c',
 
1529
          'towlower_l.c',
 
1530
          'towupper_l.c',
 
1531
          'wcscoll.c',
 
1532
          'wcscoll_l.c',
 
1533
          'wcsxfrm.c',
 
1534
          'wcsxfrm_l.c',
 
1535
          'wctrans_l.c',
 
1536
          'wctype_l.c',
 
1537
         ]],
 
1538
         ['math', [
 
1539
          '__cos.c',
 
1540
          '__cosdf.c',
 
1541
          '__sin.c',
 
1542
          '__sindf.c',
 
1543
          'ilogb.c',
 
1544
          'ilogbf.c',
 
1545
          'ilogbl.c',
 
1546
          'ldexp.c',
 
1547
          'ldexpf.c',
 
1548
          'ldexpl.c',
 
1549
          'logb.c',
 
1550
          'logbf.c',
 
1551
          'logbl.c',
 
1552
          'lgamma.c',
 
1553
          'lgamma_r.c',
 
1554
          'lgammaf.c',
 
1555
          'lgammaf_r.c',
 
1556
          'lgammal.c',
 
1557
          'scalbnf.c',
 
1558
          'signgam.c',
 
1559
          'tgamma.c',
 
1560
          'tgammaf.c',
 
1561
          'tgammal.c'
 
1562
         ]],
 
1563
         ['misc', [
 
1564
          'getopt.c',
 
1565
          'getopt_long.c',
 
1566
         ]],
1317
1567
         ['multibyte', [
1318
1568
          'btowc.c',
1319
1569
          'mblen.c',
1331
1581
          'wctob.c',
1332
1582
          'wctomb.c',
1333
1583
         ]],
 
1584
         ['regex', [
 
1585
          'regcomp.c',
 
1586
          'regerror.c',
 
1587
          'regexec.c',
 
1588
          'tre-mem.c',
 
1589
         ]],
 
1590
         ['stdio', [
 
1591
          'fwprintf.c',
 
1592
          'swprintf.c',
 
1593
          'vfwprintf.c',
 
1594
          'vswprintf.c',
 
1595
          'vwprintf.c',
 
1596
          'wprintf.c',
 
1597
          'fputwc.c',
 
1598
          'fputws.c',
 
1599
         ]],
1334
1600
         ['stdlib', [
1335
1601
           'ecvt.c',
1336
1602
           'fcvt.c',
1337
1603
           'gcvt.c',
 
1604
           'wcstod.c',
 
1605
           'wcstol.c',
1338
1606
         ]],
1339
1607
         ['string', [
 
1608
           'memccpy.c',
 
1609
           'memmem.c',
 
1610
           'mempcpy.c',
 
1611
           'memrchr.c',
 
1612
           'strcasestr.c',
 
1613
           'strchrnul.c',
 
1614
           'strlcat.c',
 
1615
           'strlcpy.c',
 
1616
           'strsep.c',
 
1617
           'strverscmp.c',
1340
1618
           'wcpcpy.c',
1341
1619
           'wcpncpy.c',
1342
1620
           'wcscasecmp.c',
1343
 
           # 'wcscasecmp_l.c', # XXX: alltypes.h issue
 
1621
           'wcscasecmp_l.c',
1344
1622
           'wcscat.c',
1345
1623
           'wcschr.c',
1346
1624
           'wcscmp.c',
1349
1627
           'wcsdup.c',
1350
1628
           'wcslen.c',
1351
1629
           'wcsncasecmp.c',
1352
 
           # 'wcsncasecmp_l.c', # XXX: alltypes.h issue
 
1630
           'wcsncasecmp_l.c',
1353
1631
           'wcsncat.c',
1354
1632
           'wcsncmp.c',
1355
1633
           'wcsncpy.c',
1476
1754
 
1477
1755
  # First, combine the bitcode files if there are several. We must also link if we have a singleton .a
1478
1756
  if len(input_files) + len(extra_files_to_link) > 1 or \
1479
 
     (not LEAVE_INPUTS_RAW and not (suffix(temp_files[0]) in BITCODE_SUFFIXES or suffix(temp_files[0]) in DYNAMICLIB_SUFFIXES) and shared.Building.is_ar(temp_files[0])):
 
1757
     (not LEAVE_INPUTS_RAW and not (suffix(temp_files[0]) in BITCODE_ENDINGS or suffix(temp_files[0]) in DYNAMICLIB_ENDINGS) and shared.Building.is_ar(temp_files[0])):
1480
1758
    linker_inputs = temp_files + extra_files_to_link
1481
1759
    logging.debug('linking: ' + str(linker_inputs))
1482
1760
    t0 = time.time()
1483
 
    shared.Building.link(linker_inputs, in_temp(target_basename + '.bc'), force_archive_contents = len(filter(lambda temp: not temp.endswith(STATICLIB_SUFFIXES), temp_files)) == 0)
 
1761
    shared.Building.link(linker_inputs, in_temp(target_basename + '.bc'), force_archive_contents = len(filter(lambda temp: not temp.endswith(STATICLIB_ENDINGS), temp_files)) == 0)
1484
1762
    t1 = time.time()
1485
1763
    logging.debug('    linking took %.2f seconds' % (t1 - t0))
1486
1764
    final = in_temp(target_basename + '.bc')
1525
1803
    else:
1526
1804
      # At minimum remove dead functions etc., this potentially saves a lot in the size of the generated code (and the time to compile it)
1527
1805
      link_opts += shared.Building.get_safe_internalize() + ['-globaldce']
1528
 
    shared.Building.llvm_opt(in_temp(target_basename + '.bc'), link_opts)
1529
 
    if DEBUG: save_intermediate('linktime', 'bc')
1530
1806
 
1531
 
  if save_bc:
1532
 
    shutil.copyfile(final, save_bc)
 
1807
    if (not save_bc and not fastcomp) or AUTODEBUG:
 
1808
      # let llvm opt directly emit ll, to skip writing and reading all the bitcode
 
1809
      link_opts += ['-S']
 
1810
      shared.Building.llvm_opt(final, link_opts, final + '.link.ll')
 
1811
      final = final + '.link.ll'
 
1812
      if DEBUG: save_intermediate('linktime', 'll')
 
1813
    else:
 
1814
      if fastcomp and not save_bc:
 
1815
        # Simplify LLVM bitcode for fastcomp
 
1816
        link_opts += fastcomp_opts
 
1817
      shared.Building.llvm_opt(final, link_opts)
 
1818
      if DEBUG: save_intermediate('linktime', 'bc')
 
1819
      if save_bc:
 
1820
        shutil.copyfile(final, save_bc)
 
1821
        if fastcomp:
 
1822
          shared.Building.llvm_opt(final, fastcomp_opts, final + '.adsimp.bc')
 
1823
          final += '.adsimp.bc'
 
1824
          if DEBUG: save_intermediate('adsimp', 'bc')
1533
1825
 
1534
1826
  # Prepare .ll for Emscripten
1535
1827
  if not LEAVE_INPUTS_RAW:
1536
 
    final = shared.Building.llvm_dis(final, final + '.ll')
 
1828
    if save_bc:
 
1829
      final = shared.Building.llvm_dis(final, final + '.ll')
1537
1830
  else:
1538
1831
    assert len(input_files) == 1
1539
 
  if DEBUG: save_intermediate('ll', 'll')
 
1832
  if DEBUG and save_bc: save_intermediate('ll', 'll')
1540
1833
 
1541
1834
  if AUTODEBUG:
1542
1835
    logging.debug('autodebug')
1544
1837
    final += '.ad.ll'
1545
1838
    if DEBUG: save_intermediate('autodebug', 'll')
1546
1839
 
 
1840
  # Simplify bitcode after autodebug
 
1841
  if fastcomp and (AUTODEBUG or LEAVE_INPUTS_RAW):
 
1842
    shared.Building.llvm_opt(final, fastcomp_opts, final + '.adsimp.bc')
 
1843
    final += '.adsimp.bc'
 
1844
    if DEBUG: save_intermediate('adsimp', 'bc')
 
1845
 
1547
1846
  # Emscripten
1548
1847
  logging.debug('LLVM => JS')
1549
1848
  extra_args = [] if not js_libraries else ['--libraries', ','.join(map(os.path.abspath, js_libraries))]
1561
1860
    if len(embed_files) > 0:
1562
1861
      file_args.append('--embed')
1563
1862
      file_args += embed_files
 
1863
    if len(exclude_files) > 0:
 
1864
      file_args.append('--exclude')
 
1865
      file_args += exclude_files
1564
1866
    if Compression.on:
1565
1867
      file_args += ['--compress', Compression.encoder, Compression.decoder, Compression.js_name]
1566
1868
    if use_preload_cache:
1567
1869
      file_args.append('--use-preload-cache')
1568
 
    code = execute([shared.PYTHON, shared.FILE_PACKAGER, unsuffixed(target) + '.data'] + file_args, stdout=PIPE)[0]
1569
 
    src = open(final).read().replace('// {{PRE_RUN_ADDITIONS}}', '// {{PRE_RUN_ADDITIONS}}\n' + code)
1570
 
    final += '.files.js'
1571
 
    open(final, 'w').write(src)
1572
 
    if DEBUG: save_intermediate('files')
 
1870
    if no_heap_copy:
 
1871
      file_args.append('--no-heap-copy')
 
1872
    file_code = execute([shared.PYTHON, shared.FILE_PACKAGER, unsuffixed(target) + '.data'] + file_args, stdout=PIPE)[0]
 
1873
    pre_js = file_code + pre_js
1573
1874
 
1574
1875
  # Apply pre and postjs files
1575
1876
  if pre_js or post_js:
1618
1919
          temp_memfile = os.path.join(shared.EMSCRIPTEN_TEMP_DIR, os.path.basename(memfile))
1619
1920
          if os.path.abspath(memfile) != os.path.abspath(memfile):
1620
1921
            shutil.copyfile(memfile, temp_memfile)
1621
 
        return 'loadMemoryInitializer("%s");' % os.path.basename(memfile)
 
1922
        return 'var memoryInitializer = "%s";' % os.path.basename(memfile)
1622
1923
      src = re.sub(shared.JS.memory_initializer_pattern, repl, open(final).read(), count=1)
1623
1924
      open(final + '.mem.js', 'w').write(src)
1624
1925
      final += '.mem.js'
1637
1938
    global final, js_optimizer_queue, js_optimizer_extra_info
1638
1939
    if len(js_optimizer_extra_info) == 0:
1639
1940
      js_optimizer_extra_info = None
1640
 
    if len(js_optimizer_queue) > 0 and not(len(js_optimizer_queue) == 1 and js_optimizer_queue[0] == 'last'):
 
1941
    if len(js_optimizer_queue) > 0 and not(not shared.Settings.ASM_JS and len(js_optimizer_queue) == 1 and js_optimizer_queue[0] == 'last'):
1641
1942
      if DEBUG != '2':
1642
1943
        if shared.Settings.ASM_JS:
1643
1944
          js_optimizer_queue = ['asm'] + js_optimizer_queue
1672
1973
      else:
1673
1974
        return 'eliminate'
1674
1975
 
1675
 
    js_optimizer_queue += [get_eliminate(), 'simplifyExpressions']
 
1976
    js_optimizer_queue += [get_eliminate()]
 
1977
 
 
1978
    if shared.Settings.AGGRESSIVE_VARIABLE_ELIMINATION:
 
1979
      js_optimizer_queue += ['aggressiveVariableElimination']
 
1980
 
 
1981
    if opt_level >= 2:
 
1982
      js_optimizer_queue += ['simplifyExpressions']
1676
1983
 
1677
1984
  if closure and not shared.Settings.ASM_JS:
1678
1985
    flush_js_optimizer_queue()
1718
2025
  if final_suffix == 'html':
1719
2026
    logging.debug('generating HTML')
1720
2027
    shell = open(shell_path).read()
 
2028
    assert '{{{ SCRIPT }}}' in shell, 'HTML shell must contain  {{{ SCRIPT }}}  , see src/shell.html for an example'
1721
2029
    html = open(target, 'w')
 
2030
    js_target = unsuffixed(target) + '.js'
 
2031
    base_js_target = os.path.basename(js_target)
1722
2032
    if proxy_to_worker:
1723
 
      html.write(shell.replace('{{{ SCRIPT_CODE }}}', open(shared.path_from_root('src', 'proxyClient.js')).read().replace('{{{ filename }}}', target_basename)))
1724
 
      js_target = unsuffixed(target) + '.js'
1725
 
      shutil.copyfile(final, js_target)
 
2033
      html.write(shell.replace('{{{ SCRIPT }}}', '<script>' + open(shared.path_from_root('src', 'proxyClient.js')).read().replace('{{{ filename }}}', target_basename) + '</script>'))
 
2034
      shutil.move(final, js_target)
1726
2035
    elif not Compression.on:
1727
2036
      if debug_level >= 4:
1728
 
        match = re.match('.*?<script[^>]*>{{{ SCRIPT_CODE }}}</script>', shell,
1729
 
            re.DOTALL)
1730
 
        if match is None:
1731
 
          raise RuntimeError('''Could not find script insertion point - make sure you have   <script type='text/javascript'>{{{ SCRIPT_CODE }}}</script>   in your HTML file (with no newlines)''')
1732
 
        generate_source_map(target, match.group().count('\n'))
1733
 
      html.write(shell.replace('{{{ SCRIPT_CODE }}}', open(final).read()))
 
2037
        generate_source_map(target)
 
2038
      shutil.move(final, js_target)
 
2039
      # TODO: use an async blob, which would allow code rewriting on the client:
 
2040
      #   var blob = new Blob([codeString]);
 
2041
      #   var script = document.createElement('script');
 
2042
      #   script.src = URL.createObjectURL(blob);
 
2043
      #   document.body.appendChild(script);
 
2044
      script_tag = '''<script async type="text/javascript" src="%s"></script>''' % base_js_target
 
2045
      html.write(shell.replace('{{{ SCRIPT }}}', script_tag))
1734
2046
    else:
1735
2047
      # Compress the main code
1736
 
      js_target = unsuffixed(target) + '.js'
1737
2048
      shutil.move(final, js_target)
1738
2049
      Compression.compress(js_target)
1739
2050
 
1781
2092
          });
1782
2093
        };
1783
2094
        compiledCodeXHR.send(null);
1784
 
''' % Compression.compressed_name(js_target)
1785
 
      html.write(shell.replace('{{{ SCRIPT_CODE }}}', decoding))
 
2095
''' % Compression.compressed_name(base_js_target)
 
2096
      html.write(shell.replace('{{{ SCRIPT }}}', '<script>' + decoding + '</script>'))
1786
2097
 
1787
2098
      # Add decompressor with web worker glue code
1788
2099
      decompressor = open('decompress.js', 'w')