@@ -10,22 +10,23 @@ module dub.project;
10
10
import dub.compilers.compiler;
11
11
import dub.dependency;
12
12
import dub.description;
13
+ import dub.generators.generator;
13
14
import dub.internal.utils;
14
15
import dub.internal.vibecompat.core.file ;
15
16
import dub.internal.vibecompat.core.log ;
16
17
import dub.internal.vibecompat.data.json;
17
18
import dub.internal.vibecompat.inet.path;
18
19
import dub.package_;
19
20
import dub.packagemanager;
20
- import dub.generators.generator ;
21
+ import dub.recipe.selection ;
21
22
22
23
import std.algorithm ;
23
24
import std.array ;
24
25
import std.conv : to;
25
26
import std.datetime ;
27
+ import std.encoding : sanitize;
26
28
import std.exception : enforce;
27
29
import std.string ;
28
- import std.encoding : sanitize;
29
30
30
31
/**
31
32
Represents a full project, a root package with its dependencies and package
@@ -1680,13 +1681,9 @@ unittest
1680
1681
"dub.selections.json" within a package's directory.
1681
1682
*/
1682
1683
final class SelectedVersions {
1683
- private struct Selected {
1684
- Dependency dep;
1685
- // Dependency[string] packages;
1686
- }
1687
1684
private {
1688
1685
enum FileVersion = 1 ;
1689
- Selected[ string ] m_selections;
1686
+ Selected m_selections;
1690
1687
bool m_dirty = false ; // has changes since last save
1691
1688
bool m_bare = true ;
1692
1689
}
@@ -1695,13 +1692,17 @@ final class SelectedVersions {
1695
1692
enum defaultFile = " dub.selections.json" ;
1696
1693
1697
1694
// / Constructs a new empty version selection.
1698
- this () {}
1695
+ public this (Selected data = Selected(FileVersion)) @safe pure nothrow @nogc
1696
+ {
1697
+ this .m_selections = data;
1698
+ }
1699
1699
1700
1700
/* * Constructs a new version selection from JSON data.
1701
1701
1702
1702
The structure of the JSON document must match the contents of the
1703
1703
"dub.selections.json" file.
1704
1704
*/
1705
+ deprecated (" Pass a `dub.recipe.selection : Selected` directly" )
1705
1706
this (Json data)
1706
1707
{
1707
1708
deserialize(data);
@@ -1719,7 +1720,7 @@ final class SelectedVersions {
1719
1720
}
1720
1721
1721
1722
// / Returns a list of names for all packages that have a version selection.
1722
- @property string [] selectedPackages() const { return m_selections.keys ; }
1723
+ @property string [] selectedPackages() const { return m_selections.versions. keys ; }
1723
1724
1724
1725
// / Determines if any changes have been made after loading the selections from a file.
1725
1726
@property bool dirty() const { return m_dirty; }
@@ -1730,48 +1731,49 @@ final class SelectedVersions {
1730
1731
// / Removes all selections.
1731
1732
void clear ()
1732
1733
{
1733
- m_selections = null ;
1734
+ m_selections.versions = null ;
1734
1735
m_dirty = true ;
1735
1736
}
1736
1737
1737
1738
// / Duplicates the set of selected versions from another instance.
1738
1739
void set (SelectedVersions versions)
1739
1740
{
1740
- m_selections = versions.m_selections.dup ;
1741
+ m_selections.fileVersion = versions.m_selections.fileVersion;
1742
+ m_selections.versions = versions.m_selections.versions.dup ;
1741
1743
m_dirty = true ;
1742
1744
}
1743
1745
1744
1746
// / Selects a certain version for a specific package.
1745
1747
void selectVersion (string package_id, Version version_)
1746
1748
{
1747
- if (auto ps = package_id in m_selections) {
1748
- if (ps.dep == Dependency(version_))
1749
+ if (auto pdep = package_id in m_selections.versions ) {
1750
+ if (* pdep == Dependency(version_))
1749
1751
return ;
1750
1752
}
1751
- m_selections[package_id] = Selected( Dependency(version_) /* , issuer */ );
1753
+ m_selections.versions [package_id] = Dependency(version_);
1752
1754
m_dirty = true ;
1753
1755
}
1754
1756
1755
1757
// / Selects a certain path for a specific package.
1756
1758
void selectVersion (string package_id, NativePath path)
1757
1759
{
1758
- if (auto ps = package_id in m_selections) {
1759
- if (ps.dep == Dependency(path))
1760
+ if (auto pdep = package_id in m_selections.versions ) {
1761
+ if (* pdep == Dependency(path))
1760
1762
return ;
1761
1763
}
1762
- m_selections[package_id] = Selected( Dependency(path) );
1764
+ m_selections.versions [package_id] = Dependency(path);
1763
1765
m_dirty = true ;
1764
1766
}
1765
1767
1766
1768
// / Selects a certain Git reference for a specific package.
1767
1769
void selectVersionWithRepository (string package_id, Repository repository)
1768
1770
{
1769
1771
const dependency = Dependency(repository);
1770
- if (auto ps = package_id in m_selections) {
1771
- if (ps.dep == dependency)
1772
+ if (auto pdep = package_id in m_selections.versions ) {
1773
+ if (* pdep == dependency)
1772
1774
return ;
1773
1775
}
1774
- m_selections[package_id] = Selected( dependency) ;
1776
+ m_selections.versions [package_id] = dependency;
1775
1777
m_dirty = true ;
1776
1778
}
1777
1779
@@ -1784,14 +1786,14 @@ final class SelectedVersions {
1784
1786
// / Removes the selection for a particular package.
1785
1787
void deselectVersion (string package_id)
1786
1788
{
1787
- m_selections.remove(package_id);
1789
+ m_selections.versions. remove(package_id);
1788
1790
m_dirty = true ;
1789
1791
}
1790
1792
1791
1793
// / Determines if a particular package has a selection set.
1792
1794
bool hasSelectedVersion (string packageId)
1793
1795
const {
1794
- return (packageId in m_selections) ! is null ;
1796
+ return (packageId in m_selections.versions ) ! is null ;
1795
1797
}
1796
1798
1797
1799
/* * Returns the selection for a particular package.
@@ -1804,7 +1806,7 @@ final class SelectedVersions {
1804
1806
Dependency getSelectedVersion (string packageId)
1805
1807
const {
1806
1808
enforce(hasSelectedVersion(packageId));
1807
- return m_selections[packageId].dep ;
1809
+ return m_selections.versions [packageId];
1808
1810
}
1809
1811
1810
1812
/* * Stores the selections to disk.
@@ -1868,10 +1870,10 @@ final class SelectedVersions {
1868
1870
const {
1869
1871
Json json = serializeToJson(m_selections);
1870
1872
Json serialized = Json.emptyObject;
1871
- serialized[" fileVersion" ] = FileVersion ;
1873
+ serialized[" fileVersion" ] = m_selections.fileVersion ;
1872
1874
serialized[" versions" ] = Json.emptyObject;
1873
- foreach (p, v ; m_selections)
1874
- serialized[" versions" ][p] = dependencyToJson(v. dep);
1875
+ foreach (p, dep ; m_selections.versions )
1876
+ serialized[" versions" ][p] = dependencyToJson(dep);
1875
1877
return serialized;
1876
1878
}
1877
1879
@@ -1880,7 +1882,7 @@ final class SelectedVersions {
1880
1882
enforce(cast (int )json[" fileVersion" ] == FileVersion, " Mismatched dub.select.json version: " ~ to! string (cast (int )json[" fileVersion" ]) ~ " vs. " ~ to! string (FileVersion));
1881
1883
clear();
1882
1884
scope (failure) clear ();
1883
- foreach (string p, v ; json[" versions" ])
1884
- m_selections[p] = Selected( dependencyFromJson(v) );
1885
+ foreach (string p, dep ; json[" versions" ])
1886
+ m_selections.versions [p] = dependencyFromJson(dep );
1885
1887
}
1886
1888
}
0 commit comments