Add --packages option to gen_snapshot in order to accept package map files (see https://github.com/dart-lang/sdk/issues/26362)

BUG=26362
R=rmacnak@google.com

Review URL: https://codereview.chromium.org/2044673002 .
This commit is contained in:
Siva Annamalai 2016-06-06 17:12:20 -07:00
parent 9ee5dfb245
commit 53c20930d1
2 changed files with 42 additions and 3 deletions

View file

@ -63,7 +63,17 @@ static const char* isolate_snapshot_filename = NULL;
static const char* assembly_filename = NULL;
static const char* instructions_blob_filename = NULL;
static const char* rodata_blob_filename = NULL;
static const char* package_root = NULL;
// Value of the --package-root flag.
// (This pointer points into an argv buffer and does not need to be
// free'd.)
static const char* commandline_package_root = NULL;
// Value of the --packages flag.
// (This pointer points into an argv buffer and does not need to be
// free'd.)
static const char* commandline_packages_file = NULL;
// Global state which contains a pointer to the script name for which
@ -249,7 +259,17 @@ static bool ProcessPackageRootOption(const char* option) {
name = ProcessOption(option, "--package-root=");
}
if (name != NULL) {
package_root = name;
commandline_package_root = name;
return true;
}
return false;
}
static bool ProcessPackagesOption(const char* option) {
const char* name = ProcessOption(option, "--packages=");
if (name != NULL) {
commandline_packages_file = name;
return true;
}
return false;
@ -296,6 +316,7 @@ static int ParseArguments(int argc,
ProcessEmbedderEntryPointsManifestOption(argv[i]) ||
ProcessURLmappingOption(argv[i]) ||
ProcessPackageRootOption(argv[i]) ||
ProcessPackagesOption(argv[i]) ||
ProcessEnvironmentOption(argv[i])) {
i += 1;
continue;
@ -312,6 +333,14 @@ static int ParseArguments(int argc,
*script_name = NULL;
}
// Verify consistency of arguments.
if ((commandline_package_root != NULL) &&
(commandline_packages_file != NULL)) {
Log::PrintErr("Specifying both a packages directory and a packages "
"file is invalid.\n");
return -1;
}
if (vm_isolate_snapshot_filename == NULL) {
Log::PrintErr("No vm isolate snapshot output file specified.\n\n");
return -1;
@ -646,6 +675,8 @@ static void PrintUsage() {
" --package_root=<path> Where to find packages, that is, \n"
" package:... imports. \n"
" \n"
" --packages=<packages_file> Where to find a package spec file \n"
" \n"
" --url_mapping=<mapping> Uses the URL mapping(s) specified on \n"
" the command line to load the \n"
" libraries. \n"
@ -1286,7 +1317,8 @@ int main(int argc, char** argv) {
CHECK_RESULT(result);
// Setup package root if specified.
result = DartUtils::SetupPackageRoot(package_root, NULL);
result = DartUtils::SetupPackageRoot(commandline_package_root,
commandline_packages_file);
CHECK_RESULT(result);
Dart_ExitScope();

View file

@ -45,6 +45,9 @@ def BuildOptions():
result.add_option("--package_root",
action="store", type="string",
help="path used to resolve package: imports.")
result.add_option("--packages",
action="store", type="string",
help="package config file used to reasolve package: imports.")
result.add_option("--url_mapping",
default=[],
action="append",
@ -112,6 +115,10 @@ def Main():
if options.package_root:
script_args.append(''.join([ "--package_root=", options.package_root]))
# Pass along the packages if there is one.
if options.packages:
script_args.append(''.join([ "--packages=", options.packages]))
# First setup the vm isolate and regular isolate snapshot output filename.
script_args.append(''.join([ "--vm_isolate_snapshot=",
options.vm_output_bin ]))