- Add dart:json, dart:uri and dart:utf8 to the known and builtin libraries.

- Unify and simplify the building of the creation of the source file.
Review URL: https://chromiumcodereview.appspot.com//9417012

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@4336 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
iposva@google.com
2012-02-16 19:59:19 +00:00
parent 74ab781eab
commit 9dc3d0f49d
17 changed files with 292 additions and 83 deletions
+123 -3
View File
@@ -4,8 +4,10 @@
{
'variables': {
'io_in_cc_file': 'io_in.cc',
'io_cc_file': '<(SHARED_INTERMEDIATE_DIR)/io_gen.cc',
'json_cc_file': '<(SHARED_INTERMEDIATE_DIR)/json_gen.cc',
'uri_cc_file': '<(SHARED_INTERMEDIATE_DIR)/uri_gen.cc',
'utf8_cc_file': '<(SHARED_INTERMEDIATE_DIR)/utf8_gen.cc',
'builtin_in_cc_file': 'builtin_in.cc',
'builtin_cc_file': '<(SHARED_INTERMEDIATE_DIR)/builtin_gen.cc',
'snapshot_in_cc_file': 'snapshot_in.cc',
@@ -41,6 +43,8 @@
'tools/create_string_literal.py',
'--output', '<(builtin_cc_file)',
'--input_cc', '<(builtin_in_cc_file)',
'--include', 'bin/builtin.h',
'--var_name', 'Builtin::builtin_source_',
'<@(_sources)',
],
'message': 'Generating ''<(builtin_cc_file)'' file.'
@@ -63,7 +67,7 @@
'action_name': 'generate_io_cc',
'inputs': [
'../tools/create_string_literal.py',
'<(io_in_cc_file)',
'<(builtin_in_cc_file)',
'<@(_sources)',
],
'outputs': [
@@ -73,19 +77,129 @@
'python',
'tools/create_string_literal.py',
'--output', '<(io_cc_file)',
'--input_cc', '<(io_in_cc_file)',
'--input_cc', '<(builtin_in_cc_file)',
'--include', 'bin/builtin.h',
'--var_name', 'Builtin::io_source_',
'<@(_sources)',
],
'message': 'Generating ''<(io_cc_file)'' file.'
},
]
},
{
'target_name': 'generate_json_cc_file',
'type': 'none',
'conditions': [
['OS=="win"', {
'msvs_cygwin_dirs': ['<(cygwin_dir)'],
}],
],
'includes': [
'json_sources.gypi',
],
'actions': [
{
'action_name': 'generate_json_cc',
'inputs': [
'../tools/create_string_literal.py',
'<(builtin_in_cc_file)',
'<@(_sources)',
],
'outputs': [
'<(json_cc_file)',
],
'action': [
'python',
'tools/create_string_literal.py',
'--output', '<(json_cc_file)',
'--input_cc', '<(builtin_in_cc_file)',
'--include', 'bin/builtin.h',
'--var_name', 'Builtin::json_source_',
'<@(_sources)',
],
'message': 'Generating ''<(json_cc_file)'' file.'
},
]
},
{
'target_name': 'generate_uri_cc_file',
'type': 'none',
'conditions': [
['OS=="win"', {
'msvs_cygwin_dirs': ['<(cygwin_dir)'],
}],
],
'includes': [
'uri_sources.gypi',
],
'actions': [
{
'action_name': 'generate_uri_cc',
'inputs': [
'../tools/create_string_literal.py',
'<(builtin_in_cc_file)',
'<@(_sources)',
],
'outputs': [
'<(uri_cc_file)',
],
'action': [
'python',
'tools/create_string_literal.py',
'--output', '<(uri_cc_file)',
'--input_cc', '<(builtin_in_cc_file)',
'--include', 'bin/builtin.h',
'--var_name', 'Builtin::uri_source_',
'<@(_sources)',
],
'message': 'Generating ''<(uri_cc_file)'' file.'
},
]
},
{
'target_name': 'generate_utf8_cc_file',
'type': 'none',
'conditions': [
['OS=="win"', {
'msvs_cygwin_dirs': ['<(cygwin_dir)'],
}],
],
'includes': [
'utf8_sources.gypi',
],
'actions': [
{
'action_name': 'generate_utf8_cc',
'inputs': [
'../tools/create_string_literal.py',
'<(builtin_in_cc_file)',
'<@(_sources)',
],
'outputs': [
'<(utf8_cc_file)',
],
'action': [
'python',
'tools/create_string_literal.py',
'--output', '<(utf8_cc_file)',
'--input_cc', '<(builtin_in_cc_file)',
'--include', 'bin/builtin.h',
'--var_name', 'Builtin::utf8_source_',
'<@(_sources)',
],
'message': 'Generating ''<(utf8_cc_file)'' file.'
},
]
},
{
'target_name': 'libdart_builtin',
'type': 'static_library',
'dependencies': [
'generate_builtin_cc_file',
'generate_io_cc_file',
'generate_json_cc_file',
'generate_uri_cc_file',
'generate_utf8_cc_file',
],
'include_dirs': [
'..',
@@ -143,6 +257,9 @@
# Include generated source files.
'<(builtin_cc_file)',
'<(io_cc_file)',
'<(json_cc_file)',
'<(uri_cc_file)',
'<(utf8_cc_file)',
],
'conditions': [
['OS=="win"', {
@@ -227,6 +344,9 @@
# Include generated source files.
'<(builtin_cc_file)',
'<(io_cc_file)',
'<(json_cc_file)',
'<(uri_cc_file)',
'<(utf8_cc_file)',
'snapshot_empty.cc',
],
'conditions': [
+40 -11
View File
@@ -25,18 +25,34 @@ static void SetupCorelibImports(Dart_Handle builtin_lib) {
Dart_Handle Builtin::Source(BuiltinLibraryId id) {
Dart_Handle source;
if (id == kBuiltinLibrary) {
source = Dart_NewString(Builtin::builtin_source_);
} else {
ASSERT(id == kIOLibrary);
source = Dart_NewString(Builtin::io_source_);
switch (id) {
case kBuiltinLibrary:
source = Dart_NewString(Builtin::builtin_source_);
break;
case kIOLibrary:
source = Dart_NewString(Builtin::io_source_);
break;
case kJsonLibrary:
source = Dart_NewString(Builtin::json_source_);
break;
case kUriLibrary:
source = Dart_NewString(Builtin::uri_source_);
break;
case kUtf8Library:
source = Dart_NewString(Builtin::utf8_source_);
break;
default:
return Dart_Error("Unknown builtin source requested.");
}
return source;
}
void Builtin::SetupLibrary(Dart_Handle library, BuiltinLibraryId id) {
if (id == kBuiltinLibrary) {
if ((id == kJsonLibrary) || (id == kUriLibrary) || (id == kUtf8Library)) {
// No native resolver for these pure Dart libraries.
return;
} else if (id == kBuiltinLibrary) {
// Setup core lib, builtin import structure.
SetupCorelibImports(library);
}
@@ -47,11 +63,24 @@ void Builtin::SetupLibrary(Dart_Handle library, BuiltinLibraryId id) {
Dart_Handle Builtin::LoadLibrary(BuiltinLibraryId id) {
Dart_Handle url;
if (id == kBuiltinLibrary) {
url = Dart_NewString(DartUtils::kBuiltinLibURL);
} else {
ASSERT(id == kIOLibrary);
url = Dart_NewString(DartUtils::kIOLibURL);
switch (id) {
case kBuiltinLibrary:
url = Dart_NewString(DartUtils::kBuiltinLibURL);
break;
case kIOLibrary:
url = Dart_NewString(DartUtils::kIOLibURL);
break;
case kJsonLibrary:
url = Dart_NewString(DartUtils::kJsonLibURL);
break;
case kUriLibrary:
url = Dart_NewString(DartUtils::kUriLibURL);
break;
case kUtf8Library:
url = Dart_NewString(DartUtils::kUtf8LibURL);
break;
default:
return Dart_Error("Unknown builtin library requested.");
}
Dart_Handle library = Dart_LookupLibrary(url);
if (Dart_IsError(library)) {
+7 -1
View File
@@ -23,7 +23,10 @@ class Builtin {
public:
enum BuiltinLibraryId {
kBuiltinLibrary,
kIOLibrary
kIOLibrary,
kJsonLibrary,
kUriLibrary,
kUtf8Library,
};
static Dart_Handle Source(BuiltinLibraryId id);
@@ -39,6 +42,9 @@ class Builtin {
static const char builtin_source_[];
static const char io_source_[];
static const char json_source_[];
static const char uri_source_[];
static const char utf8_source_[];
DISALLOW_ALLOCATION();
DISALLOW_IMPLICIT_CONSTRUCTORS(Builtin);
+2 -5
View File
@@ -2,15 +2,12 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include <stdlib.h>
#include <string.h>
#include "bin/builtin.h"
#include "{{INCLUDE}}"
// The string on the next line will be filled in with the contents of the
// builtin.dart file.
// This string forms the content of builtin functionality which is injected
// into standalone dart to provide some test/debug functionality.
const char Builtin::builtin_source_[] = {
const char {{VAR_NAME}}[] = {
{{DART_SOURCE}}
};
+19 -5
View File
@@ -29,11 +29,25 @@ Dart_Handle Builtin::LoadLibrary(BuiltinLibraryId id) {
void Builtin::ImportLibrary(Dart_Handle library, BuiltinLibraryId id) {
Dart_Handle url;
if (id == kBuiltinLibrary) {
url = Dart_NewString(DartUtils::kBuiltinLibURL);
} else {
ASSERT(id == kIOLibrary);
url = Dart_NewString(DartUtils::kIOLibURL);
switch (id) {
case kBuiltinLibrary:
url = Dart_NewString(DartUtils::kBuiltinLibURL);
break;
case kIOLibrary:
url = Dart_NewString(DartUtils::kIOLibURL);
break;
case kJsonLibrary:
url = Dart_NewString(DartUtils::kJsonLibURL);
break;
case kUriLibrary:
url = Dart_NewString(DartUtils::kUriLibURL);
break;
case kUtf8Library:
url = Dart_NewString(DartUtils::kUtf8LibURL);
break;
default:
url = Dart_Error("Unknown builtin library requested.");
UNREACHABLE();
}
Dart_Handle imported_library = Dart_LookupLibrary(url);
// Import the builtin library into current library.
+17
View File
@@ -14,6 +14,9 @@ const char* DartUtils::kBuiltinLibURL = "dart:builtin";
const char* DartUtils::kCoreLibURL = "dart:core";
const char* DartUtils::kCoreImplLibURL = "dart:coreimpl";
const char* DartUtils::kIOLibURL = "dart:io";
const char* DartUtils::kJsonLibURL = "dart:json";
const char* DartUtils::kUriLibURL = "dart:uri";
const char* DartUtils::kUtf8LibURL = "dart:utf8";
const char* DartUtils::kIdFieldName = "_id";
@@ -106,6 +109,20 @@ bool DartUtils::IsDartIOLibURL(const char* url_name) {
}
bool DartUtils::IsDartJsonLibURL(const char* url_name) {
return (strcmp(url_name, kJsonLibURL) == 0);
}
bool DartUtils::IsDartUriLibURL(const char* url_name) {
return (strcmp(url_name, kUriLibURL) == 0);
}
bool DartUtils::IsDartUtf8LibURL(const char* url_name) {
return (strcmp(url_name, kUtf8LibURL) == 0);
}
Dart_Handle DartUtils::CanonicalizeURL(CommandLineOptions* url_mapping,
Dart_Handle library,
+6
View File
@@ -69,6 +69,9 @@ class DartUtils {
const char* val);
static bool IsDartSchemeURL(const char* url_name);
static bool IsDartIOLibURL(const char* url_name);
static bool IsDartJsonLibURL(const char* url_name);
static bool IsDartUriLibURL(const char* url_name);
static bool IsDartUtf8LibURL(const char* url_name);
static Dart_Handle CanonicalizeURL(CommandLineOptions* url_mapping,
Dart_Handle library,
const char* url_str);
@@ -87,6 +90,9 @@ class DartUtils {
static const char* kCoreLibURL;
static const char* kCoreImplLibURL;
static const char* kIOLibURL;
static const char* kJsonLibURL;
static const char* kUriLibURL;
static const char* kUtf8LibURL;
static const char* kIdFieldName;
+8 -3
View File
@@ -204,10 +204,9 @@ static Dart_Handle LoadGenericSnapshotCreationScript(
BuiltinLibraryTagHandler,
import_map);
} else {
ASSERT(id == Builtin::kIOLibrary);
// Load the dart:io library to make it available in the snapshot
// Load the builtin library to make it available in the snapshot
// for importing.
lib = Builtin::LoadLibrary(Builtin::kIOLibrary);
lib = Builtin::LoadLibrary(id);
}
if (!Dart_IsError(lib)) {
Builtin::SetupLibrary(lib, id);
@@ -287,6 +286,12 @@ int main(int argc, char** argv) {
VerifyLoaded(library);
library = LoadGenericSnapshotCreationScript(Builtin::kIOLibrary);
VerifyLoaded(library);
library = LoadGenericSnapshotCreationScript(Builtin::kJsonLibrary);
VerifyLoaded(library);
library = LoadGenericSnapshotCreationScript(Builtin::kUriLibrary);
VerifyLoaded(library);
library = LoadGenericSnapshotCreationScript(Builtin::kUtf8Library);
VerifyLoaded(library);
}
uint8_t* buffer = NULL;
-14
View File
@@ -1,14 +0,0 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include <stdlib.h>
#include <string.h>
#include "bin/builtin.h"
// The string on the next line will be filled in with the contents of
// the dart files of the dart:io library.
const char Builtin::io_source_[] = {
{{DART_SOURCE}}
};
+10
View File
@@ -0,0 +1,10 @@
# Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
# This file contains all sources for the dart:io library.
{
'sources': [
'../../lib/json/json.dart',
],
}
+9 -2
View File
@@ -267,9 +267,16 @@ static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag,
return DartUtils::CanonicalizeURL(NULL, library, url_string);
}
if (is_dart_scheme_url) {
// Handle imports of dart:io.
if (DartUtils::IsDartIOLibURL(url_string) && (tag == kImportTag)) {
ASSERT(tag == kImportTag);
// Handle imports of other built-in libraries present in the SDK.
if (DartUtils::IsDartIOLibURL(url_string)) {
return Builtin::LoadLibrary(Builtin::kIOLibrary);
} else if (DartUtils::IsDartJsonLibURL(url_string)) {
return Builtin::LoadLibrary(Builtin::kJsonLibrary);
} else if (DartUtils::IsDartUriLibURL(url_string)) {
return Builtin::LoadLibrary(Builtin::kUriLibrary);
} else if (DartUtils::IsDartUtf8LibURL(url_string)) {
return Builtin::LoadLibrary(Builtin::kUtf8Library);
} else {
return Dart_Error("Do not know how to load '%s'", url_string);
}
+10
View File
@@ -0,0 +1,10 @@
# Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
# This file contains all sources for the dart:io library.
{
'sources': [
'../../lib/uri/uri.dart',
],
}
+10
View File
@@ -0,0 +1,10 @@
# Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
# This file contains all sources for the dart:io library.
{
'sources': [
'../../lib/utf8/utf8.dart',
],
}
+20 -2
View File
@@ -31,8 +31,10 @@ def makeString(input_files):
return result
def makeFile(output_file, input_cc_file, input_files):
def makeFile(output_file, input_cc_file, include, var_name, input_files):
bootstrap_cc_text = open(input_cc_file).read()
bootstrap_cc_text = bootstrap_cc_text.replace("{{INCLUDE}}", include)
bootstrap_cc_text = bootstrap_cc_text.replace("{{VAR_NAME}}", var_name)
bootstrap_cc_text = bootstrap_cc_text.replace("{{DART_SOURCE}}",
makeString(input_files))
open(output_file, 'w').write(bootstrap_cc_text)
@@ -49,6 +51,12 @@ def main(args):
parser.add_option("--input_cc",
action="store", type="string",
help="input template file")
parser.add_option("--include",
action="store", type="string",
help="variable name")
parser.add_option("--var_name",
action="store", type="string",
help="variable name")
(options, args) = parser.parse_args()
if not options.output:
@@ -57,6 +65,12 @@ def main(args):
if not len(options.input_cc):
sys.stderr.write('--input_cc not specified\n')
return -1
if not len(options.include):
sys.stderr.write('--include not specified\n')
return -1
if not len(options.var_name):
sys.stderr.write('--var_name not specified\n')
return -1
if len(args) == 0:
sys.stderr.write('No input files specified\n')
return -1
@@ -65,7 +79,11 @@ def main(args):
for arg in args:
files.append(arg)
if not makeFile(options.output, options.input_cc, files):
if not makeFile(options.output,
options.input_cc,
options.include,
options.var_name,
files):
return -1
return 0
-16
View File
@@ -1,16 +0,0 @@
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "vm/bootstrap.h"
namespace dart {
// The string on the next line will be filled in with the contents of the
// bootstrap dart files.
const char Bootstrap::corelib_impl_source_[] = {
{{DART_SOURCE}}
};
} // namespace dart
-15
View File
@@ -1,15 +0,0 @@
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "vm/bootstrap.h"
namespace dart {
// The string on the next line will be filled in with the contents of the
// bootstrap dart files.
const char Bootstrap::corelib_source_[] = {
{{DART_SOURCE}}
};
} // namespace dart
+11 -6
View File
@@ -4,9 +4,8 @@
{
'variables': {
'corelib_in_cc_file': 'corelib_in.cc',
'builtin_in_cc_file': '../bin/builtin_in.cc',
'corelib_cc_file': '<(SHARED_INTERMEDIATE_DIR)/corelib_gen.cc',
'corelib_impl_in_cc_file': 'corelib_impl_in.cc',
'corelib_impl_cc_file': '<(SHARED_INTERMEDIATE_DIR)/corelib_impl_gen.cc',
'snapshot_test_dat_file': '<(SHARED_INTERMEDIATE_DIR)/snapshot_test.dat',
'snapshot_test_in_dat_file': 'snapshot_test_in.dat',
@@ -118,7 +117,7 @@
'action_name': 'generate_corelib_cc',
'inputs': [
'../tools/create_string_literal.py',
'<(corelib_in_cc_file)',
'<(builtin_in_cc_file)',
'<@(_sources)',
],
'outputs': [
@@ -128,7 +127,9 @@
'python',
'tools/create_string_literal.py',
'--output', '<(corelib_cc_file)',
'--input_cc', '<(corelib_in_cc_file)',
'--input_cc', '<(builtin_in_cc_file)',
'--include', 'vm/bootstrap.h',
'--var_name', 'dart::Bootstrap::corelib_source_',
'<@(_sources)',
],
'message': 'Generating ''<(corelib_cc_file)'' file.'
@@ -161,7 +162,7 @@
'action_name': 'generate_corelib_impl_cc',
'inputs': [
'../tools/create_string_literal.py',
'<(corelib_impl_in_cc_file)',
'<(builtin_in_cc_file)',
'<@(_sources)',
],
'outputs': [
@@ -171,7 +172,9 @@
'python',
'tools/create_string_literal.py',
'--output', '<(corelib_impl_cc_file)',
'--input_cc', '<(corelib_impl_in_cc_file)',
'--input_cc', '<(builtin_in_cc_file)',
'--include', 'vm/bootstrap.h',
'--var_name', 'dart::Bootstrap::corelib_impl_source_',
'<@(_sources)',
],
'message': 'Generating ''<(corelib_impl_cc_file)'' file.'
@@ -202,6 +205,8 @@
'tools/create_string_literal.py',
'--output', '<(snapshot_test_dat_file)',
'--input_cc', '<(snapshot_test_in_dat_file)',
'--include', 'INTENTIONALLY_LEFT_BLANK',
'--var_name', 'INTENTIONALLY_LEFT_BLANK_TOO',
'<(snapshot_test_dart_file)',
],
'message': 'Generating ''<(snapshot_test_dat_file)'' file.'