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

Features (WIP). #345

Closed
wants to merge 9 commits into from
Closed
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
2 changes: 1 addition & 1 deletion buckaroo-tests/Command.fs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ let ``Command.parse works correctly`` () =
Result.Ok
(
Command.AddDependencies
[ { Package = ijkXyz; Constraint = Constraint.wildcard; Targets = None } ],
[ { Package = ijkXyz; Constraint = Constraint.wildcard; Targets = None; Features = None; Conditions = None } ],
defaultLoggingLevel,
RemoteFirst
),
Expand Down
2 changes: 1 addition & 1 deletion buckaroo-tests/Dependency.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ open Buckaroo
let ``Dependency.parse works correctly`` () =
let p = PackageIdentifier.GitHub { Owner = "abc"; Project = "def" }
let cases = [
("github.com/abc/def@*", { Package = p; Constraint = Constraint.wildcard; Targets = None } |> Result.Ok)
("github.com/abc/def@*", { Package = p; Constraint = Constraint.wildcard; Targets = None; Features = None; Conditions = None } |> Result.Ok)
// TODO:
// ("github.com/abc/def@*//:foo", { Package = p; Constraint = Constraint.wildcard; Targets = Some [ { Folders = []; Name = "foo" } ] } |> Result.Ok)
// ("", Result.Error "");
Expand Down
58 changes: 53 additions & 5 deletions buckaroo-tests/Manifest.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ open System
open Xunit
open FSharpx

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

Expand All @@ -14,13 +12,17 @@ let ``Manifest.parse works correctly`` () =
let a = {
Package = PackageIdentifier.GitHub { Owner = "abc"; Project = "def" };
Constraint = Constraint.wildcard;
Targets = None
Targets = None;
Features = None;
Conditions = None;
}

let b = {
Package = PackageIdentifier.GitHub { Owner = "ijk"; Project = "xyz" };
Constraint = Constraint.wildcard;
Targets = Some [ { Folders = []; Name = "foo" } ]
Targets = Some [ { Folders = []; Name = "foo" } ];
Features = None;
Conditions = None;
}

let lmnqrs = { Owner = "lmn"; Project = "qrs" }
Expand All @@ -29,6 +31,8 @@ let ``Manifest.parse works correctly`` () =
Package = PackageIdentifier.Adhoc lmnqrs;
Constraint = Constraint.wildcard;
Targets = None;
Features = None;
Conditions = None;
}

let locationC =
Expand Down Expand Up @@ -89,10 +93,30 @@ let ``Manifest.toToml roundtrip 1`` () =
Targets = Some ([{Folders=["foo"; "bar"]; Name = "xxx"}])
Constraint = All <| Set[Constraint.Exactly (Version.SemVer SemVer.zero)]
Package = PackageIdentifier.GitHub { Owner = "abc"; Project = "def" }
Features = ([
("profile", "core" |> FeatureUnitValue.String |> FeatureValue.Value);
("api", FeatureValue.Dictionary ([
("gl", "3.2" |> FeatureUnitValue.String);
("gles", "" |> FeatureUnitValue.String);
] |> Map.ofSeq) );
("extensions", FeatureValue.Array [
"GL_EXT_framebuffer_multisample" |> FeatureUnitValue.String;
"GL_EXT_texture_filter_anisotropic" |> FeatureUnitValue.String;
] );
] |> Map.ofSeq |> Some);
Conditions = [{
Source = "gl > 3";
Expression =
Expression.BinaryExpression (
Expression.Variable "gl",
BinaryOperator.More,
Expression.Value (3 |> int64 |> FeatureUnitValue.Integer |> FeatureValue.Value)
);
}] |> Some;
}]
}

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

// 3 new-lines indicates poor formatting
Assert.True (
Expand Down Expand Up @@ -125,11 +149,35 @@ let ``Manifest.toToml roundtrip 2`` () =
Targets = Some ([{Folders=["foo"; "bar"]; Name = "xxx"}])
Constraint = All <| Set[Constraint.Exactly (Version.SemVer SemVer.zero)]
Package = PackageIdentifier.GitHub { Owner = "abc"; Project = "def" }
Features = ([
("profile", "core" |> FeatureUnitValue.String |> FeatureValue.Value);
("api", FeatureValue.Dictionary ([
("gl", "3.2" |> FeatureUnitValue.String);
("gles", "" |> FeatureUnitValue.String);
] |> Map.ofSeq) );
("extensions", FeatureValue.Array [
"GL_EXT_framebuffer_multisample" |> FeatureUnitValue.String;
"GL_EXT_texture_filter_anisotropic" |> FeatureUnitValue.String;
] );
] |> Map.ofSeq |> Some);
Conditions = None;
}]
PrivateDependencies = Set [{
Targets = Some ([{Folders=["foo"; "bar"]; Name = "yyy"}])
Constraint = Any <|Set[Constraint.Exactly (Version.SemVer SemVer.zero)]
Package = PackageIdentifier.GitHub { Owner = "abc"; Project = "def" }
Features = ([
("profile", "core" |> FeatureUnitValue.String |> FeatureValue.Value);
("api", FeatureValue.Dictionary ([
("gl", "3.2" |> FeatureUnitValue.String);
("gles", "" |> FeatureUnitValue.String);
] |> Map.ofSeq) );
("extensions", FeatureValue.Array [
"GL_EXT_framebuffer_multisample" |> FeatureUnitValue.String;
"GL_EXT_texture_filter_anisotropic" |> FeatureUnitValue.String;
] );
] |> Map.ofSeq |> Some);
Conditions = None;
}]
}

