Skip to content

Commit

Permalink
Windows - Fix #242: Failure building menhir (#294)
Browse files Browse the repository at this point in the history
* Rewrite prefixes in both forms for windows

* Fix slashes

* Fix type of args to fastreplacestring
  • Loading branch information
bryphe committed Jul 26, 2018
1 parent fa1e352 commit bd6f534
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions esy-build-package/Build.re
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,27 @@ let commitBuildToStore = (config: Config.t, build: build) => {
empty
% config.fastreplacestringCmd
% p(path)
% p(origPrefix)
% p(destPrefix)
% origPrefix
% destPrefix
);
Bos.OS.Cmd.run(cmd);
};
let rewritePrefixesInFile = (~origPrefix, ~destPrefix, path) => {
let origPrefixString = Path.to_string(origPrefix);
let destPrefixString = Path.to_string(destPrefix);
switch (System.Platform.host) {
| Windows =>
/* On Windows, the slashes could be either `/` or windows-style `\` */
/* We'll replace both styles */
let%bind () = rewritePrefixInFile(~origPrefix=origPrefixString, ~destPrefix=destPrefixString, path);
let normalizedOrigPrefix = Path.normalizePathSlashes(origPrefixString);
let normalizedDestPrefix = Path.normalizePathSlashes(destPrefixString);
let%bind () = rewritePrefixInFile(~origPrefix=normalizedOrigPrefix, ~destPrefix=normalizedDestPrefix, path);
ok;
| _ =>
rewritePrefixInFile(~origPrefix=origPrefixString, ~destPrefix=destPrefixString, path);
}
};
let rewriteTargetInSymlink = (~origPrefix, ~destPrefix, path) => {
let%bind targetPath = readlink(path);
switch (Path.rem_prefix(origPrefix, targetPath)) {
Expand All @@ -376,7 +392,7 @@ let commitBuildToStore = (config: Config.t, build: build) => {
let relocate = (path: Path.t, stats: Unix.stats) =>
switch (stats.st_kind) {
| Unix.S_REG =>
rewritePrefixInFile(
rewritePrefixesInFile(
~origPrefix=build.stagePath,
~destPrefix=build.installPath,
path,
Expand Down

0 comments on commit bd6f534

Please sign in to comment.