@@ -18,6 +18,7 @@ import (
1818 "github.com/kballard/go-shellquote"
1919 "github.com/microsoft/azldev/internal/global/opctx"
2020 "github.com/microsoft/azldev/internal/utils/hostinfo"
21+ "github.com/samber/lo"
2122)
2223
2324const (
@@ -46,6 +47,10 @@ type Runner struct {
4647 bindMounts []bindMountRequest
4748 enableNetwork bool
4849
50+ // noPreClean requests that the root *not* be cleaned on command execution, even if mock deems
51+ // it ought to be.
52+ noPreClean bool
53+
4954 // baseDir is the base directory where mock will create all of its root directories. If not set,
5055 // it defaults to the host system default (typically, /var/lib/mock).
5156 baseDir string // optional
@@ -83,6 +88,9 @@ func (r *Runner) Clone() *Runner {
8388 mockConfigPath : r .mockConfigPath ,
8489 bindMounts : deep .MustCopy (r .bindMounts ),
8590 enableNetwork : r .enableNetwork ,
91+ noPreClean : r .noPreClean ,
92+ baseDir : r .baseDir ,
93+ rootDir : r .rootDir ,
8694 }
8795}
8896
@@ -97,13 +105,39 @@ func (r *Runner) AddBindMount(hostPath, mockRootPath string) *Runner {
97105 return r
98106}
99107
108+ // BindMounts retrieves the set of bind mounts configured for this [Runner], expressed as
109+ // a map from host path to mock root path.
110+ func (r * Runner ) BindMounts () map [string ]string {
111+ return lo .SliceToMap (r .bindMounts , func (item bindMountRequest ) (string , string ) {
112+ return item .hostPath , item .mockRootPath
113+ })
114+ }
115+
100116// Updates the [Runner]'s configuration to enable external network access from within the mock root.
101117func (r * Runner ) EnableNetwork () * Runner {
102118 r .enableNetwork = true
103119
104120 return r
105121}
106122
123+ // HasNetworkEnabled indicates whether the [Runner] is configured to enable network access.
124+ func (r * Runner ) HasNetworkEnabled () bool {
125+ return r .enableNetwork
126+ }
127+
128+ // WithNoPreClean updates the [Runner]'s configuration to ensure that mock does *not* pre-clean
129+ // the root when invoking an operation.
130+ func (r * Runner ) WithNoPreClean () * Runner {
131+ r .noPreClean = true
132+
133+ return r
134+ }
135+
136+ // HasNoPreClean indicates whether the [Runner] is configured to avoid pre-cleaning the root.
137+ func (r * Runner ) HasNoPreClean () bool {
138+ return r .noPreClean
139+ }
140+
107141// WithBaseDir updates the [Runner]'s configuration to set which directory mock roots are created
108142// under by default. If not set, mock will write under its default base (/var/lib/mock).
109143func (r * Runner ) WithBaseDir (baseDir string ) * Runner {
@@ -112,6 +146,11 @@ func (r *Runner) WithBaseDir(baseDir string) *Runner {
112146 return r
113147}
114148
149+ // BaseDir retrieves the path to the base directory used by this [Runner] for mock roots.
150+ func (r * Runner ) BaseDir () string {
151+ return r .baseDir
152+ }
153+
115154// WithRootDir update's the [Runner]'s configuration to set which directory the root is created
116155// under.
117156func (r * Runner ) WithRootDir (rootDir string ) * Runner {
@@ -120,6 +159,11 @@ func (r *Runner) WithRootDir(rootDir string) *Runner {
120159 return r
121160}
122161
162+ // RootDir retrieves the path to the mock root used by this [Runner].
163+ func (r * Runner ) RootDir () string {
164+ return r .rootDir
165+ }
166+
123167// Retrieves the path to the mock .cfg file used by this [Runner].
124168func (r * Runner ) ConfigPath () string {
125169 return r .mockConfigPath
@@ -147,7 +191,7 @@ func (r *Runner) InitRoot(ctx context.Context) (err error) {
147191 }
148192
149193 if ! r .verbose {
150- extcmd .SetLongRunning ("Waiting for mock..." )
194+ extcmd .SetLongRunning ("Waiting for mock (initializing build root) ..." )
151195 }
152196
153197 err = extcmd .Run (ctx )
@@ -226,7 +270,7 @@ func (r *Runner) BuildSRPM(
226270 }
227271
228272 if ! r .verbose {
229- extcmd .SetLongRunning ("Waiting for mock..." )
273+ extcmd .SetLongRunning ("Waiting for mock (building SRPM) ..." )
230274 }
231275
232276 // Watch output logs in real-time so we can asynchronously synthesize progress updates.
@@ -314,7 +358,7 @@ func (r *Runner) BuildRPM(ctx context.Context, srpmPath, outputDirPath string, o
314358 return fmt .Errorf ("failed to create external command for mock: %w" , err )
315359 }
316360
317- extcmd = extcmd .SetLongRunning ("Waiting for mock..." )
361+ extcmd = extcmd .SetLongRunning ("Waiting for mock (building RPM) ..." )
318362
319363 // Watch output logs in real-time so we can asynchronously synthesize progress updates.
320364 err = addMockLogListeners (r .eventListener , extcmd , outputDirPath )
@@ -457,6 +501,8 @@ func (r *Runner) ScrubRoot(ctx context.Context) error {
457501 return fmt .Errorf ("failed to create external command for mock: %w" , err )
458502 }
459503
504+ extcmd = extcmd .SetLongRunning ("Waiting for mock (cleaning build root)..." )
505+
460506 err = extcmd .Run (ctx )
461507 if err != nil {
462508 return fmt .Errorf ("mock failed to scrub root: %w" , err )
@@ -493,6 +539,10 @@ func (r *Runner) getBaseArgs() (args []string) {
493539 args = append (args , "--enable-network" )
494540 }
495541
542+ if r .noPreClean {
543+ args = append (args , "--no-clean" )
544+ }
545+
496546 if len (r .bindMounts ) > 0 {
497547 pairs := []string {}
498548
0 commit comments