Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use nailgun environment in forked processes #413

Merged
merged 5 commits into from
Apr 5, 2018

Conversation

jvican
Copy link
Contributor

@jvican jvican commented Mar 29, 2018

This commit propagates the remoteEnv properties in the nailgun context
to the place where we run and test projects in forked projects. Thanks
to the fact that we always fork, we're able to use the environment
variables from the user without weird hacks to mutate System.getenv
and scope it per client.

Fixes #335.

@@ -9,8 +9,8 @@ object Integrations {
val MiniBetterFiles = RootProject(uri(
"git://github.com/scalacenter/mini-better-files.git#0ed848993a2fd5a36e4366b5efb9c68dce958fc2"))
val WithResources = RootProject(
uri("git://github.com/scalacenter/with-resources.git#7529b2c3ac455cbb1889d4791c4e0d4957e29306"))
uri("git://github.com/scalacenter/with-resources.git#f0a46830cae7ef6282d9bba64b6da34bae18f339"))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These new hashes contain modifications to the dummy code to fail if the env variable BLOOP_OWNER is not accessible via sys.env.

@jvican
Copy link
Contributor Author

jvican commented Mar 29, 2018

What this means is that now Bloop will use the environment variable of the places where the bloop client is involved (e.g. your terminal) to run and test code.

@jvican jvican force-pushed the topic/expose-env-variables branch 4 times, most recently from 5d35914 to e161985 Compare April 2, 2018 19:15
@jvican jvican requested a review from Duhemm April 2, 2018 19:47
@jvican
Copy link
Contributor Author

jvican commented Apr 2, 2018

This is ready for review 🎉.

Copy link
Collaborator

@Duhemm Duhemm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor comment, and a question.

Are we sure that we want to remove everything from a forked process' environment before adding more values? Could we be discarding values that users would expect to be present in the environment?

@@ -47,6 +47,7 @@ final case class ForkProcess(javaEnv: JavaEnv, classpath: Array[AbsolutePath]) {
className: String,
args: Array[String],
logger: Logger,
env: Properties,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc needs updating

@@ -68,6 +69,9 @@ final case class ForkProcess(javaEnv: JavaEnv, classpath: Array[AbsolutePath]) {
} else {
val processBuilder = new ProcessBuilder(cmd: _*)
processBuilder.directory(cwd.toFile)
val processEnv = processBuilder.environment()
processEnv.clear()
env.forEach { case (k: String, v: String) => processEnv.put(k, v); () }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that you can use putAll here

@@ -68,6 +69,9 @@ final case class ForkProcess(javaEnv: JavaEnv, classpath: Array[AbsolutePath]) {
} else {
val processBuilder = new ProcessBuilder(cmd: _*)
processBuilder.directory(cwd.toFile)
val processEnv = processBuilder.environment()
processEnv.clear()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure that we want to discard everything?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I elaborated on my other comment.

@@ -79,7 +73,8 @@ object TestInternals {
fork: ForkProcess,
discoveredTests: DiscoveredTests,
eventHandler: EventHandler,
logger: Logger): Unit = {
logger: Logger,
env: Properties): Unit = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc needs updating

import scala.collection.JavaConverters._
System.getenv().asScala.foldLeft(new Properties()) {
case (props, (key, value)) => props.setProperty(key, value); props
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use clone?

@jvican
Copy link
Contributor Author

jvican commented Apr 3, 2018

Are we sure that we want to remove everything from a forked process' environment before adding more values? Could we be discarding values that users would expect to be present in the environment?

This PR will not expose any of the server's environment variables to the test and run tasks, so yeah, if users expect those to be in they won't. I think that doing this is the right behaviour, and it's very unlikely someone would want env variables from the server for these particular tasks.

However, the rest of the tasks will still use the environment variables of the server (as expected).

Copy link
Collaborator

@Duhemm Duhemm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jvican jvican force-pushed the topic/expose-env-variables branch from 0bfacfe to 704169e Compare April 3, 2018 08:34
This commit propagates the `remoteEnv` properties in the nailgun context
to the place where we run and test projects in forked projects. Thanks
to the fact that we always fork, we're able to use the environment
variables from the user without weird hacks to mutate `System.getenv`
and scope it per client.

Fixes #335.
The problem is that we were expecting 5 sources instead of 6.

This commit fixes that and adds more cases to make the whole test more
reliable.
Something is acting up.
@jvican jvican force-pushed the topic/expose-env-variables branch from 704169e to 87181dc Compare April 3, 2018 09:36
@jvican jvican merged commit 0dbe10a into master Apr 5, 2018
@tgodzik tgodzik deleted the topic/expose-env-variables branch September 7, 2021 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants