@@ -11,6 +11,14 @@ open FSharp.Compiler.SourceCodeServices
1111open Fable
1212open Globbing.Operators
1313
14+ type Options = {
15+ define: string []
16+ noReferences: bool
17+ noRestore: bool
18+ rootDir: string
19+ projFile: string
20+ }
21+
1422let isSystemPackage ( pkgName : string ) =
1523 pkgName.StartsWith( " System." )
1624 || pkgName.StartsWith( " Microsoft." )
@@ -234,12 +242,15 @@ let private isUsefulOption (opt : string) =
234242/// and get F# compiler args from an .fsproj file. As we'll merge this
235243/// later with other projects we'll only take the sources and the references,
236244/// checking if some .dlls correspond to Fable libraries
237- let fullCrack noReferences ( projFile : string ): CrackedFsproj =
245+ let fullCrack ( opts : Options ): CrackedFsproj =
246+ let projFile = opts.projFile
238247 // Use case insensitive keys, as package names in .paket.resolved
239248 // may have a different case, see #1227
240249 let dllRefs = Dictionary( StringComparer.OrdinalIgnoreCase)
241250 // Try restoring project
242- if projFile.EndsWith( " .fsproj" ) then
251+ if opts.noRestore then
252+ Log.always " Skipping restore..."
253+ else
243254 Process.runCmd Log.always
244255 ( IO.Path.GetDirectoryName projFile)
245256 " dotnet" [ " restore" ; IO.Path.GetFileName projFile]
@@ -265,7 +276,7 @@ let fullCrack noReferences (projFile: string): CrackedFsproj =
265276 else
266277 ( Path.normalizeFullPath line):: src, otherOpts)
267278 let projRefs =
268- if noReferences then []
279+ if opts. noReferences then []
269280 else
270281 projRefs |> List.choose ( fun projRef ->
271282 // Remove dllRefs corresponding to project references
@@ -307,7 +318,7 @@ let easyCrack (projFile: string): CrackedFsproj =
307318 PackageReferences = []
308319 OtherCompilerOptions = [] }
309320
310- let getCrackedProjectsFromMainFsproj noReferences ( projFile : string ) =
321+ let getCrackedProjectsFromMainFsproj ( opts : Options ) =
311322 let rec crackProjects ( acc : CrackedFsproj list ) ( projFile : string ) =
312323 let crackedFsproj =
313324 match acc |> List.tryFind ( fun x -> x.ProjectFile = projFile) with
@@ -316,29 +327,29 @@ let getCrackedProjectsFromMainFsproj noReferences (projFile: string) =
316327 // Add always a reference to the front to preserve compilation order
317328 // Duplicated items will be removed later
318329 List.fold crackProjects ( crackedFsproj:: acc) crackedFsproj.ProjectReferences
319- let mainProj = fullCrack noReferences projFile
330+ let mainProj = fullCrack opts
320331 let refProjs =
321332 List.fold crackProjects [] mainProj.ProjectReferences
322333 |> List.distinctBy ( fun x -> x.ProjectFile)
323334 refProjs, mainProj
324335
325- let getCrackedProjects define noReferences ( projFile : string ) =
326- match ( Path.GetExtension projFile) .ToLower() with
336+ let getCrackedProjects ( opts : Options ) =
337+ match ( Path.GetExtension opts. projFile) .ToLower() with
327338 | " .fsx" ->
328- getProjectOptionsFromScript define projFile
339+ getProjectOptionsFromScript opts. define opts. projFile
329340 | " .fsproj" ->
330- getCrackedProjectsFromMainFsproj noReferences projFile
341+ getCrackedProjectsFromMainFsproj opts
331342 | s -> failwithf " Unsupported project type: %s " s
332343
333344// It is common for editors with rich editing or 'intellisense' to also be watching the project
334345// file for changes. In some cases that editor will lock the file which can cause fable to
335346// get a read error. If that happens the lock is usually brief so we can reasonably wait
336347// for it to be released.
337- let retryGetCrackedProjects define noReferences ( projFile : string ) =
348+ let retryGetCrackedProjects opts =
338349 let retryUntil = ( DateTime.Now + TimeSpan.FromSeconds 2. )
339350 let rec retry () =
340351 try
341- getCrackedProjects define noReferences projFile
352+ getCrackedProjects opts
342353 with
343354 | :? IOException as ioex ->
344355 if retryUntil > DateTime.Now then
@@ -357,7 +368,7 @@ let createFableDir rootDir =
357368 let fableDir = IO.Path.Combine( rootDir, Naming.fableHiddenDir)
358369 if isDirectoryEmpty fableDir then
359370 Directory.CreateDirectory( fableDir) |> ignore
360- File.WriteAllText( IO.Path.Combine( fableDir, " .gitignore" ), " *. *" )
371+ File.WriteAllText( IO.Path.Combine( fableDir, " .gitignore" ), " **/ *" )
361372 fableDir
362373
363374let copyDirIfDoesNotExist ( source : string ) ( target : string ) =
@@ -398,13 +409,12 @@ let removeFilesInObjFolder sourceFiles =
398409 let reg = System.Text.RegularExpressions.Regex( @" [\\\/]obj[\\\/]" )
399410 sourceFiles |> Array.filter ( reg.IsMatch >> not )
400411
401- let getFullProjectOpts ( define : string []) ( noReferences : bool ) ( rootDir : string ) ( projFile : string ) =
402- let projFile = Path.GetFullPath( projFile)
403- if not ( File.Exists( projFile)) then
404- failwith ( " File does not exist: " + projFile)
405- let projRefs , mainProj = retryGetCrackedProjects define noReferences projFile
412+ let getFullProjectOpts ( opts : Options ) =
413+ if not ( File.Exists( opts.projFile)) then
414+ failwith ( " File does not exist: " + opts.projFile)
415+ let projRefs , mainProj = retryGetCrackedProjects opts
406416 let fableLibraryPath , pkgRefs =
407- copyFableLibraryAndPackageSources rootDir mainProj.PackageReferences
417+ copyFableLibraryAndPackageSources opts. rootDir mainProj.PackageReferences
408418 let projOpts =
409419 let sourceFiles =
410420 let pkgSources = pkgRefs |> List.collect getSourcesFromFsproj
@@ -433,9 +443,9 @@ let getFullProjectOpts (define: string[]) (noReferences: bool) (rootDir: string)
433443 mainProj.DllReferences
434444 |> List.mapToArray ( fun r -> " -r:" + r)
435445 let otherOpts = mainProj.OtherCompilerOptions |> Array.ofList
436- [ getBasicCompilerArgs define
446+ [ getBasicCompilerArgs opts. define
437447 otherOpts
438448 dllRefs ]
439449 |> Array.concat
440- makeProjectOptions projFile sourceFiles otherOptions
450+ makeProjectOptions opts. projFile sourceFiles otherOptions
441451 projOpts, fableLibraryPath
0 commit comments