Skip to content

Commit ec51dec

Browse files
committed
Rename FSStrings
1 parent f9a3cb4 commit ec51dec

File tree

6 files changed

+31
-12
lines changed

6 files changed

+31
-12
lines changed

fcs/fcs-fable/System.IO.fs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
namespace System.IO
66

7-
module Directory =
8-
let GetCurrentDirectory () = "." //TODO: proper xplat implementation
9-
107
module Path =
118
let Combine (path1: string, path2: string) = //TODO: proper xplat implementation
129
let path1 =
@@ -29,14 +26,11 @@ module Path =
2926
else path.Substring(i)
3027

3128
let GetInvalidPathChars () = //TODO: proper xplat implementation
32-
Seq.toArray "<>:\"|?*\b\t"
29+
Seq.toArray "<>\"|?*\b\t"
3330

3431
let GetInvalidFileNameChars () = //TODO: proper xplat implementation
3532
Seq.toArray "<>:\"|\\/?*\b\t"
3633

37-
let GetFullPath (path: string) = //TODO: proper xplat implementation
38-
path
39-
4034
let GetFileName (path: string) =
4135
let normPath = path.Replace("\\", "/").TrimEnd('/')
4236
let i = normPath.LastIndexOf("/")

fcs/fcs-fable/test/Platform.fs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ let measureTime (f: 'a -> 'b) x =
1414
sw.Stop()
1515
sw.ElapsedMilliseconds, res
1616

17+
let normalizeFullPath (path: string) =
18+
System.IO.Path.GetFullPath(path).Replace('\\', '/')
19+
20+
let getRelativePath (pathFrom: string) (pathTo: string) =
21+
System.IO.Path.GetRelativePath(pathFrom, pathTo).Replace('\\', '/')
22+
1723
#else // !DOTNET_FILE_SYSTEM
1824

1925
open Fable.Core.JsInterop
@@ -27,8 +33,13 @@ type private IProcess =
2733
abstract hrtime: unit -> float []
2834
abstract hrtime: float[] -> float[]
2935

36+
type private IPath =
37+
abstract resolve: string -> string
38+
abstract relative: string * string -> string
39+
3040
let private File: IFileSystem = importAll "fs"
3141
let private Process: IProcess = importAll "process"
42+
let private Path: IPath = importAll "path"
3243

3344
let readAllBytes metadataPath (fileName:string) = File.readFileSync (metadataPath + fileName)
3445
let readAllText (filePath:string) = (File.readFileSync (filePath, "utf8")).TrimStart('\uFEFF')
@@ -40,6 +51,12 @@ let measureTime (f: 'a -> 'b) x =
4051
let elapsed = Process.hrtime(startTime)
4152
int64 (elapsed.[0] * 1e3 + elapsed.[1] / 1e6), res
4253

54+
let normalizeFullPath (path: string) =
55+
Path.resolve(path).Replace('\\', '/')
56+
57+
let getRelativePath (pathFrom: string) (pathTo: string) =
58+
Path.relative(pathFrom, pathTo).Replace('\\', '/')
59+
4360
#endif
4461

4562
module Path =

fcs/fcs-fable/test/bench.fs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,9 @@ let rec parseProject projectPath =
5252

5353
let projectFileDir = Path.GetDirectoryName projectPath
5454
let isAbsolutePath (path: string) = path.StartsWith("/") || path.IndexOf(":") = 1
55-
let trimPath (path: string) = path.Replace("../", "").Replace("./", "").Replace(":", "")
5655
let makePath path = if isAbsolutePath path then path else Path.Combine(projectFileDir, path)
57-
let makeName path = Path.Combine(projectFileDir, path) |> trimPath
5856

59-
let fileNames = sourceFiles |> Array.map (fun path -> path |> makeName)
57+
let fileNames = sourceFiles |> Array.map (fun path -> path |> makePath |> normalizeFullPath)
6058
let sources = sourceFiles |> Array.map (fun path -> path |> makePath |> readAllText)
6159

6260
let parsedProjects = projectRefs |> Array.map makePath |> Array.map parseProject
@@ -67,7 +65,11 @@ let rec parseProject projectPath =
6765
(projectFileName, fileNames, sources, defines |> Array.distinct)
6866

6967
let dedupFileNames fileNames =
70-
let nameSet = System.Collections.Generic.HashSet<string>()
68+
let comparerIgnoreCase =
69+
{ new System.Collections.Generic.IEqualityComparer<string> with
70+
member __.Equals(x, y) = x.ToLowerInvariant() = y.ToLowerInvariant()
71+
member __.GetHashCode(x) = hash (x.ToLowerInvariant()) }
72+
let nameSet = System.Collections.Generic.HashSet<string>(comparerIgnoreCase)
7173
let padName (name: string) =
7274
let pos = name.LastIndexOf(".")
7375
let nm = if pos < 0 then name else name.Substring(0, pos)

src/absil/illib.fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1326,9 +1326,11 @@ module Shim =
13261326
member __.FileStreamCreateShim (fileName: string) = new FileStream(fileName,FileMode.Create,FileAccess.Write,FileShare.Read ,0x1000,false) :> Stream
13271327

13281328
member __.FileStreamWriteExistingShim (fileName: string) = new FileStream(fileName,FileMode.Open,FileAccess.Write,FileShare.Read ,0x1000,false) :> Stream
1329-
#endif
13301329

13311330
member __.GetFullPathShim (fileName: string) = System.IO.Path.GetFullPath fileName
1331+
#else //FABLE_COMPILER
1332+
member __.GetFullPathShim (fileName: string) = fileName
1333+
#endif
13321334

13331335
member __.IsPathRootedShim (path: string) = Path.IsPathRooted path
13341336

src/fsharp/lexhelp.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,11 @@ module Keywords =
335335
if String.IsNullOrWhiteSpace(filename) then
336336
String.Empty
337337
else if filename = stdinMockFilename then
338+
#if !FABLE_COMPILER
338339
System.IO.Directory.GetCurrentDirectory()
340+
#else //FABLE_COMPILER
341+
"."
342+
#endif
339343
else
340344
filename
341345
|> FileSystem.GetFullPathShim (* asserts that path is already absolute *)

0 commit comments

Comments
 (0)