Skip to content

Commit

Permalink
Don't download the bootstrapper if already launched from the bootstra…
Browse files Browse the repository at this point in the history
…pper.
  • Loading branch information
vbfox committed Oct 16, 2016
1 parent 223ad2e commit 9f83162
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/Paket.Core/NugetConvert.fs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ let convertR rootDirectory force credsMigrationMode = trial {
return! createResult(rootDirectory, nugetEnv, credsMigrationMode)
}

let replaceNuGetWithPaket initAutoRestore installAfter result =
let replaceNuGetWithPaket initAutoRestore installAfter fromBootstrapper result =
let remove (fi : FileInfo) =
tracefn "Removing %s" fi.FullName
fi.Delete()
Expand Down Expand Up @@ -399,7 +399,7 @@ let replaceNuGetWithPaket initAutoRestore installAfter result =

if initAutoRestore && (autoVSPackageRestore || result.NuGetEnv.NuGetTargets.IsSome) then
try
VSIntegration.TurnOnAutoRestore result.PaketEnv |> returnOrFail
VSIntegration.TurnOnAutoRestore fromBootstrapper result.PaketEnv |> returnOrFail
with
| exn ->
traceWarnfn "Could not enable auto restore%sMessage: %s" Environment.NewLine exn.Message
Expand Down
18 changes: 14 additions & 4 deletions src/Paket.Core/PublicAPI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ type Dependencies(dependenciesFileName: string) =
)

/// Converts the solution from NuGet to Paket.
static member ConvertFromNuget(force: bool,installAfter: bool, initAutoRestore: bool,credsMigrationMode: string option, ?directory) : unit =
static member ConvertFromNuget(force: bool,installAfter: bool, initAutoRestore: bool,credsMigrationMode: string option, ?directory: DirectoryInfo) : unit =
match directory with
|Some d -> Dependencies.ConvertFromNuget(force, installAfter, initAutoRestore, credsMigrationMode, false, d)
|None -> Dependencies.ConvertFromNuget(force, installAfter, initAutoRestore, credsMigrationMode, false)

/// Converts the solution from NuGet to Paket.
static member ConvertFromNuget(force: bool,installAfter: bool, initAutoRestore: bool,credsMigrationMode: string option, fromBootstrapper, ?directory: DirectoryInfo) : unit =
let dir = defaultArg directory (DirectoryInfo(Directory.GetCurrentDirectory()))
let rootDirectory = dir

Expand All @@ -81,7 +87,7 @@ type Dependencies(dependenciesFileName: string) =
fun () ->
NuGetConvert.convertR rootDirectory force credsMigrationMode
|> returnOrFail
|> NuGetConvert.replaceNuGetWithPaket initAutoRestore installAfter
|> NuGetConvert.replaceNuGetWithPaket initAutoRestore installAfter fromBootstrapper
)

/// Converts the current package dependency graph to the simplest dependency graph.
Expand Down Expand Up @@ -289,15 +295,19 @@ type Dependencies(dependenciesFileName: string) =

/// Downloads the latest paket.bootstrapper into the .paket folder.
member this.DownloadLatestBootstrapper() : unit =
this.DownloadLatestBootstrapper(false)

/// Downloads the latest paket.bootstrapper into the .paket folder.
member this.DownloadLatestBootstrapper(fromBootstrapper) : unit =
Utils.RunInLockedAccessMode(
this.RootPath,
fun () -> Releases.downloadLatestBootstrapperAndTargets |> this.Process)
fun () -> Releases.downloadLatestBootstrapperAndTargets fromBootstrapper |> this.Process)

/// Pulls new paket.targets and bootstrapper and puts them into .paket folder.
member this.TurnOnAutoRestore(): unit =
Utils.RunInLockedAccessMode(
this.RootPath,
fun () -> VSIntegration.TurnOnAutoRestore |> this.Process)
fun () -> VSIntegration.TurnOnAutoRestore false |> this.Process)

/// Removes paket.targets file and Import section from project files.
member this.TurnOffAutoRestore(): unit =
Expand Down
11 changes: 3 additions & 8 deletions src/Paket.Core/Releases.fs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,9 @@ let private downloadLatestVersionOf files destDir =
()
}

/// Downloads the latest version of the paket.bootstrapper to the .paket dir
let downloadLatestBootstrapper environment =
let exeDir = Path.Combine(environment.RootDirectory.FullName, Constants.PaketFolderName)

downloadLatestVersionOf [Constants.BootstrapperFileName] exeDir

/// Downloads the latest version of the paket.bootstrapper and paket.targets to the .paket dir
let downloadLatestBootstrapperAndTargets environment =
let downloadLatestBootstrapperAndTargets fromBootstrapper environment =
let exeDir = Path.Combine(environment.RootDirectory.FullName, Constants.PaketFolderName)

