Skip to content

Commit

Permalink
Support Dune Lang 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ManasJayanth committed Dec 26, 2022
1 parent 42dd313 commit 6563f31
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
12 changes: 12 additions & 0 deletions bin/Pesy.re
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,18 @@ let pesy_build = () =>
);
fprintf(stderr, "%s\n", message);
exit(-1);
| InvalidDuneVersion(version) =>
let message =
Pastel.(
<Pastel>
<Pastel color=Red> "Error: " </Pastel>
<Pastel>
"Invalid Dune version" <Pastel bold=true> {version} </Pastel>
</Pastel>
</Pastel>
);
fprintf(stderr, "%s\n", message);
exit(-1);
};

let buildTarget = build(manifestFile);
Expand Down
3 changes: 2 additions & 1 deletion errors/Errors.re
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ exception BuildValidationFailures(list(validationError));
exception ImportsParserFailure(unit);
exception LocalLibraryPathNotFound(string);
exception ForeignStubsIncorrectlyUsed;
exception CNamesIncorrectlyUsed;
exception CNamesIncorrectlyUsed;
exception InvalidDuneVersion(string);
17 changes: 5 additions & 12 deletions lib/Lib.re
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,12 @@ let duneEject = (projectPath, manifestFile, subpackageNameOrPath) => {
let validateManifestFile = (projectPath, manifestFile) => {
let conf = PesyConf.get(manifestFile);
let pkgs = PesyConf.pkgs(conf);

let duneProjectPath = Path.(projectPath / "dune-project");
let duneVersion =
DuneFile.ofFile(duneProjectPath) |> DuneProject.findLangVersion;

let rootName = PesyConf.rootName(conf);
let _ =
try(
pkgs
|> List.map(PesyConf.toPesyConf(projectPath, rootName, ~duneVersion))
) {
| x => raise(x)
};

();
};
ignore(
pkgs
|> List.map(PesyConf.toPesyConf(projectPath, rootName, ~duneVersion)),
);
};
16 changes: 9 additions & 7 deletions lib/PesyConf.re
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ type package = {
pkgType,
};

exception InvalidDuneVersion;
module Version = {
type t =
| V1(int)
| V2(int);
| V2(int)
| V3(int);
let ofString = version => {
let vs = String.split_on_char('.', version) |> List.map(int_of_string);
switch (vs) {
| [1, minorVersion] => V1(minorVersion)
| [2, minorVersion] => V2(minorVersion)
| _ => raise(InvalidDuneVersion)
| [3, minorVersion] => V3(minorVersion)
| _ => raise(InvalidDuneVersion(version))
};
};
};
Expand Down Expand Up @@ -761,10 +762,11 @@ let toPesyConf = (projectPath, rootName, pkg, ~duneVersion) => {
| (V1(_), Some(cn), None)
| (V1(_), Some(cn), Some(_)) => Some(Stubs.ofCNames(cStubs(cn)))
| (V1(_), None, Some(_)) => raise(ForeignStubsIncorrectlyUsed)
| (V2(_), None, None) => None
| (V2(_), Some(_), None) => raise(CNamesIncorrectlyUsed)
| (V2(_), None, Some(fs))
| (V2(_), Some(_), Some(fs)) =>
/* foreign stubs is supported in version > 1.0 */
| (_, None, None) => None
| (_, Some(_), None) => raise(CNamesIncorrectlyUsed)
| (_, None, Some(fs))
| (_, Some(_), Some(fs)) =>
Some(Stubs.ofForeignStubs(foreignStubs(fs)))
};

Expand Down

0 comments on commit 6563f31

Please sign in to comment.