xcaddy icon indicating copy to clipboard operation
xcaddy copied to clipboard

Add XCADDY_GO_MOD_CACHE_RW env var (#102)

Open akeskimo opened this issue 3 years ago • 6 comments

Commit 47f9ded5d83ca8e701852ca7ad57cd3453e6f988 is not sufficient alone to ensure that all go modules are installed with write bit set because 'go mod' or 'go get' might install submodules of other modules as read-only.

If set, the environment variable appends '-modcacherw' to go mod and go get to ensure that submodules of other modules have write access.

akeskimo avatar Aug 13 '22 10:08 akeskimo

Relates to #102 which was not fully resolved, yet.

akeskimo avatar Aug 13 '22 10:08 akeskimo

It's best if we don't make super specific flags for the various possible options. According to the go command docs -- emphasis mine:

The build flags are shared by the build, clean, get, install, list, run, and test commands:

The env var introduced earlier is concerned with build flags. What do you think of injecting the provided XCADDY_GO_BUILD_FLAGS across the various commands instead of injecting the -modcacherw as a separate flag? Does this resolve your issue?

mohammed90 avatar Aug 13 '22 22:08 mohammed90

Yes, that will also work. I will amend the change.

akeskimo avatar Aug 14 '22 09:08 akeskimo

@mohammed90, I think this patch version is better but it does not support build flags to all those commands that you suggested so I think I can improve this a bit. The only common interface that I could find was this

environment.go:

func (env environment) newCommand(command string, args ...string) *exec.Cmd {
	cmd := exec.Command(command, args...)
	cmd.Dir = env.tempFolder
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	return cmd
}

so I could change this interface to append the build flags but I was not sure if you would be OK with it. The name of that method is very generic and it could be potentially used for running other than build-related commands. What do you think?

akeskimo avatar Aug 15 '22 09:08 akeskimo

I guess this commit would be sufficient as a final solution?

akeskimo avatar Aug 15 '22 09:08 akeskimo

@mohammed90, I think this patch version is better but it does not support build flags to all those commands that you suggested so I think I can improve this a bit. The only common interface that I could find was this

environment.go:

func (env environment) newCommand(command string, args ...string) *exec.Cmd {
	cmd := exec.Command(command, args...)
	cmd.Dir = env.tempFolder
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	return cmd
}

so I could change this interface to append the build flags but I was not sure if you would be OK with it. The name of that method is very generic and it could be potentially used for running other than build-related commands. What do you think?

A method like this can guarantee it's only using go command.

func (env environment) newGoCommand(args ...string) *exec.Cmd {
	return env.newCommand(utils.GetGo(), args...)
}

mohammed90 avatar Aug 15 '22 17:08 mohammed90

Sounds good to me. Thank you for your help, Mohammed!

akeskimo avatar Aug 16 '22 20:08 akeskimo