downloadLatestVersionOf [Constants.TargetsFileName; Constants.BootstrapperFileName] exeDir
let bootstrapperDownload = if fromBootstrapper then [] else [Constants.BootstrapperFileName]
downloadLatestVersionOf ([Constants.TargetsFileName] @ bootstrapperDownload) exeDir
4 changes: 2 additions & 2 deletions src/Paket.Core/VSIntegration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ let TurnOffAutoRestore environment =
}

/// Activates the Visual Studio NuGet autorestore feature in all projects
let TurnOnAutoRestore environment =
let TurnOnAutoRestore fromBootstrapper environment =
let exeDir = Path.Combine(environment.RootDirectory.FullName, Constants.PaketFolderName)

trial {
do! TurnOffAutoRestore environment
do! downloadLatestBootstrapperAndTargets environment
do! downloadLatestBootstrapperAndTargets fromBootstrapper environment
let paketTargetsPath = Path.Combine(exeDir, Constants.TargetsFileName)

environment.Projects
Expand Down
2 changes: 2 additions & 0 deletions src/Paket/Commands.fs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ type Command =
| [<Inherit>] Log_File of path:string
| [<AltCommandLine("-s"); Inherit>] Silent
| [<Inherit>] Version
| [<Inherit;Hidden>] From_Bootstrapper
// subcommands
| [<CustomCommandLine("add")>] Add of ParseResults<AddArgs>
| [<CustomCommandLine("clear-cache")>] ClearCache of ParseResults<ClearCacheArgs>
Expand Down Expand Up @@ -366,6 +367,7 @@ with
| Silent -> "Suppress console output for the paket process."
| Verbose -> "Enable verbose console output for the paket process."
| Version -> "Display the version."
| From_Bootstrapper -> "Call comming from the '--run' feature of the bootstrapper."

let commandParser = ArgumentParser.Create<Command>(programName = "paket", errorHandler = new ProcessExiter())

Expand Down
14 changes: 8 additions & 6 deletions src/Paket/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,22 @@ let autoRestore (results : ParseResults<_>) =
| On -> Dependencies.Locate().TurnOnAutoRestore()
| Off -> Dependencies.Locate().TurnOffAutoRestore()

let convert (results : ParseResults<_>) =
let convert (fromBootstrapper:bool) (results : ParseResults<_>) =
let force = results.Contains <@ ConvertFromNugetArgs.Force @>
let noInstall = results.Contains <@ ConvertFromNugetArgs.No_Install @>
let noAutoRestore = results.Contains <@ ConvertFromNugetArgs.No_Auto_Restore @>
let credsMigrationMode = results.TryGetResult <@ ConvertFromNugetArgs.Creds_Migration @>
Dependencies.ConvertFromNuget(force, noInstall |> not, noAutoRestore |> not, credsMigrationMode)
Dependencies.ConvertFromNuget(force, noInstall |> not, noAutoRestore |> not, credsMigrationMode, fromBootstrapper=fromBootstrapper)

let findRefs (results : ParseResults<_>) =
let packages = results.GetResult <@ FindRefsArgs.Packages @>
let group = defaultArg (results.TryGetResult <@ FindRefsArgs.Group @>) (Constants.MainDependencyGroup.ToString())
packages |> List.map (fun p -> group,p)
|> Dependencies.Locate().ShowReferencesFor

let init (results : ParseResults<InitArgs>) =
let init (fromBootstrapper:bool) (results : ParseResults<InitArgs>) =
Dependencies.Init()
Dependencies.Locate().DownloadLatestBootstrapper()
Dependencies.Locate().DownloadLatestBootstrapper(fromBootstrapper)

let clearCache (results : ParseResults<ClearCacheArgs>) =
Dependencies.ClearCache()
Expand Down Expand Up @@ -374,6 +374,8 @@ let main() =
if results.Contains <@ Verbose @> then
Logging.verbose <- true

let fromBootstrapper = results.Contains <@ From_Bootstrapper @>

let version = results.Contains <@ Version @>
if not version then

Expand All @@ -386,9 +388,9 @@ let main() =
| Add r -> processCommand silent add r
| ClearCache r -> processCommand silent clearCache r
| Config r -> processWithValidation silent validateConfig config r
| ConvertFromNuget r -> processCommand silent convert r
| ConvertFromNuget r -> processCommand silent (convert fromBootstrapper) r
| FindRefs r -> processCommand silent findRefs r
| Init r -> processCommand silent init r
| Init r -> processCommand silent (init fromBootstrapper) r
| AutoRestore r -> processWithValidation silent validateAutoRestore autoRestore r
| Install r -> processCommand silent install r
| Outdated r -> processCommand silent outdated r
Expand Down

0 comments on commit 9f83162

Please sign in to comment.