From bfa5a3967113590fdb83e1508e40695fdcae5fc3 Mon Sep 17 00:00:00 2001
From: "rnystrom@google.com" <rnystrom@google.com>
Date: Fri, 15 Mar 2013 18:33:05 +0000
Subject: [PATCH] Remove support for SDK dependencies.

BUG=https://code.google.com/p/dart/issues/detail?id=6354

Review URL: https://codereview.chromium.org//12790006

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge@20098 260f80e4-7a28-3924-810f-c04153c831b5
---
 lib/src/sdk_source.dart                       | 54 ---------------
 lib/src/system_cache.dart                     |  4 +-
 lib/src/validator/dependency.dart             |  8 +--
 test/install/pub_install_test.dart            | 12 ++--
 test/install/sdk/check_out_test.dart          | 31 ---------
 .../sdk/check_out_transitive_test.dart        | 38 -----------
 test/sdk_constraint_test.dart                 | 68 ++++++++-----------
 test/test_pub.dart                            |  4 --
 test/update/pub_update_test.dart              | 13 ++--
 test/validator_test.dart                      |  9 ---
 test/version_solver_test.dart                 | 54 +--------------
 11 files changed, 40 insertions(+), 255 deletions(-)
 delete mode 100644 lib/src/sdk_source.dart
 delete mode 100644 test/install/sdk/check_out_test.dart
 delete mode 100644 test/install/sdk/check_out_transitive_test.dart

diff --git a/lib/src/sdk_source.dart b/lib/src/sdk_source.dart
deleted file mode 100644
index c02a1728..00000000
--- a/lib/src/sdk_source.dart
+++ /dev/null
@@ -1,54 +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.
-
-library sdk_source;
-
-import 'dart:async';
-
-import '../../pkg/pathos/lib/path.dart' as path;
-
-import 'io.dart';
-import 'package.dart';
-import 'pubspec.dart';
-import 'sdk.dart' as sdk;
-import 'source.dart';
-import 'utils.dart';
-import 'version.dart';
-
-/// A package source that uses libraries from the Dart SDK.
-class SdkSource extends Source {
-  final String name = "sdk";
-  final bool shouldCache = false;
-
-  /// SDK packages are not individually versioned. Instead, their version is
-  /// inferred from the revision number of the SDK itself.
-  Future<Pubspec> describe(PackageId id) {
-    return defer(() {
-      var packageDir = _getPackagePath(id);
-      // TODO(rnystrom): What if packageDir is null?
-      var pubspec = new Pubspec.load(id.name, packageDir, systemCache.sources);
-      // Ignore the pubspec's version, and use the SDK's.
-      return new Pubspec(id.name, sdk.version, pubspec.dependencies,
-          pubspec.devDependencies, pubspec.environment);
-    });
-  }
-
-  /// Since all the SDK files are already available locally, installation just
-  /// involves symlinking the SDK library into the packages directory.
-  Future<bool> install(PackageId id, String destPath) {
-    return defer(() {
-      var path = _getPackagePath(id);
-      if (path == null) return false;
-
-      return createPackageSymlink(id.name, path, destPath).then((_) => true);
-    });
-  }
-
-  /// Gets the path in the SDK's "pkg" directory to the directory containing
-  /// package [id]. Returns `null` if the package could not be found.
-  String _getPackagePath(PackageId id) {
-    var pkgPath = path.join(sdk.rootDirectory, "pkg", id.description);
-    return dirExists(pkgPath) ? pkgPath : null;
-  }
-}
diff --git a/lib/src/system_cache.dart b/lib/src/system_cache.dart
index 7670b76f..e93f8f4f 100644
--- a/lib/src/system_cache.dart
+++ b/lib/src/system_cache.dart
@@ -17,7 +17,6 @@ import 'log.dart' as log;
 import 'package.dart';
 import 'path_source.dart';
 import 'pubspec.dart';
-import 'sdk_source.dart';
 import 'source.dart';
 import 'source_registry.dart';
 import 'utils.dart';
@@ -26,7 +25,7 @@ import 'version.dart';
 /// The system-wide cache of installed packages.
 ///
 /// This cache contains all packages that are downloaded from the internet.
