Skip to content

Commit

Permalink
Merge pull request #357 from LoopPerfect/feature/bazel
Browse files Browse the repository at this point in the history
feature/bazel
  • Loading branch information
nikhedonia authored Oct 8, 2019
2 parents b84a015 + 6ee3037 commit 49b5425
Show file tree
Hide file tree
Showing 40 changed files with 999 additions and 371 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj

Expand Down
10 changes: 5 additions & 5 deletions buckaroo-cli/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ open System
[<EntryPoint>]
let main argv =
async {
let session = Guid.NewGuid() |> string
let session = Guid.NewGuid () |> string
let input = argv |> String.concat " "

let! telemetry =
Expand All @@ -15,12 +15,12 @@ let main argv =
let! exitCode = async {
try
match Buckaroo.Command.parse input with
| Result.Ok (command, loggingLevel, fetchStyle) ->
do!
| Ok (command, loggingLevel, fetchStyle) ->
let! exitCode =
command
|> Buckaroo.Command.runCommand loggingLevel fetchStyle
return 0
| Result.Error error ->
return exitCode
| Error error ->
Console.WriteLine error
return 1
with error ->
Expand Down
16 changes: 8 additions & 8 deletions buckaroo-tests/Lock.fs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ let ``Lock.parse works correctly 2`` () =
|> Lock.parse

let expected = {
ManifestHash = "aabbccddee";
ManifestHash = "aabbccddee"
Dependencies =
[
{
Package = PackageIdentifier.Adhoc { Owner = "abc"; Project = "def" };
PackagePath = [], PackageIdentifier.Adhoc { Owner = "abc"; Project = "def" }
Target = {
Folders = [];
Name = "def";
Folders = []
Name = "def"
}
}
]
Expand Down Expand Up @@ -117,14 +117,14 @@ let ``Lock.parse works correctly 3`` () =
|> Lock.parse

let expected = {
ManifestHash = "aabbccddee";
ManifestHash = "aabbccddee"
Dependencies =
[
{
Package = PackageIdentifier.Adhoc { Owner = "abc"; Project = "def" };
PackagePath = [], PackageIdentifier.Adhoc { Owner = "abc"; Project = "def" }
Target = {
Folders = [];
Name = "def";
Folders = []
Name = "def"
}
}
]
Expand Down
52 changes: 42 additions & 10 deletions buckaroo-tests/Manifest.fs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
module Buckaroo.Tests.Manifest

open System
open Xunit
open FSharpx

open Buckaroo
open Buckaroo.Tests
open Buckaroo
open Buckaroo.Tests

Expand Down Expand Up @@ -107,18 +104,26 @@ let ``Manifest.toToml roundtrip 1`` () =
[<Fact>]
let ``Manifest.toToml roundtrip 2`` () =
let expected : Manifest = {
Targets = Set [
{Folders=["foo"; "bar"]; Name = "xxx"}
{Folders=["foo"; "bar"]; Name = "yyy"}
]
Tags = Set ["c++"; "java"; "ml"]
Targets =
Set [
{ Folders = [ "foo"; "bar"]; Name = "xxx" }
{ Folders = [ "foo"; "bar"]; Name = "yyy" }
]
Tags = Set [ "c++"; "java"; "ml" ]
Locations = Map.ofSeq [
({Owner = "test"; Project = "test1"}, PackageSource.Http (Map.ofSeq [
(Version.SemVer { SemVer.zero with Major = 2 }, {
({Owner = "testorg1"; Project = "test1"}, PackageSource.Http (Map.ofSeq [
(Version.SemVer { SemVer.zero with Major = 1 }, {
Url = "https://test.com"
StripPrefix = Some "prefix"
Type = Some ArchiveType.Zip
})
]));
({Owner = "testorg2"; Project = "test2"}, PackageSource.Http (Map.ofSeq [
(Version.SemVer { SemVer.zero with Major = 2 }, {
Url = "https://testing.com"
StripPrefix = Some "other_prefix"
Type = Some ArchiveType.Zip
})
]))
]
Dependencies = Set [{
Expand All @@ -131,6 +136,33 @@ let ``Manifest.toToml roundtrip 2`` () =
Constraint = Any <|Set[Constraint.Exactly (Version.SemVer SemVer.zero)]
Package = PackageIdentifier.GitHub { Owner = "abc"; Project = "def" }
}]
Overrides = Map.empty
}

let actual = expected |> Manifest.toToml |> Manifest.parse

// 3 new-lines indicates poor formatting
Assert.True (
expected
|> Manifest.toToml
|> String.contains "\n\n\n"
|> not
)

Assert.Equal (Result.Ok expected, actual)

[<Fact>]
let ``Manifest.toToml roundtrip 3`` () =
let expected : Manifest = {
Manifest.zero with
Overrides =
Map.empty
|> Map.add
(PackageIdentifier.GitHub { Owner = "abc"; Project = "def" })
(PackageIdentifier.GitHub { Owner = "abc"; Project = "pqr" })
|> Map.add
(PackageIdentifier.GitHub { Owner = "ijk"; Project = "lmo" })
(PackageIdentifier.GitHub { Owner = "gfh"; Project = "xyz" })
}

let actual = expected |> Manifest.toToml |> Manifest.parse
Expand Down
29 changes: 14 additions & 15 deletions buckaroo-tests/Paths.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,25 @@ open System.IO
open Xunit
open Buckaroo

let private sep = new String([| Path.DirectorySeparatorChar |])

let private sep = String [| Path.DirectorySeparatorChar |]

[<Fact>]
let ``Paths.normalize works correctly`` () =
let ``Paths.normalize works correctly`` () =
let cases = [
(".", "");
("a", "a");
("a" + sep + "", "a" + sep + "");
("" + sep + "a" + sep + "", "" + sep + "a" + sep + "");
("a" + sep + " " + sep + "b", "a" + sep + " " + sep + "b");
("" + sep + "a" + sep + "", "" + sep + "a" + sep + "");
("b", "a" + sep + ".." + sep + "b");
("c" + sep + "d", "a" + sep + ".." + sep + "b" + sep + ".." + sep + "c" + sep + "." + sep + "." + sep + "." + sep + "d");
(".." + sep + ".." + sep + ".." + sep + "a" + sep + "b" + sep + "c", ".." + sep + ".." + sep + ".." + sep + "a" + sep + "b" + sep + "c");
(".." + sep + ".." + sep + ".." + sep + "a", ".." + sep + ".." + sep + ".." + sep + "." + sep + "a");
(".", "");
("a", "a");
("a" + sep + "", "a" + sep + "");
("" + sep + "a" + sep + "", "" + sep + "a" + sep + "");
("a" + sep + " " + sep + "b", "a" + sep + " " + sep + "b");
("" + sep + "a" + sep + "", "" + sep + "a" + sep + "");
("b", "a" + sep + ".." + sep + "b");
("c" + sep + "d", "a" + sep + ".." + sep + "b" + sep + ".." + sep + "c" + sep + "." + sep + "." + sep + "." + sep + "d");
(".." + sep + ".." + sep + ".." + sep + "a" + sep + "b" + sep + "c", ".." + sep + ".." + sep + ".." + sep + "a" + sep + "b" + sep + "c");
(".." + sep + ".." + sep + ".." + sep + "a", ".." + sep + ".." + sep + ".." + sep + "." + sep + "a");
(
".." + sep + ".." + sep + ".." + sep + ".." + sep + ".." + sep + ".." + sep + "buckaroo" + sep + "github" + sep + "buckaroo-pm" + sep + "pkg-config-cairo",
".." + sep + ".." + sep + ".." + sep + ".." + sep + ".." + sep + ".." + sep + "buckaroo" + sep + "github" + sep + "buckaroo-pm" + sep + "pkg-config-cairo",
".." + sep + ".." + sep + ".." + sep + ".." + sep + ".." + sep + ".." + sep + "." + sep + "buckaroo" + sep + "github" + sep + "buckaroo-pm" + sep + "pkg-config-cairo"
);
);
]

for (expected, input) in cases do
Expand Down
101 changes: 77 additions & 24 deletions buckaroo-tests/Solver.fs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
module Buckaroo.Tests.Solver

open Xunit
open Buckaroo
open FSharp.Control

open Buckaroo
open Buckaroo.Console
open Buckaroo.Tasks
open Buckaroo.Tests

type CookBook = List<PackageIdentifier * Set<Version> * Manifest>
type LockBookEntries = List<(string*int) * List<string*int*Set<Version>>>
type LockBookEntries = List<(string * int) * List<string * int * Set<Version>>>
type LockBook = Map<PackageLock, Lock>

let package name = PackageIdentifier.Adhoc {
Expand All @@ -18,38 +17,41 @@ let package name = PackageIdentifier.Adhoc {
}

let br b = Version.Git (GitVersion.Branch b)
let rev (x : int) = Version.Git(GitVersion.Revision (x.ToString()))
let ver (x : int) = Version.SemVer {SemVer.zero with Major = x}
let rev (x : int) = Version.Git (GitVersion.Revision (string x))
let ver (x : int) = Version.SemVer { SemVer.zero with Major = x }

let dep (p : string, c: Constraint) : Buckaroo.Dependency = {
Package = package p;
Constraint = c;
let dep (p : string, c: Constraint) : Buckaroo.Dependency =
{
Package = package p
Constraint = c
Targets = None
}
}

let manifest xs = {
Manifest.zero
with Dependencies = xs |> List.map dep |> Set.ofList
}
let manifest xs =
{
Manifest.zero
with Dependencies = xs |> List.map dep |> Set.ofList
}

let lockPackage (p, r, vs) : LockedPackage = {
Versions = Set vs
Location = PackageLock.GitHub {
Package = {Owner = "test"; Project = p};
Revision = r.ToString()
Package = { Owner = "test"; Project = p }
Revision = string r
}
PrivatePackages = Map.empty
}

let packageLock (p, r) : PackageLock = PackageLock.GitHub {
Package = {Owner = "test"; Project = p};
Revision = r.ToString()
Package = { Owner = "test"; Project = p }
Revision = string r
}

let lock deps : Lock = {
ManifestHash = "";
Dependencies = Set[]
Packages = deps
Dependencies = Set []
Packages =
deps
|> Seq.map (fun (name, r, vs) -> (package name, lockPackage (name, r, vs)))
|> Map.ofSeq
}
Expand All @@ -61,7 +63,7 @@ let lockBookOf (entries : LockBookEntries) : LockBook =

type TestingSourceExplorer (cookBook : CookBook, lockBook : LockBook) =
interface ISourceExplorer with
member this.FetchVersions (_ : PackageSources) (package: PackageIdentifier) : AsyncSeq<Version> = asyncSeq {
member this.FetchVersions (_ : PackageSources) (package: PackageIdentifier) : AsyncSeq<Version> = asyncSeq {
yield!
cookBook
|> Seq.choose (fun (p, v, _) ->
Expand Down Expand Up @@ -123,26 +125,33 @@ let solve (partial : Solution) (cookBook : CookBook) (lockBookEntries : LockBook
let lockBook = lockBookOf lockBookEntries
let console = ConsoleManager (LoggingLevel.Silent)
let context : TaskContext = {
BuildSystem = BuildSystem.Bazel
Console = console
DownloadManager = DownloadManager(console, "/tmp")
GitManager = new GitManager(CacheFirst, console, new GitCli(console), "/tmp")
SourceExplorer = TestingSourceExplorer(cookBook, lockBook)
}

Buckaroo.Solver.solve
context partial
root style
context
partial
root
style
(lockBook |> Map.tryFind (packageLock ("root", 0)))

let getLockedRev (p : string) (r : _) =
match r with
| Ok solution ->
if not (Map.containsKey (package p) solution.Resolutions)
then
failwith (p + " is not in the solution")

let (resolved, _) = solution.Resolutions.[package p]

match resolved.Lock with
| PackageLock.GitHub g -> g.Revision
| _ -> ""
| _ -> ""
()

let isOk (r : _) =
match r with
Expand Down Expand Up @@ -605,9 +614,53 @@ let ``Solver can handle the simple triangle case`` () =
let solution =
solve
completeSolution
cookBook lockBookSpec root
cookBook
lockBookSpec
root
ResolutionStyle.Upgrading
|> Async.RunSynchronously

Assert.Equal ("1", getLockedRev "a" solution)
Assert.Equal ("1", getLockedRev "b" solution)


[<Fact>]
let ``Solver can follow overrides`` () =
let cookBook = [
(package "x",
Set [ver 1],
manifest [("b", Exactly (ver 1))])
(package "y",
Set [ver 1],
manifest [])
]

let lockBookSpec = [
(("root", 0), [
("x", 1, Set [ ver 1 ])
("y", 1, Set [ ver 1 ])
])
]

let root = {
manifest [
("a", Exactly (ver 1) )
] with
Overrides =
Map.empty
|> Map.add (package "a") (package "x")
|> Map.add (package "b") (package "y")
}

let solution =
solve
Solution.empty
cookBook
lockBookSpec
root
ResolutionStyle.Upgrading
|> Async.RunSynchronously

// We should find a and b in solution, but they point to locations from x and y
Assert.Equal ("1", getLockedRev "a" solution)
Assert.Equal ("1", getLockedRev "b" solution)
Loading

0 comments on commit 49b5425

Please sign in to comment.