Expand Down
4 changes: 3 additions & 1 deletion buckaroo-tests/Solver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ let ver (x : int) = Version.SemVer {SemVer.zero with Major = x}
let dep (p : string, c: Constraint) : Buckaroo.Dependency = {
Package = package p;
Constraint = c;
Targets = None
Targets = None;
Features = None;
Conditions = None;
}

let manifest xs = {
Expand Down
4 changes: 2 additions & 2 deletions buckaroo/BuckConfig.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ type INIData = Map<string, Map<INIKey,INIValue>>
let rec renderValue (value : INIValue) : string =
match value with
| INIString s -> s
| INITuple xs -> xs |> Seq.map renderValue |> String.concat ", "
| INIList xs -> xs |> Seq.map renderValue |> String.concat ", "
| INITuple xs -> xs |> Seq.map renderValue |> String.concat " "
| INIList xs -> xs |> Seq.map renderValue |> String.concat " "
| INIEmpty -> ""

let renderSection (section : Map<INIKey, INIValue>) : string =
Expand Down
4 changes: 4 additions & 0 deletions buckaroo/Command.fs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ module Command =
Package = p;
Constraint = c;
Targets = None;
Features = None;
Conditions = None;
}
} <|>
parse {
Expand All @@ -116,6 +118,8 @@ module Command =
Package = p;
Constraint = Constraint.wildcard;
Targets = None;
Features = None;
Conditions = None;
}
}
}
Expand Down
112 changes: 112 additions & 0 deletions buckaroo/Condition.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#nowarn "40"
namespace Buckaroo

type BinaryOperator =
| And
| Or
| Equal
| NotEqual
| Less
| LessEqual
| More
| MoreEqual
| Contains

type Expression =
| Value of FeatureValue
| Variable of string
| NotExpression of Expression
| BinaryExpression of Expression * BinaryOperator * Expression

type Condition = {
Source : string;
Expression : Expression;
}

module ConditionParse =
open FParsec

let private ws = CharParsers.spaces
let private str = CharParsers.skipString

let private featureNameParser : Parser<string, unit> =
CharParsers.regex @"\w[\w\d]*"

let private valueParser = FeatureValueParse.featureValueParser
let rec private variableParser = featureNameParser |>> Variable

and private andParser = (str "and") >>. (Primitives.preturn And)
and private orParser = (str "or") >>. (Primitives.preturn Or)
and private equalParser = (str "=") >>. (Primitives.preturn Equal)
and private notEqualParser = (str "<>") >>. (Primitives.preturn NotEqual)
and private lessParser = (str "<") >>. (Primitives.preturn Less)
and private lessEqualParser = (str "<=") >>. (Primitives.preturn LessEqual)
and private moreParser = (str ">") >>. (Primitives.preturn More)
and private moreEqualParser = (str ">=") >>. (Primitives.preturn MoreEqual)
and private containsParser = (str "contains") >>. (Primitives.preturn Contains)

and private binaryOperatorParser prev operators =
Primitives.pipe2
(ws >>. prev .>> ws)
(Primitives.opt (Primitives.tuple2
operators
((parse.Delay (fun() -> binaryOperatorParser prev operators)) <|> prev)
))
(fun left rest ->
match rest with
| None -> left
| Some (operator, right) -> BinaryExpression (left, operator, right)
)

and private compareExpressionParser =
binaryOperatorParser
unitParser
(
equalParser
<|> notEqualParser
<|> lessParser
<|> lessEqualParser
<|> moreParser
<|> moreEqualParser
<|> containsParser
)

and private notOperatorExpressionParser =
(ws >>. (str "not") >>. ws >>. compareExpressionParser |>> NotExpression)
<|> compareExpressionParser

and private logicalExpressionParser =
binaryOperatorParser
notOperatorExpressionParser
(
andParser
<|> orParser
)

and private binaryOperatorExpressionParser = logicalExpressionParser

and private unitParser =
ws >>. (
FeatureValueParse.featureValueParser |>> Value
<|> variableParser
<|> (Primitives.between (str "(") (str ")") expressionParser)
)

and private expressionParser = parse.Delay (fun () ->
Primitives.choice [
binaryOperatorExpressionParser;
unitParser;
])

let private conditionParser : Parser<Expression, unit> =
expressionParser
.>> ws
.>> CharParsers.eof

let parse (input : string) : Result<Condition, string> =
match run conditionParser input with
| Success(result, _, _) -> Result.Ok <| {
Source = input;
Expression = result;
}
| Failure(errorMsg, _, _) -> Result.Error errorMsg
6 changes: 4 additions & 2 deletions buckaroo/Dependency.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ namespace Buckaroo
type Dependency = {
Package : PackageIdentifier;
Constraint : Constraint;
Targets : Target list option
Targets : Target list option;
Features : Map<string, FeatureValue> option;
Conditions : Condition list option;
}

module Dependency =
Expand Down Expand Up @@ -55,7 +57,7 @@ module Dependency =
do! CharParsers.skipString "@"
let! c = Constraint.parser
return
{ Package = p; Constraint = c; Targets = None }
{ Package = p; Constraint = c; Targets = None; Features = None; Conditions = None }
}

let parse (x : string) : Result<Dependency, string> =
Expand Down
15 changes: 15 additions & 0 deletions buckaroo/Escape.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Buckaroo


module Escape =
open System.Text.RegularExpressions

let escapeRegex = Regex(@"([\'""])")
let escapeReplacement = "\\$1"

let escape (quote : string) (input : string) =
quote + escapeRegex.Replace(input, escapeReplacement) + quote

let escapeWithoutQuotes = escape ""
let escapeWithSingleQuotes = escape "'"
let escapeWithDoubleQuotes = escape "\""
Loading