Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'tag_pattern' feature to git dependencies #4427

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/src/command/add.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ For example:
help: 'Path of git package in repository',
hide: true,
);
argParser.addOption(
'git-tag-pattern',
help: 'The tag-pattern to search for versions in repository',
hide: true,
);
argParser.addOption(
'hosted-url',
help: 'URL of package host server',
Expand Down Expand Up @@ -527,6 +532,11 @@ Specify multiple sdk packages with descriptors.''');
if (gitUrl == null) {
usageException('The `--git-url` is required for git dependencies.');
}
if (argResults.gitRef != null && argResults.tagPattern != null) {
usageException(
'Cannot provide both `--git-ref` and `--git-tag-pattern`.',
);
}

/// Process the git options to return the simplest representation to be
/// added to the pubspec.
Expand All @@ -538,6 +548,7 @@ Specify multiple sdk packages with descriptors.''');
containingDir: p.current,
ref: argResults.gitRef,
path: argResults.gitPath,
tagPattern: argResults.tagPattern,
),
);
} on FormatException catch (e) {
Expand Down Expand Up @@ -775,6 +786,8 @@ extension on ArgResults {
bool get isDryRun => flag('dry-run');
String? get gitUrl => this['git-url'] as String?;
String? get gitPath => this['git-path'] as String?;
String? get tagPattern => this['git-tag-pattern'] as String?;

String? get gitRef => this['git-ref'] as String?;
String? get hostedUrl => this['hosted-url'] as String?;
String? get path => this['path'] as String?;
Expand Down
2 changes: 2 additions & 0 deletions lib/src/command/dependency_services.dart
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ class DependencyServicesApplyCommand extends PubCommand {
} else if (targetRevision != null &&
(lockFileYaml['packages'] as Map).containsKey(targetPackage)) {
final ref = entrypoint.lockFile.packages[targetPackage]!.toRef();

final currentDescription = ref.description as GitDescription;
final updatedRef = PackageRef(
targetPackage,
Expand All @@ -405,6 +406,7 @@ class DependencyServicesApplyCommand extends PubCommand {
path: currentDescription.path,
ref: targetRevision,
containingDir: directory,
tagPattern: currentDescription.tagPattern,
),
);
final versions = await cache.getVersions(updatedRef);
Expand Down
7 changes: 3 additions & 4 deletions lib/src/command/upgrade.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import '../package_name.dart';
import '../pubspec.dart';
import '../pubspec_utils.dart';
import '../solver.dart';
import '../source/hosted.dart';
import '../utils.dart';

/// Handles the `upgrade` pub command.
Expand Down Expand Up @@ -247,11 +246,11 @@ be direct 'dependencies' or 'dev_dependencies', following packages are not:
// Mapping from original to changed value.
var changes = <Package, Map<PackageRange, PackageRange>>{};
for (final package in entrypoint.workspaceRoot.transitiveWorkspace) {
final declaredHostedDependencies = [
final declaredUpgradableDependencies = [
...package.dependencies.values,
...package.devDependencies.values,
].where((dep) => dep.source is HostedSource);
for (final dep in declaredHostedDependencies) {
].where((dep) => dep.description.hasMultipleVersions);
for (final dep in declaredUpgradableDependencies) {
final resolvedPackage = resolvedPackages[dep.name]!;
if (!toUpgrade.contains(dep.name)) {
// If we're not trying to upgrade this package, or it wasn't in the
Expand Down
2 changes: 2 additions & 0 deletions lib/src/global_packages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,15 @@ class GlobalPackages {
required bool overwriteBinStubs,
String? path,
String? ref,
String? tagPattern,
}) async {
final name = await cache.git.getPackageNameFromRepo(
repo,
ref,
path,
cache,
relativeTo: p.current,
tagPattern: tagPattern,
);

// TODO(nweiz): Add some special handling for git repos that contain path
Expand Down
3 changes: 3 additions & 0 deletions lib/src/language_version.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class LanguageVersion implements Comparable<LanguageVersion> {

bool get supportsWorkspaces => this >= firstVersionWithWorkspaces;

bool get supportsTagPattern => this >= firstVersionWithTagPattern;

/// Minimum language version at which short hosted syntax is supported.
///
/// This allows `hosted` dependencies to be expressed as:
Expand Down Expand Up @@ -109,6 +111,7 @@ class LanguageVersion implements Comparable<LanguageVersion> {
static const firstVersionWithNullSafety = LanguageVersion(2, 12);
static const firstVersionWithShorterHostedSyntax = LanguageVersion(2, 15);
static const firstVersionWithWorkspaces = LanguageVersion(3, 5);
static const firstVersionWithTagPattern = LanguageVersion(3, 7);

/// Transform language version to string that can be parsed with
/// [LanguageVersion.parse].
Expand Down
2 changes: 1 addition & 1 deletion lib/src/package_name.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class PackageRange {
bool get _showVersionConstraint {
if (isRoot) return false;
if (!constraint.isAny) return true;
return description.source.hasMultipleVersions;
return description.hasMultipleVersions;
}

/// Returns a copy of `this` with the same semantics, but with a `^`-style
Expand Down
5 changes: 4 additions & 1 deletion lib/src/solver/version_solver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,10 @@ class VersionSolver {
// can't be downgraded.
if (_type == SolveType.downgrade) {
final locked = _lockFile.packages[package];
if (locked != null && !locked.source.hasMultipleVersions) return locked;
if (locked != null &&
!locked.description.description.hasMultipleVersions) {
return locked;
}
}

if (_unlock.isEmpty || _unlock.contains(package)) return null;
Expand Down
11 changes: 5 additions & 6 deletions lib/src/source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ abstract class Source {
/// all sources.
String get name;

/// Whether this source can choose between multiple versions of the same
/// package during version solving.
///
/// Defaults to `false`.
bool get hasMultipleVersions => false;

/// Parses a [PackageRef] from a name and a user-provided [description].
///
/// When a [Pubspec] is parsed, it reads in the description for each
Expand Down Expand Up @@ -190,6 +184,11 @@ abstract class Source {
/// with a version constraint.
abstract class Description {
Source get source;

/// Whether the source can choose between multiple versions of this
/// package during version solving.
bool get hasMultipleVersions;

Object? serializeForPubspec({
required String? containingDir,
required LanguageVersion languageVersion,
Expand Down
Loading