Skip to content

Commit 8ea0bb1

Browse files
authored
Merge pull request #191 from LoopPerfect/feat/private-receipts
Feat/private receipts
2 parents 520e742 + 30861a2 commit 8ea0bb1

18 files changed

+961
-429
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
/buck-out/
1414
.buckconfig.local
1515

16+
fsi.fsx
17+
1618
## Ignore Visual Studio temporary files, build results, and
1719
## files generated by popular Visual Studio add-ons.
1820

buckaroo-tests/Lock.fs

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
module Buckaroo.Tests.Lock
2+
3+
open Xunit
4+
open Buckaroo
5+
6+
[<Fact>]
7+
let ``Lock.parse works correctly 1`` () =
8+
let actual =
9+
[
10+
"manifest = \"aabbccddee\"";
11+
]
12+
|> String.concat "\n"
13+
|> Lock.parse
14+
15+
let expected = {
16+
ManifestHash = "aabbccddee";
17+
Dependencies = Set.empty;
18+
Packages = Map.empty;
19+
}
20+
21+
Assert.Equal(Result.Ok expected, actual)
22+
23+
[<Fact>]
24+
let ``Lock.parse works correctly 2`` () =
25+
let actual =
26+
[
27+
"manifest = \"aabbccddee\"";
28+
"";
29+
"[[dependency]]";
30+
"package = \"abc/def\"";
31+
"target = \"//:def\"";
32+
"";
33+
"[lock.\"abc/def\"]";
34+
"url = \"https://www.abc.com/def.zip\"";
35+
"version = \"1.2.3\"";
36+
"sha256 = \"aabbccddee\"";
37+
]
38+
|> String.concat "\n"
39+
|> Lock.parse
40+
41+
let expected = {
42+
ManifestHash = "aabbccddee";
43+
Dependencies =
44+
[
45+
{
46+
Package = PackageIdentifier.Adhoc { Owner = "abc"; Project = "def" };
47+
Target = {
48+
Folders = [];
49+
Name = "def";
50+
}
51+
}
52+
]
53+
|> Set.ofSeq;
54+
Packages =
55+
Map.empty
56+
|> Map.add
57+
(PackageIdentifier.Adhoc { Owner = "abc"; Project = "def" })
58+
{
59+
Version = Version.SemVerVersion { SemVer.zero with Major = 1; Minor = 2; Patch = 3 };
60+
Location = PackageLocation.Http {
61+
Url = "https://www.abc.com/def.zip";
62+
StripPrefix = None;
63+
Type = None;
64+
Sha256 = "aabbccddee";
65+
};
66+
PrivatePackages = Map.empty;
67+
};
68+
}
69+
70+
Assert.Equal(Result.Ok expected, actual)
71+
72+
[<Fact>]
73+
let ``Lock.parse works correctly 3`` () =
74+
let actual =
75+
[
76+
"manifest = \"aabbccddee\"";
77+
"";
78+
"[[dependency]]";
79+
"package = \"abc/def\"";
80+
"target = \"//:def\"";
81+
"";
82+
"[lock.\"abc/def\"]";
83+
"url = \"https://www.abc.com/def.zip\"";
84+
"version = \"1.2.3\"";
85+
"sha256 = \"aabbccddee\"";
86+
"";
87+
"[lock.\"abc/def\".lock.\"ijk/xyz\"]";
88+
"url = \"https://www.ijk.com/xyz.zip\"";
89+
"version = \"1\"";
90+
"sha256 = \"aabbccddee\"";
91+
"";
92+
]
93+
|> String.concat "\n"
94+
|> Lock.parse
95+
96+
let expected = {
97+
ManifestHash = "aabbccddee";
98+
Dependencies =
99+
[
100+
{
101+
Package = PackageIdentifier.Adhoc { Owner = "abc"; Project = "def" };
102+
Target = {
103+
Folders = [];
104+
Name = "def";
105+
}
106+
}
107+
]
108+
|> Set.ofSeq;
109+
Packages =
110+
Map.empty
111+
|> Map.add
112+
(PackageIdentifier.Adhoc { Owner = "abc"; Project = "def" })
113+
{
114+
Version = Version.SemVerVersion { SemVer.zero with Major = 1; Minor = 2; Patch = 3 };
115+
Location = PackageLocation.Http {
116+
Url = "https://www.abc.com/def.zip";
117+
StripPrefix = None;
118+
Type = None;
119+
Sha256 = "aabbccddee";
120+
};
121+
PrivatePackages =
122+
Map.empty
123+
|> Map.add
124+
(PackageIdentifier.Adhoc { Owner = "ijk"; Project = "xyz" })
125+
{
126+
Version = Version.SemVerVersion { SemVer.zero with Major = 1; };
127+
Location = PackageLocation.Http {
128+
Url = "https://www.ijk.com/xyz.zip";
129+
StripPrefix = None;
130+
Type = None;
131+
Sha256 = "aabbccddee";
132+
};
133+
PrivatePackages = Map.empty;
134+
};
135+
};
136+
}
137+
138+
Assert.Equal(Result.Ok expected, actual)

