Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // +build !windows | |
| 6 | |
| 7 // *nix-specific function implementations for the firstrun subcommand. | |
| 8 | |
| 9 package firstrun | |
| 10 | |
| 11 import ( | |
| 12 "os" | |
| 13 "os/user" | |
| 14 "path/filepath" | |
| 15 | |
| 16 "infra/tools/cr/lib/terminal" | |
| 17 ) | |
| 18 | |
| 19 // firstrunCheckNotInstalled is a sanity check to make sure that the user really | |
| 20 // wants to do firstrun again, if it looks like cr is already installed. | |
| 21 func firstrunCheckNotInstalled() { | |
| 22 // Check to see if a path ending in '/cr/bin' in in $PATH. | |
| 23 pathenv := os.Getenv("PATH") | |
| 24 terminal.Debug("$PATH is %v\n", pathenv) | |
| 25 possibleDirs := make([]string, 1) | |
| 26 for _, elem := range filepath.SplitList(pathenv) { | |
| 27 terminal.Debug("Examining %v\n", elem) | |
| 28 head, bindir := filepath.Split(elem) | |
| 29 crdir := filepath.Base(head) | |
| 30 terminal.Debug("Last elements of path are %v, %v\n", crdir, bind ir) | |
| 31 if bindir == "bin" && crdir == "cr" { | |
| 32 possibleDirs = append(possibleDirs, elem) | |
| 33 } | |
| 34 } | |
| 35 terminal.Debug("Possible dirs are %v\n", possibleDirs) | |
| 36 // Check to see if an executable called 'cr' is in that path. | |
|
seanmccullough1
2016/05/06 00:43:54
If this comment (and many others here) is a TODO,
agable
2016/05/10 00:34:10
Done.
| |
| 37 } | |
| 38 | |
| 39 // firstrunPromptInstallDir prompts the user for a directory path to install cr. | |
| 40 func firstrunPromptInstallDir() { | |
| 41 // Figure out a sane place to suggest. | |
| 42 _, err := user.Current() | |
| 43 if err != nil { | |
|
seanmccullough1
2016/05/06 00:43:54
returning err here would fit naturally.
agable
2016/05/10 00:34:10
Removed the stub, returns an error now.
| |
| 44 } | |
| 45 // Suggest it and ask the user for an alternative. | |
| 46 // Check that the chosen directory makes sense. | |
| 47 } | |
| 48 | |
| 49 // firstrunInitInstallDir sets up the selected directory to house cr. It creates | |
| 50 // the modules/ and bin/ subdirectories, places the cr executable in the | |
| 51 // top level, and symlinks it into bin/. | |
| 52 func firstrunInitInstallDir(dir string) { | |
| 53 // Create the cr/ directory. | |
| 54 // Copy this executable into the cr/ directory. | |
| 55 // Create the bin/ subdirectory. | |
| 56 // Add a symlink to the cr executable in the bin/ subdirectory. | |
| 57 // Create the modules/ subdirectory. | |
| 58 } | |
| 59 | |
| 60 // firstrunUpdatePath finds the rcfile in which $PATH is set, sees if it can | |
| 61 // automatically update it, and prompts the user for permission to do so. | |
| 62 func firstrunUpdatePath() { | |
| 63 // Detect the user's default shell. | |
| 64 // Find their shell's rcfile. | |
| 65 // Find lines modifying $PATH in that file. | |
| 66 // Fine a line mentioning depot_tools. | |
| 67 // Produce a git-style diff adding the install bin/ dir to that line, or | |
| 68 // above that line. | |
| 69 // Prompt the user to see if they want to apply that diff. | |
| 70 // Apply the diff, or print instructions on how to do it manually. | |
| 71 } | |
| 72 | |
| 73 // firstrunPrintUpdatePathInstructions prints instructions for the user to | |
| 74 // update their $PATH manually. This is used if updatePath fails, or if the user | |
| 75 // declines to have their rcfile updated automatically. | |
| 76 func firstrunPrintUpdatePathInstructions() { | |
| 77 | |
| 78 } | |
| OLD | NEW |