Windows: Link library sources into gen_snapshot/dart_bootstrap

This allows gen_snapshot and dart_bootstrap to run without having
a full SDK snapshot around.

The generated cc file looks like:

static const char source_array_1[] = {
 '\x2f', '\x2f', '\x20', '\x43', '\x6f', ...
};
static const char source_array_2[] = {
 '\x2f', '\x2f', '\x20', '\x43', '\x6f', ...
};
...

const char* dart::Bootstrap::core_source_paths_[] = {
 "dart:core",
 "/path/to/sdk/lib/core/core.dart",
 source_array_1,

 "annotations.dart",
 "/path/to/sdk/lib/core/annotations.dart",
 source_array_2,
...

R=asiva@google.com

Review-Url: https://codereview.chromium.org/2668353004 .
This commit is contained in:
Florian Schneider 2017-02-01 15:55:59 -08:00
parent 90ed8e9d27
commit 15a4d5d6d1
5 changed files with 22 additions and 20 deletions

View file

@ -8,6 +8,7 @@
// This file is used to generate the mapping of standalone dart libraries
// to the corresponding files that implement them.
{{SOURCE_ARRAYS}}
const char* {{VAR_NAME}}[] = {
{{LIBRARY_SOURCE_MAP}}
{{PART_SOURCE_MAP}}

View file

@ -8,6 +8,7 @@
// This file is used to generate the mapping of libraries which have
// dart:<name> handles to the corresponding files that implement them.
{{SOURCE_ARRAYS}}
const char* {{VAR_NAME}}[] = {
{{LIBRARY_SOURCE_MAP}}
{{PART_SOURCE_MAP}}

View file

@ -16,31 +16,40 @@ from optparse import OptionParser
HOST_OS = utils.GuessOS()
def makeString(input_file):
# TODO(iposva): For now avoid creating overly long strings on Windows.
if HOST_OS == 'win32':
return 'NULL'
result = '"'
def makeString(input_file, var_name):
result = 'static const char ' + var_name + '[] = {\n '
fileHandle = open(input_file, 'rb')
lineCounter = 0
for byte in fileHandle.read():
result += '\\x%02x' % ord(byte)
result += '\'\\x%02x' % ord(byte) + '\', '
lineCounter += 1
if lineCounter == 19:
result += '"\n "'
result += '\n '
lineCounter = 0
result += '"'
result += '0};\n'
return result
def makeSourceArrays(in_files):
result = '';
file_count = 0;
for string_file in in_files:
if string_file.endswith('.dart'):
file_count += 1
file_string = makeString(string_file, "source_array_" + str(file_count))
result += file_string
return result
def makeFile(output_file, input_cc_file, include, var_name, lib_name, in_files):
part_index = [ ]
bootstrap_cc_text = open(input_cc_file).read()
bootstrap_cc_text = bootstrap_cc_text.replace("{{SOURCE_ARRAYS}}", makeSourceArrays(in_files))
bootstrap_cc_text = bootstrap_cc_text.replace("{{INCLUDE}}", include)
bootstrap_cc_text = bootstrap_cc_text.replace("{{VAR_NAME}}", var_name)
main_file_found = False
file_count = 0
for string_file in in_files:
if string_file.endswith('.dart'):
file_count += 1
if (not main_file_found):
inpt = open(string_file, 'r')
for line in inpt:
@ -51,7 +60,7 @@ def makeFile(output_file, input_cc_file, include, var_name, lib_name, in_files):
"{{LIBRARY_SOURCE_MAP}}",
' "' + lib_name + '",\n "' +
os.path.abspath(string_file).replace('\\', '\\\\') + '",\n' +
' ' + makeString(string_file) + ',\n')
' source_array_' + str(file_count) + ',\n')
inpt.close()
if (main_file_found):
continue
@ -59,14 +68,13 @@ def makeFile(output_file, input_cc_file, include, var_name, lib_name, in_files):
os.path.basename(string_file).replace('\\', '\\\\') + '",\n')
part_index.append(' "' +
os.path.abspath(string_file).replace('\\', '\\\\') + '",\n')
part_index.append(' ' + makeString(string_file) + ',\n\n')
part_index.append(' source_array_' + str(file_count) + ',\n\n')
bootstrap_cc_text = bootstrap_cc_text.replace("{{LIBRARY_SOURCE_MAP}}", '')
bootstrap_cc_text = bootstrap_cc_text.replace("{{PART_SOURCE_MAP}}",
''.join(part_index))
open(output_file, 'w').write(bootstrap_cc_text)
return True
def main(args):
try:
# Parse input.

View file

@ -22,7 +22,7 @@ namespace dart {
DEFINE_FLAG(bool,
use_corelib_source_files,
kDefaultCorelibSourceFlag,
false,
"Attempt to use source files directly when loading in the core "
"libraries during the bootstrap process");

View file

@ -135,16 +135,8 @@ static const uword kZapUninitializedWord = 0xabababababababab;
#error Unknown host architecture.
#endif
#endif // !defined(TARGET_OS_WINDOWS))
// Default value for flag --use-corelib-source-files.
#if defined(TARGET_OS_WINDOWS)
static const bool kDefaultCorelibSourceFlag = true;
#else
static const bool kDefaultCorelibSourceFlag = false;
#endif // defined(TARGET_OS_WINDOWS)
} // namespace dart
#endif // RUNTIME_VM_GLOBALS_H_