-/// Packages that are available locally (e.g. from the SDK) don't use this
+/// Packages that are available locally (e.g. path dependencies) don't use this
 /// cache.
 class SystemCache {
   /// The root directory where this package cache is located.
@@ -52,7 +51,6 @@ class SystemCache {
     cache.register(new GitSource());
     cache.register(new HostedSource());
     cache.register(new PathSource());
-    cache.register(new SdkSource());
     cache.sources.setDefault('hosted');
     return cache;
   }
diff --git a/lib/src/validator/dependency.dart b/lib/src/validator/dependency.dart
index de027385..d66059de 100644
--- a/lib/src/validator/dependency.dart
+++ b/lib/src/validator/dependency.dart
@@ -34,13 +34,7 @@ class DependencyValidator extends Validator {
         return new Future.immediate(null);
       }
 
-      if (dependency.constraint.isAny &&
-          // TODO(nweiz): once we have development dependencies (issue 5358), we
-          // should warn about unittest. Until then, it's reasonable not to put
-          // a constraint on it.
-          dependency.name != 'unittest') {
-        _warnAboutConstraint(dependency);
-      }
+      if (dependency.constraint.isAny) _warnAboutConstraint(dependency);
 
       return new Future.immediate(null);
     });
diff --git a/test/install/pub_install_test.dart b/test/install/pub_install_test.dart
index b82565a7..f01bc8fe 100644
--- a/test/install/pub_install_test.dart
+++ b/test/install/pub_install_test.dart
@@ -67,17 +67,13 @@ main() {
   });
 
   integration('does not add a package if it does not have a "lib" directory', () {
-    // Using an SDK source, but this should be true of all sources.
-    dir(sdkPath, [
-      dir('pkg', [
-        dir('foo', [
-          libPubspec('foo', '0.0.0-not.used')
-        ])
-      ])
+    // Using a path source, but this should be true of all sources.
+    dir('foo', [
+      libPubspec('foo', '0.0.0-not.used')
     ]).scheduleCreate();
 
     dir(appPath, [
-      pubspec({"name": "myapp", "dependencies": {"foo": {"sdk": "foo"}}})
+      pubspec({"name": "myapp", "dependencies": {"foo": {"path": "../foo"}}})
     ]).scheduleCreate();
 
     schedulePub(args: ['install'],
diff --git a/test/install/sdk/check_out_test.dart b/test/install/sdk/check_out_test.dart
deleted file mode 100644
index 8d2521b6..00000000
--- a/test/install/sdk/check_out_test.dart
+++ /dev/null
@@ -1,31 +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.
-
-library pub_tests;
-
-import 'dart:io';
-
-import '../../test_pub.dart';
-
-main() {
-  integration('checks out a package from the SDK', () {
-    dir(sdkPath, [
-      dir('pkg', [
-        dir('foo', [
-          libDir('foo', 'foo 0.1.2+3'),
-          libPubspec('foo', '0.0.0-not.used')
-        ])
-      ])
-    ]).scheduleCreate();
-
-    dir(appPath, [
-      pubspec({"name": "myapp", "dependencies": {"foo": {"sdk": "foo"}}})
-    ]).scheduleCreate();
-
-    schedulePub(args: ['install'],
-        output: new RegExp(r"Dependencies installed!$"));
-
-    packagesDir({"foo": "0.1.2+3"}).scheduleValidate();
-  });
-}
diff --git a/test/install/sdk/check_out_transitive_test.dart b/test/install/sdk/check_out_transitive_test.dart
deleted file mode 100644
index 88454b02..00000000
--- a/test/install/sdk/check_out_transitive_test.dart
+++ /dev/null
@@ -1,38 +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.
-
-library pub_tests;
-
-import 'dart:io';
-
-import '../../test_pub.dart';
-
-main() {
-  integration('includes transitive dependencies', () {
-    dir(sdkPath, [
-      dir('pkg', [
-        dir('foo', [
-          libDir('foo', 'foo 0.1.2+3'),
-          libPubspec('foo', '0.0.0-not.used', deps: [{'sdk': 'bar'}])
-        ]),
-        dir('bar', [
-          libDir('bar', 'bar 0.1.2+3'),
-          libPubspec('bar', '0.0.0-not.used')
-        ])
-      ])
-    ]).scheduleCreate();
-
-    dir(appPath, [
-      appPubspec([{'sdk': 'foo'}])
-    ]).scheduleCreate();
-
-    schedulePub(args: ['install'],
-        output: new RegExp(r"Dependencies installed!$"));
-
-    packagesDir({
-      'foo': '0.1.2+3',
-      'bar': '0.1.2+3'
-    }).scheduleValidate();
-  });
-}
diff --git a/test/sdk_constraint_test.dart b/test/sdk_constraint_test.dart
index 7032c611..77ea8544 100644
--- a/test/sdk_constraint_test.dart
+++ b/test/sdk_constraint_test.dart
@@ -44,26 +44,22 @@ main() {
     });
 
     integration("gives an error if some dependencies do not match", () {
-      // Using an SDK source, but this should be true of all sources.
-      dir(sdkPath, [
-        dir("pkg", [
-          dir("foo", [
-            libPubspec("foo", "0.0.1", sdk: ">0.1.3"),
-            libDir("foo")
-          ]),
-          dir("bar", [
-            libPubspec("bar", "0.0.1", sdk: ">0.1.1"),
-            libDir("bar")
-          ])
-        ])
+      // Using a path source, but this should be true of all sources.
+      dir("foo", [
+        libPubspec("foo", "0.0.1", sdk: ">0.1.3"),
+        libDir("foo")
+      ]).scheduleCreate();
+      dir("bar", [
+        libPubspec("bar", "0.0.1", sdk: ">0.1.1"),
+        libDir("bar")
       ]).scheduleCreate();
 
       dir(appPath, [
         pubspec({
           "name": "myapp",
           "dependencies": {
-            "foo": { "sdk": "foo" },
-            "bar": { "sdk": "bar" }
+            "foo": {"path": "../foo"},
+            "bar": {"path": "../bar"}
           },
           "environment": {"sdk": ">2.0.0"}
         })
@@ -82,27 +78,23 @@ main() {
     });
 
     integration("gives an error if a transitive dependency doesn't match", () {
-      // Using an SDK source, but this should be true of all sources.
-      dir(sdkPath, [
-        dir("pkg", [
-          dir("foo", [
-            libPubspec("foo", "0.0.1", deps: [
-              {"sdk": "bar"}
-            ]),
-            libDir("foo")
-          ]),
-          dir("bar", [
-            libPubspec("bar", "0.0.1", sdk: "<0.1.1"),
-            libDir("bar")
-          ])
-        ])
+      // Using a path source, but this should be true of all sources.
+      dir("foo", [
+        libPubspec("foo", "0.0.1", deps: [
+          {"path": "../bar"}
+        ]),
+        libDir("foo")
+      ]).scheduleCreate();
+      dir("bar", [
+        libPubspec("bar", "0.0.1", sdk: "<0.1.1"),
+        libDir("bar")
       ]).scheduleCreate();
 
       dir(appPath, [
         pubspec({
           "name": "myapp",
           "dependencies": {
-            "foo": { "sdk": "foo" }
+            "foo": {"path": "../foo"}
           }
         })
       ]).scheduleCreate();
@@ -119,23 +111,19 @@ main() {
     });
 
     integration("handles a circular dependency on the root package", () {
-      // Using an SDK source, but this should be true of all sources.
-      dir(sdkPath, [
-        dir("pkg", [
-          dir("foo", [
-            libPubspec("foo", "0.0.1", sdk: ">3.0.0", deps: [
-              {"sdk": "myapp"}
-            ]),
-            libDir("foo")
-          ])
-        ])
+      // Using a path source, but this should be true of all sources.
+      dir("foo", [
+        libPubspec("foo", "0.0.1", sdk: ">3.0.0", deps: [
+          {"path": "../myapp"}
+        ]),
+        libDir("foo")
       ]).scheduleCreate();
 
       dir(appPath, [
         pubspec({
           "name": "myapp",
           "dependencies": {
-            "foo": { "sdk": "foo" }
+            "foo": {"path": "../foo"}
           },
           "environment": {"sdk": ">2.0.0"}
         })
diff --git a/test/test_pub.dart b/test/test_pub.dart
index 8c9730d7..bf573fd9 100644
--- a/test/test_pub.dart
+++ b/test/test_pub.dart
@@ -33,7 +33,6 @@ import '../../pub/http.dart';
 import '../../pub/io.dart';
 import '../../pub/path_source.dart';
 import '../../pub/safe_http_server.dart';
-import '../../pub/sdk_source.dart';
 import '../../pub/system_cache.dart';
 import '../../pub/utils.dart';
 import '../../pub/validator.dart';
@@ -411,9 +410,6 @@ Future<Map> _dependencyListToMap(List<Map> dependencies) {
       case "path":
         source = new PathSource();
         break;
-      case "sdk":
-        source = new SdkSource();
-        break;
       default:
         throw 'Unknown source "$sourceName"';
       }
diff --git a/test/update/pub_update_test.dart b/test/update/pub_update_test.dart
index c28951ce..a32b6361 100644
--- a/test/update/pub_update_test.dart
+++ b/test/update/pub_update_test.dart
@@ -10,6 +10,7 @@ import '../../../../pkg/unittest/lib/unittest.dart';
 import '../test_pub.dart';
 
 main() {
+  initConfig();
   group('requires', () {
     integration('a pubspec', () {
       dir(appPath, []).scheduleCreate();
@@ -67,17 +68,13 @@ main() {
 
   integration('does not add a package if it does not have a "lib" '
       'directory', () {
-    // Using an SDK source, but this should be true of all sources.
-    dir(sdkPath, [
-      dir('pkg', [
-        dir('foo', [
-          libPubspec('foo', '0.0.0-not.used')
-        ])
-      ])
+    // Using a path source, but this should be true of all sources.
+    dir('foo', [
+      libPubspec('foo', '0.0.0-not.used')
     ]).scheduleCreate();
 
     dir(appPath, [
-      pubspec({"name": "myapp", "dependencies": {"foo": {"sdk": "foo"}}})
+      pubspec({"name": "myapp", "dependencies": {"foo": {"path": "../foo"}}})
     ]).scheduleCreate();
 
     schedulePub(args: ['update'],
diff --git a/test/validator_test.dart b/test/validator_test.dart
index c4396332..2c369458 100644
--- a/test/validator_test.dart
+++ b/test/validator_test.dart
@@ -161,15 +161,6 @@ main() {
       expectNoValidationError(lib);
     });
 
-    integration('has an unconstrained dependency on "unittest"', () {
-      dir(appPath, [
-        libPubspec("test_pkg", "1.0.0", deps: [
-          {'hosted': 'unittest'}
-        ])
-      ]).scheduleCreate();
-      expectNoValidationError(dependency);
-    });
-
     integration('has a nested directory named "tools"', () {
       dir(appPath, [
         dir("foo", [dir("tools")])
diff --git a/test/version_solver_test.dart b/test/version_solver_test.dart
index 17997564..bdec057b 100644
--- a/test/version_solver_test.dart
+++ b/test/version_solver_test.dart
@@ -69,7 +69,6 @@ Matcher sourceMismatch(String package1, String package2) {
 
 MockSource source1;
 MockSource source2;
-Source versionlessSource;
 
 main() {
   initConfig();
@@ -151,30 +150,6 @@ main() {
     'bang': '1.0.0'
   });
 
-  testResolve('from versionless source', {
-    'myapp 0.0.0': {
-      'foo from versionless': 'any'
-    },
-    'foo 1.2.3 from versionless': {}
-  }, result: {
-    'myapp from root': '0.0.0',
-    'foo from versionless': '1.2.3'
-  });
-
-  testResolve('transitively through versionless source', {
-    'myapp 0.0.0': {
-      'foo from versionless': 'any'
-    },
-    'foo 1.2.3 from versionless': {
-      'bar': '>=1.0.0'
-    },
-    'bar 1.1.0': {}
-  }, result: {
-    'myapp from root': '0.0.0',
-    'foo from versionless': '1.2.3',
-    'bar': '1.1.0'
-  });
-
   testResolve('with compatible locked dependency', {
     'myapp 0.0.0': {
       'foo': 'any'
@@ -426,10 +401,8 @@ testResolve(description, packages, {lockfile, result, Matcher error}) {
     var cache = new SystemCache('.');
     source1 = new MockSource('mock1');
     source2 = new MockSource('mock2');
-    versionlessSource = new MockVersionlessSource();
     cache.register(source1);
     cache.register(source2);
-    cache.register(versionlessSource);
     cache.sources.setDefault(source1.name);
 
     // Build the test package graph.
@@ -553,30 +526,6 @@ class MockSource extends Source {
   }
 }
 
-/// A source used for testing that doesn't natively understand versioning,
-/// similar to how the Git and SDK sources work.
-class MockVersionlessSource extends Source {
-  final Map<String, Package> _packages;
-
-  final String name = 'versionless';
-  final bool shouldCache = false;
-
-  MockVersionlessSource()
-    : _packages = <String, Package>{};
-
-  Future<bool> install(PackageId id, String path) {
-    throw 'no';
-  }
-
-  Future<Pubspec> describe(PackageId id) {
-    return new Future<Pubspec>.immediate(_packages[id.description].pubspec);
-  }
-
-  void addPackage(Package package) {
-    _packages[package.name] = package;
-  }
-}
-
 void parseSource(String description,
     callback(bool isDev, String name, Source source)) {
   var isDev = false;
@@ -592,8 +541,7 @@ void parseSource(String description,
   var sourceNames = {
     'mock1': source1,
     'mock2': source2,
-    'root': null,
-    'versionless': versionlessSource
+    'root': null
   };
 
   var match = new RegExp(r"(.*) from (.*)").firstMatch(description);
-- 
GitLab