buckaroo-tests/Paths.fs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module Buckaroo.Tests.Paths
2+
3+
open System
4+
open System.IO
5+
open Xunit
6+
open Buckaroo
7+
8+
let private sep = new String([| Path.DirectorySeparatorChar |])
9+
10+
11+
[<Fact>]
12+
let ``Paths.normalize works correctly`` () =
13+
let cases = [
14+
(".", "");
15+
("a", "a");
16+
("a" + sep + "", "a" + sep + "");
17+
("" + sep + "a" + sep + "", "" + sep + "a" + sep + "");
18+
("a" + sep + " " + sep + "b", "a" + sep + " " + sep + "b");
19+
("" + sep + "a" + sep + "", "" + sep + "a" + sep + "");
20+
("b", "a" + sep + ".." + sep + "b");
21+
("c" + sep + "d", "a" + sep + ".." + sep + "b" + sep + ".." + sep + "c" + sep + "." + sep + "." + sep + "." + sep + "d");
22+
(".." + sep + ".." + sep + ".." + sep + "a" + sep + "b" + sep + "c", ".." + sep + ".." + sep + ".." + sep + "a" + sep + "b" + sep + "c");
23+
(".." + sep + ".." + sep + ".." + sep + "a", ".." + sep + ".." + sep + ".." + sep + "." + sep + "a");
24+
(
25+
".." + sep + ".." + sep + ".." + sep + ".." + sep + ".." + sep + ".." + sep + "buckaroo" + sep + "github" + sep + "buckaroo-pm" + sep + "pkg-config-cairo",
26+
".." + sep + ".." + sep + ".." + sep + ".." + sep + ".." + sep + ".." + sep + "." + sep + "buckaroo" + sep + "github" + sep + "buckaroo-pm" + sep + "pkg-config-cairo"
27+
);
28+
]
29+
30+
for (expected, input) in cases do
31+
Assert.Equal(expected, Paths.normalize input)

buckaroo-tests/buckaroo-tests.fsproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
<Compile Include="PackageIdentifier.fs" />
2222
<Compile Include="Manifest.fs" />
2323
<Compile Include="Bash.fs" />
24+
<Compile Include="Lock.fs" />
25+
<Compile Include="Paths.fs" />
2426
<Compile Include="Program.fs" />
2527
</ItemGroup>
2628

buckaroo/Command.fs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ module Command =
118118
| Failure(error, _, _) -> Result.Error error
119119

120120
let listDependencies = async {
121-
let! manifest = Tasks.readManifest
121+
let! manifest = Tasks.readManifest "."
122122
manifest.Dependencies
123123
|> Seq.distinct
124124
|> Seq.map Dependency.show
@@ -141,7 +141,7 @@ module Command =
141141
let add (context : Tasks.TaskContext) dependencies = async {
142142
let sourceExplorer = context.SourceExplorer
143143

144-
let! manifest = Tasks.readManifest
144+
let! manifest = Tasks.readManifest "."
145145
let newManifest = {
146146
manifest with
147147
Dependencies =
@@ -167,6 +167,7 @@ module Command =
167167
do! Tasks.writeLock (Lock.fromManifestAndSolution newManifest solution)
168168
do! InstallCommand.task context
169169
| _ -> ()
170+
System.Console.WriteLine ("Success. ")
170171
return ()
171172
}
172173

buckaroo/Files.fs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ let writeFile (path : string) (content : string) = async {
3535
return! sw.WriteAsync(content) |> Async.AwaitTask
3636
}
3737

38+
let touch (path : string) = async {
39+
if File.Exists path |> not
40+
then
41+
do! writeFile path ""
42+
}
43+
3844
let readFile (path : string) = async {
3945
use sr = new StreamReader(path)
4046
return! sr.ReadToEndAsync() |> Async.AwaitTask

0 commit comments

Comments
 (0)