mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 15:21:54 +00:00
Put a snapshot of pub in the SDK.
BUG=9117 Review URL: https://codereview.chromium.org//13966011 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@21979 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
c2b4a4e4a9
commit
cc6e2f7b93
5
dart.gyp
5
dart.gyp
|
@ -50,6 +50,7 @@
|
|||
'dependencies': [
|
||||
'runtime/dart-runtime.gyp:dart',
|
||||
'utils/compiler/compiler.gyp:dart2js',
|
||||
'utils/pub/pub.gyp:pub',
|
||||
'analyzer',
|
||||
'compiler',
|
||||
],
|
||||
|
@ -62,6 +63,7 @@
|
|||
'tools/create_sdk.py',
|
||||
'<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)dart<(EXECUTABLE_SUFFIX)',
|
||||
'<(SHARED_INTERMEDIATE_DIR)/utils_wrapper.dart.snapshot',
|
||||
'<(SHARED_INTERMEDIATE_DIR)/pub.dart.snapshot',
|
||||
'<(PRODUCT_DIR)/analyzer/bin/dart_analyzer',
|
||||
'<(PRODUCT_DIR)/dartanalyzer/dartanalyzer.jar',
|
||||
],
|
||||
|
@ -72,8 +74,7 @@
|
|||
'python',
|
||||
'tools/create_sdk.py',
|
||||
'--sdk_output_dir', '<(PRODUCT_DIR)/dart-sdk',
|
||||
'--utils_snapshot_location',
|
||||
'<(SHARED_INTERMEDIATE_DIR)/utils_wrapper.dart.snapshot'
|
||||
'--snapshot_location', '<(SHARED_INTERMEDIATE_DIR)/'
|
||||
],
|
||||
'message': 'Creating SDK.',
|
||||
},
|
||||
|
|
|
@ -8,5 +8,4 @@
|
|||
BIN_DIR="$(cd "${0%/*}" ; pwd -P)"
|
||||
DART_SDK="$(cd "${BIN_DIR%/*}" ; pwd -P)"
|
||||
|
||||
exec "$BIN_DIR"/dart --package-root="$DART_SDK"/packages/ \
|
||||
"$DART_SDK"/lib/_internal/pub/bin/pub.dart $@
|
||||
exec "$BIN_DIR"/dart "$DART_SDK"/bin/snapshots/pub.dart.snapshot $@
|
||||
|
|
|
@ -13,4 +13,4 @@ if %SCRIPTPATH:~-1%==\ set SCRIPTPATH=%SCRIPTPATH:~0,-1%
|
|||
|
||||
:: The trailing forward slash in --package-root is required because of issue
|
||||
:: 9499.
|
||||
"%SCRIPTPATH%\dart.exe" --package-root="%SCRIPTPATH%\..\packages/" "%SCRIPTPATH%\..\lib\_internal\pub\bin\pub.dart" %*
|
||||
"%SCRIPTPATH%\dart.exe" "%SCRIPTPATH%\..\bin\snapshots\pub.dart.snapshot" %*
|
||||
|
|
|
@ -16,6 +16,7 @@ import 'package:http/http.dart' show ByteStream;
|
|||
import 'error_group.dart';
|
||||
import 'exit_codes.dart' as exit_codes;
|
||||
import 'log.dart' as log;
|
||||
import 'sdk.dart' as sdk;
|
||||
import 'utils.dart';
|
||||
|
||||
export 'package:http/http.dart' show ByteStream;
|
||||
|
@ -252,9 +253,30 @@ void createPackageSymlink(String name, String target, String symlink,
|
|||
}
|
||||
}
|
||||
|
||||
/// Resolves [target] relative to the root directory of pub.
|
||||
String relativeToPub(String target) => path.normalize(path.join(
|
||||
path.dirname(libraryPath('pub.io')), '..', '..', target));
|
||||
/// Whether pub is running from within the Dart SDK, as opposed to from the Dart
|
||||
/// source repository.
|
||||
bool get runningFromSdk => path.extension(new Options().script) == 'snapshot';
|
||||
|
||||
/// Resolves [target] relative to the path to pub's `resource` directory.
|
||||
String resourcePath(String target) {
|
||||
if (runningFromSdk) {
|
||||
return path.join(
|
||||
sdk.rootDirectory, 'lib', '_internal', 'pub', 'resource', target);
|
||||
} else {
|
||||
return path.join(
|
||||
path.dirname(libraryPath('pub.io')), '..', '..', 'resource', target);
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the path to the root of the Dart repository. This will throw a
|
||||
/// [StateError] if it's called when running pub from the SDK.
|
||||
String get repoRoot {
|
||||
if (runningFromSdk) {
|
||||
throw new StateError("Can't get the repo root from the SDK.");
|
||||
}
|
||||
return path.join(
|
||||
path.dirname(libraryPath('pub.io')), '..', '..', '..', '..', '..', '..');
|
||||
}
|
||||
|
||||
/// A line-by-line stream of standard input.
|
||||
final Stream<String> stdinLines = streamToLines(
|
||||
|
@ -538,6 +560,11 @@ Future<bool> extractTarGz(Stream<List<int>> stream, String destination) {
|
|||
});
|
||||
}
|
||||
|
||||
String get pathTo7zip {
|
||||
if (runningFromSdk) return resourcePath(path.join('7zip', '7za.exe'));
|
||||
return path.join(repoRoot, 'third_party', '7zip', '7za.exe');
|
||||
}
|
||||
|
||||
Future<bool> _extractTarGzWindows(Stream<List<int>> stream,
|
||||
String destination) {
|
||||
// TODO(rnystrom): In the repo's history, there is an older implementation of
|
||||
|
@ -547,11 +574,6 @@ Future<bool> _extractTarGzWindows(Stream<List<int>> stream,
|
|||
// read from stdin instead of a file. Consider resurrecting that version if
|
||||
// we can figure out why it fails.
|
||||
|
||||
// Note: This line of code gets munged by create_sdk.py to be the correct
|
||||
// relative path to 7zip in the SDK.
|
||||
var pathTo7zip = '../../../../third_party/7zip/7za.exe';
|
||||
var command = relativeToPub(pathTo7zip);
|
||||
|
||||
return withTempDir((tempDir) {
|
||||
// Write the archive to a temp file.
|
||||
var dataFile = path.join(tempDir, 'data.tar.gz');
|
||||
|
@ -560,7 +582,7 @@ Future<bool> _extractTarGzWindows(Stream<List<int>> stream,
|
|||
// first we un-gzip it to a tar file.
|
||||
// Note: Setting the working directory instead of passing in a full file
|
||||
// path because 7zip says "A full path is not allowed here."
|
||||
return runProcess(command, ['e', 'data.tar.gz'], workingDir: tempDir);
|
||||
return runProcess(pathTo7zip, ['e', 'data.tar.gz'], workingDir: tempDir);
|
||||
}).then((result) {
|
||||
if (result.exitCode != 0) {
|
||||
throw new Exception('Could not un-gzip (exit code ${result.exitCode}). '
|
||||
|
@ -577,7 +599,7 @@ Future<bool> _extractTarGzWindows(Stream<List<int>> stream,
|
|||
});
|
||||
|
||||
// Untar the archive into the destination directory.
|
||||
return runProcess(command, ['x', tarFile], workingDir: destination);
|
||||
return runProcess(pathTo7zip, ['x', tarFile], workingDir: destination);
|
||||
}).then((result) {
|
||||
if (result.exitCode != 0) {
|
||||
throw new Exception('Could not un-tar (exit code ${result.exitCode}). '
|
||||
|
@ -635,20 +657,15 @@ ByteStream createTarGz(List contents, {baseDir}) {
|
|||
var args = ["a", "-w$baseDir", tarFile];
|
||||
args.addAll(contents.map((entry) => '-i!"$entry"'));
|
||||
|
||||
// Note: This line of code gets munged by create_sdk.py to be the correct
|
||||
// relative path to 7zip in the SDK.
|
||||
var pathTo7zip = '../../../../third_party/7zip/7za.exe';
|
||||
var command = relativeToPub(pathTo7zip);
|
||||
|
||||
// We're passing 'baseDir' both as '-w' and setting it as the working
|
||||
// directory explicitly here intentionally. The former ensures that the
|
||||
// files added to the archive have the correct relative path in the archive.
|
||||
// The latter enables relative paths in the "-i" args to be resolved.
|
||||
return runProcess(command, args, workingDir: baseDir).then((_) {
|
||||
return runProcess(pathTo7zip, args, workingDir: baseDir).then((_) {
|
||||
// GZIP it. 7zip doesn't support doing both as a single operation. Send
|
||||
// the output to stdout.
|
||||
args = ["a", "unused", "-tgzip", "-so", tarFile];
|
||||
return startProcess(command, args);
|
||||
return startProcess(pathTo7zip, args);
|
||||
}).then((process) {
|
||||
// Ignore 7zip's stderr. 7zip writes its normal output to stderr. We don't
|
||||
// want to show that since it's meaningless.
|
||||
|
|
|
@ -115,7 +115,7 @@ void run() {
|
|||
break;
|
||||
}
|
||||
|
||||
SecureSocket.initialize(database: relativeToPub('resource/certs'));
|
||||
SecureSocket.initialize(database: resourcePath('certs'));
|
||||
|
||||
var cacheDir;
|
||||
if (Platform.environment.containsKey('PUB_CACHE')) {
|
||||
|
|
|
@ -389,22 +389,12 @@ ScheduledProcess startPub({List args, Future<Uri> tokenEndpoint}) {
|
|||
description: args.isEmpty ? 'pub' : 'pub ${args.first}');
|
||||
}
|
||||
|
||||
/// Whether pub is running from within the Dart SDK, as opposed to from the Dart
|
||||
/// source repository.
|
||||
bool get _runningFromSdk =>
|
||||
fileExists(relativeToPub(path.join('..', '..', '..', '..', 'version')));
|
||||
|
||||
// TODO(nweiz): use the built-in mechanism for accessing this once it exists
|
||||
// (issue 9119).
|
||||
/// The path to the `packages` directory from which pub loads its dependencies.
|
||||
String get _packageRoot {
|
||||
if (_runningFromSdk) {
|
||||
return path.absolute(relativeToPub(
|
||||
path.join('..', '..', '..', '..', 'packages')));
|
||||
} else {
|
||||
return path.absolute(path.join(
|
||||
path.dirname(new Options().executable), '..', '..', 'packages'));
|
||||
}
|
||||
return path.absolute(path.join(
|
||||
path.dirname(new Options().executable), '..', '..', 'packages'));
|
||||
}
|
||||
|
||||
/// Skips the current test if Git is not installed. This validates that the
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
# ......pub
|
||||
# ......snapshots/
|
||||
# ........utils_wrapper.dart.snapshot
|
||||
# ........pub.dart.snapshot
|
||||
# ....include/
|
||||
# ......dart_api.h
|
||||
# ......dart_debugger_api.h
|
||||
|
@ -78,8 +79,8 @@ def GetOptions():
|
|||
options = optparse.OptionParser(usage='usage: %prog [options]')
|
||||
options.add_option("--sdk_output_dir",
|
||||
help='Where to output the sdk')
|
||||
options.add_option("--utils_snapshot_location",
|
||||
help='Location of the utils snapshot.')
|
||||
options.add_option("--snapshot_location",
|
||||
help='Location of the snapshots.')
|
||||
return options.parse_args()
|
||||
|
||||
|
||||
|
@ -119,8 +120,11 @@ def CopyDartScripts(home, sdk_root):
|
|||
os.path.join(sdk_root, 'bin'))
|
||||
|
||||
|
||||
def CopySnapshots(snapshot, sdk_root):
|
||||
copyfile(snapshot, join(sdk_root, 'bin', 'snapshots', basename(snapshot)))
|
||||
def CopySnapshots(snapshots, sdk_root):
|
||||
for snapshot in ['utils_wrapper', 'pub']:
|
||||
snapshot += '.dart.snapshot'
|
||||
copyfile(join(snapshots, snapshot),
|
||||
join(sdk_root, 'bin', 'snapshots', snapshot))
|
||||
|
||||
|
||||
def Main(argv):
|
||||
|
@ -132,7 +136,7 @@ def Main(argv):
|
|||
SDK = options.sdk_output_dir
|
||||
SDK_tmp = '%s.tmp' % SDK
|
||||
|
||||
SNAPSHOT = options.utils_snapshot_location
|
||||
SNAPSHOT = options.snapshot_location
|
||||
|
||||
# TODO(dgrove) - deal with architectures that are not ia32.
|
||||
|
||||
|
@ -205,7 +209,9 @@ def Main(argv):
|
|||
|
||||
os.makedirs(join(LIB, 'html'))
|
||||
|
||||
for library in ['_internal',
|
||||
for library in [join('_internal', 'compiler'),
|
||||
join('_internal', 'dartdoc'),
|
||||
join('_internal', 'pub', 'resource'),
|
||||
'async', 'collection', '_collection_dev', 'core',
|
||||
'crypto', 'io', 'isolate',
|
||||
join('chrome', 'dart2js'), join('chrome', 'dartium'),
|
||||
|
@ -219,7 +225,12 @@ def Main(argv):
|
|||
join('web_gl', 'dart2js'), join('web_gl', 'dartium'),
|
||||
join('web_sql', 'dart2js'), join('web_sql', 'dartium')]:
|
||||
copytree(join(HOME, 'sdk', 'lib', library), join(LIB, library),
|
||||
ignore=ignore_patterns('*.svn', 'doc', '*.py', '*.gypi', '*.sh'))
|
||||
ignore=ignore_patterns('*.svn', 'doc', '*.py', '*.gypi', '*.sh',
|
||||
'.gitignore'))
|
||||
|
||||
# Copy lib/_internal/libraries.dart.
|
||||
copyfile(join(HOME, 'sdk', 'lib', '_internal', 'libraries.dart'),
|
||||
join(LIB, '_internal', 'libraries.dart'))
|
||||
|
||||
# Create and copy packages.
|
||||
PACKAGES = join(SDK_tmp, 'packages')
|
||||
|
@ -268,22 +279,12 @@ def Main(argv):
|
|||
for jarFile in jarFiles:
|
||||
copyfile(jarFile, join(DARTANALYZER_DEST, os.path.basename(jarFile)))
|
||||
|
||||
PUB_DEST = join(SDK_tmp, 'lib', '_internal', 'pub')
|
||||
|
||||
|
||||
# Copy in 7zip for Windows.
|
||||
if HOST_OS == 'win32':
|
||||
copytree(join(HOME, 'third_party', '7zip'),
|
||||
join(PUB_DEST, 'resource', '7zip'),
|
||||
join(SDK_tmp, 'lib', '_internal', 'pub', 'resource', '7zip'),
|
||||
ignore=ignore_patterns('.svn'))
|
||||
|
||||
ReplaceInFiles([
|
||||
join(PUB_DEST, 'lib', 'src', 'io.dart'),
|
||||
], [
|
||||
("../../../../third_party/7zip/7za.exe",
|
||||
"resource/7zip/7za.exe"),
|
||||
])
|
||||
|
||||
# Copy dart2js/dartdoc/pub.
|
||||
CopyDartScripts(HOME, SDK_tmp)
|
||||
CopySnapshots(SNAPSHOT, SDK_tmp)
|
||||
|
|
36
utils/pub/pub.gyp
Normal file
36
utils/pub/pub.gyp
Normal file
|
@ -0,0 +1,36 @@
|
|||
# Copyright (c) 2013, 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.
|
||||
|
||||
{
|
||||
'targets': [
|
||||
{
|
||||
'target_name': 'pub',
|
||||
'type': 'none',
|
||||
'dependencies': [
|
||||
'../../runtime/dart-runtime.gyp:dart',
|
||||
],
|
||||
'actions': [
|
||||
{
|
||||
'action_name': 'generate_pub_snapshot',
|
||||
'inputs': [
|
||||
'<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)dart<(EXECUTABLE_SUFFIX)',
|
||||
'<!@(["python", "../../tools/list_files.py", "\\.dart$", "../../sdk/lib/_internal/pub"])',
|
||||
'../../sdk/lib/_internal/libraries.dart',
|
||||
'<!@(["python", "../../tools/list_files.py", "\\.dart$", "../../sdk/lib/_internal/compiler"])',
|
||||
'<!@(["python", "../../tools/list_files.py", "\\.dart$", "../../pkg"])',
|
||||
],
|
||||
'outputs': [
|
||||
'<(SHARED_INTERMEDIATE_DIR)/pub.dart.snapshot',
|
||||
],
|
||||
'action': [
|
||||
'<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)dart<(EXECUTABLE_SUFFIX)',
|
||||
'--package-root=<(PRODUCT_DIR)/packages/',
|
||||
'--generate-script-snapshot=<(SHARED_INTERMEDIATE_DIR)/pub.dart.snapshot',
|
||||
'../../sdk/lib/_internal/pub/bin/pub.dart',
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
Loading…
Reference in a new issue