@@ -441,82 +441,52 @@ def lower_camel_case(str):
441
441
return str [0 ].lower () + str [1 :] if str [1 :] else ""
442
442
443
443
444
- # Adapted from PEP 257: strips a uniform amount of indentation from the lines of the multiline string.
445
- # This allows us to use multiline strings with pythonic identation which produce the same identation in the written file
446
- def trim (str ):
447
- if not str :
448
- return ""
449
- # Convert tabs to spaces (following the normal Python rules)
450
- # and split into a list of lines:
451
- lines = str .expandtabs ().splitlines ()
452
- # Determine minimum indentation (first line doesn't count):
453
- indent = sys .maxsize
454
- for line in lines :
455
-
456
- stripped = line .lstrip ()
457
- if stripped :
458
- indent = min (indent , len (line ) - len (stripped ))
459
- # Remove indentation (first line is special):
460
- trimmed = []
461
- if indent < sys .maxsize :
462
- for line in lines :
463
- trimmed .append (line [indent :].rstrip ())
464
- # Strip off trailing and leading blank lines:
465
- while trimmed and not trimmed [- 1 ]:
466
- trimmed .pop ()
467
- while trimmed and not trimmed [0 ]:
468
- trimmed .pop (0 )
469
- # Return a single string:
470
- return "\n " .join (trimmed )
471
-
472
-
473
444
#############################################
474
445
# write frozen files
475
446
476
- FROZEN_MODULES_HEADER = """
477
- /*
478
- * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
479
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
480
- *
481
- * The Universal Permissive License (UPL), Version 1.0
482
- *
483
- * Subject to the condition set forth below, permission is hereby granted to any
484
- * person obtaining a copy of this software, associated documentation and/or
485
- * data (collectively the "Software"), free of charge and under any and all
486
- * copyright rights in the Software, and any and all patent rights owned or
487
- * freely licensable by each licensor hereunder covering either (i) the
488
- * unmodified Software as contributed to or provided by such licensor, or (ii)
489
- * the Larger Works (as defined below), to deal in both
490
- *
491
- * (a) the Software, and
492
- *
493
- * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
494
- * one is included with the Software each a "Larger Work" to which the Software
495
- * is contributed by such licensors),
496
- *
497
- * without restriction, including without limitation the rights to copy, create
498
- * derivative works of, display, perform, and distribute the Software and make,
499
- * use, sell, offer for sale, import, export, have made, and have sold the
500
- * Software and the Larger Work(s), and to sublicense the foregoing rights on
501
- * either these or other terms.
502
- *
503
- * This license is subject to the following condition:
504
- *
505
- * The above copyright notice and either this complete permission notice or at a
506
- * minimum a reference to the UPL must be included in all copies or substantial
507
- * portions of the Software.
508
- *
509
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
510
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
511
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
512
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
513
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
514
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
515
- * SOFTWARE.
516
- */
517
- package com.oracle.graal.python.builtins.objects.module;
518
-
519
- public final class FrozenModules {"""
447
+ FROZEN_MODULES_HEADER = """/*
448
+ * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
449
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
450
+ *
451
+ * The Universal Permissive License (UPL), Version 1.0
452
+ *
453
+ * Subject to the condition set forth below, permission is hereby granted to any
454
+ * person obtaining a copy of this software, associated documentation and/or
455
+ * data (collectively the "Software"), free of charge and under any and all
456
+ * copyright rights in the Software, and any and all patent rights owned or
457
+ * freely licensable by each licensor hereunder covering either (i) the
458
+ * unmodified Software as contributed to or provided by such licensor, or (ii)
459
+ * the Larger Works (as defined below), to deal in both
460
+ *
461
+ * (a) the Software, and
462
+ *
463
+ * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
464
+ * one is included with the Software each a "Larger Work" to which the Software
465
+ * is contributed by such licensors),
466
+ *
467
+ * without restriction, including without limitation the rights to copy, create
468
+ * derivative works of, display, perform, and distribute the Software and make,
469
+ * use, sell, offer for sale, import, export, have made, and have sold the
470
+ * Software and the Larger Work(s), and to sublicense the foregoing rights on
471
+ * either these or other terms.
472
+ *
473
+ * This license is subject to the following condition:
474
+ *
475
+ * The above copyright notice and either this complete permission notice or at a
476
+ * minimum a reference to the UPL must be included in all copies or substantial
477
+ * portions of the Software.
478
+ *
479
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
480
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
481
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
482
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
483
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
484
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
485
+ * SOFTWARE.
486
+ */
487
+ package com.oracle.graal.python.builtins.objects.module;
488
+
489
+ public final class FrozenModules {"""
520
490
521
491
def freeze_module (src ):
522
492
with open (src .pyfile , "r" ) as src_file , open (src .binaryfile , "wb" ) as binary_file :
@@ -543,10 +513,13 @@ def write_frozen_lookup(out_file, modules):
543
513
out_file .write (" switch (name) {\n " )
544
514
for module in modules :
545
515
if module .source and (module .source .ispkg != module .ispkg ):
546
- out_file .write (f' case "{ module .name } ": return Map.{ module .symbol } .asPackage({ "true" if module .ispkg else "false" } );\n ' )
516
+ out_file .write (f' case "{ module .name } ":\n ' )
517
+ out_file .write (f' return Map.{ module .symbol } .asPackage({ "true" if module .ispkg else "false" } );\n ' )
547
518
else :
548
- out_file .write (f' case "{ module .name } ": return Map.{ module .symbol } ;\n ' )
549
- out_file .write (" default: return null;\n " )
519
+ out_file .write (f' case "{ module .name } ":\n ' )
520
+ out_file .write (f' return Map.{ module .symbol } ;\n ' )
521
+ out_file .write (" default:\n " )
522
+ out_file .write (" return null;\n " )
550
523
out_file .write (" }\n " )
551
524
out_file .write (" }\n " )
552
525
@@ -561,7 +534,7 @@ def write_frozen_module_file(file, modules):
561
534
content = None
562
535
os .makedirs (os .path .dirname (file ), exist_ok = True )
563
536
with open (file , "w" ) as out_file :
564
- out_file .write (trim ( FROZEN_MODULES_HEADER ) )
537
+ out_file .write (FROZEN_MODULES_HEADER )
565
538
out_file .write ("\n \n " )
566
539
write_frozen_modules_map (out_file , modules )
567
540
out_file .write ("\n " )
@@ -575,6 +548,7 @@ def write_frozen_module_file(file, modules):
575
548
os .utime (file , (atime , mtime ))
576
549
else :
577
550
print (f"{ file } modified, rebuild needed!" )
551
+ sys .exit (1 )
578
552
579
553
def add_tabs (str , number ):
580
554
lines = str .splitlines ()
0 commit comments