github.com/btwiuse/jiri@v0.0.0-20191125065820-53353bcfef54/cmd/jiri/resolve.go (about) 1 // Copyright 2018 The Fuchsia Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "strings" 9 10 "github.com/btwiuse/jiri" 11 "github.com/btwiuse/jiri/cmdline" 12 "github.com/btwiuse/jiri/project" 13 ) 14 15 type resolveFlags struct { 16 lockFilePath string 17 localManifestFlag bool 18 enablePackageLock bool 19 enableProjectLock bool 20 enablePackageVersion bool 21 allowFloatingRefs bool 22 hostnameAllowList string 23 } 24 25 func (r *resolveFlags) AllowFloatingRefs() bool { 26 return r.allowFloatingRefs 27 } 28 29 func (r *resolveFlags) LockFilePath() string { 30 return r.lockFilePath 31 } 32 33 func (r *resolveFlags) LocalManifest() bool { 34 return r.localManifestFlag 35 } 36 37 func (r *resolveFlags) EnablePackageLock() bool { 38 return r.enablePackageLock 39 } 40 41 func (r *resolveFlags) EnableProjectLock() bool { 42 return r.enableProjectLock 43 } 44 45 func (r *resolveFlags) HostnameAllowList() []string { 46 ret := make([]string, 0) 47 hosts := strings.Split(r.hostnameAllowList, ",") 48 for _, item := range hosts { 49 item = strings.TrimSpace(item) 50 if item == "" { 51 continue 52 } 53 ret = append(ret, item) 54 } 55 return ret 56 } 57 58 var resolveFlag resolveFlags 59 60 var cmdResolve = &cmdline.Command{ 61 Runner: jiri.RunnerFunc(runResolve), 62 Name: "resolve", 63 Short: "Generate jiri lockfile", 64 Long: ` 65 Generate jiri lockfile in json format for <manifest ...>. If no manifest 66 provided, jiri will use .jiri_manifest by default. 67 `, 68 ArgsName: "<manifest ...>", 69 ArgsLong: "<manifest ...> is a list of manifest files for lockfile generation", 70 } 71 72 func init() { 73 flags := &cmdResolve.Flags 74 flags.StringVar(&resolveFlag.lockFilePath, "output", "jiri.lock", "Path to the generated lockfile") 75 flags.BoolVar(&resolveFlag.localManifestFlag, "local-manifest", false, "Use local manifest") 76 flags.BoolVar(&resolveFlag.enablePackageLock, "enable-package-lock", true, "Enable resolving packages in lockfile") 77 flags.BoolVar(&resolveFlag.enableProjectLock, "enable-project-lock", false, "Enable resolving projects in lockfile") 78 flags.BoolVar(&resolveFlag.allowFloatingRefs, "allow-floating-refs", false, "Allow packages to be pinned to floating refs such as \"latest\"") 79 flags.StringVar(&resolveFlag.hostnameAllowList, "allow-hosts", "", "List of hostnames that can be used in the url of a repository, seperated by comma. It will not be enforced if it is left empty.") 80 } 81 82 func runResolve(jirix *jiri.X, args []string) error { 83 manifestFiles := make([]string, 0) 84 if len(args) == 0 { 85 // Use .jiri_manifest if no manifest file path is present 86 manifestFiles = append(manifestFiles, jirix.JiriManifestFile()) 87 } else { 88 for _, m := range args { 89 manifestFiles = append(manifestFiles, m) 90 } 91 } 92 // While revision pins for projects can be updated by 'jiri edit', 93 // instance IDs of packages can only be updated by 'jiri resolve' due 94 // to the way how cipd works. Since roller is using 'jiri resolve' 95 // to update a single jiri.lock file each time, it will cause conflicting 96 // instance ids between updated 'jiri.lock' and un-updated 'jiri.lock' files. 97 // Jiri will halt when detecting conflicts in locks. So to make it work, 98 // we need to temporarily disable the conflicts detection. 99 jirix.IgnoreLockConflicts = true 100 return project.GenerateJiriLockFile(jirix, manifestFiles, &resolveFlag) 101 }