-
Notifications
You must be signed in to change notification settings - Fork 323
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
Override CWD in runEngineDistribution
to the parent of the project being run to avoid warning
#10928
Merged
mergify
merged 1 commit into
develop
from
wip/radeusgd/avoid-warning-in-runenginedistribution
Aug 31, 2024
Merged
Override CWD in runEngineDistribution
to the parent of the project being run to avoid warning
#10928
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ import scala.sys.process._ | |
|
||
import org.enso.build.WithDebugCommand | ||
|
||
import scala.util.Try | ||
|
||
object DistributionPackage { | ||
|
||
/** File extensions. */ | ||
|
@@ -267,26 +269,36 @@ object DistributionPackage { | |
): Boolean = { | ||
import scala.collection.JavaConverters._ | ||
|
||
val enso = distributionRoot / "bin" / batName("enso") | ||
log.info(s"Executing $enso ${args.mkString(" ")}") | ||
val pb = new java.lang.ProcessBuilder() | ||
val all = new java.util.ArrayList[String]() | ||
val disablePrivateCheck = { | ||
val findRun = args.indexOf("--run") | ||
if (findRun >= 0 && findRun + 1 < args.size) { | ||
val whatToRun = args(findRun + 1) | ||
val enso = distributionRoot / "bin" / batName("enso") | ||
val pb = new java.lang.ProcessBuilder() | ||
val all = new java.util.ArrayList[String]() | ||
val runArgumentIndex = locateRunArgument(args) | ||
val runArgument = runArgumentIndex.map(args) | ||
val disablePrivateCheck = runArgument match { | ||
case Some(whatToRun) => | ||
if (whatToRun.startsWith("test/") && whatToRun.endsWith("_Tests")) { | ||
whatToRun.contains("_Internal_") | ||
} else { | ||
false | ||
} | ||
} else { | ||
false | ||
} | ||
case None => false | ||
} | ||
all.add(enso.getAbsolutePath()) | ||
|
||
val runArgumentAsFile = runArgument.flatMap(createFileIfValidPath) | ||
val projectDirectory = runArgumentAsFile.flatMap(findProjectRoot) | ||
val cwdOverride: Option[File] = | ||
projectDirectory.flatMap(findParentFile).map(_.getAbsoluteFile) | ||
|
||
all.add(enso.getAbsolutePath) | ||
all.addAll(args.asJava) | ||
pb.command(all) | ||
// Override the working directory of new process to be the parent of the project directory. | ||
cwdOverride.foreach { c => | ||
pb.directory(c) | ||
} | ||
if (cwdOverride.isDefined) { | ||
// If the working directory is changed, we need to translate the path - make it absolute. | ||
all.set(runArgumentIndex.get + 1, runArgumentAsFile.get.getAbsolutePath) | ||
} | ||
if (args.contains("--debug")) { | ||
all.remove("--debug") | ||
pb.environment().put("JAVA_OPTS", "-ea " + WithDebugCommand.DEBUG_OPTION) | ||
|
@@ -296,7 +308,9 @@ object DistributionPackage { | |
if (disablePrivateCheck) { | ||
all.add("--disable-private-check") | ||
} | ||
pb.command(all) | ||
pb.inheritIO() | ||
log.info(s"Executing ${all.asScala.mkString(" ")}") | ||
val p = pb.start() | ||
val exitCode = p.waitFor() | ||
if (exitCode != 0) { | ||
|
@@ -305,6 +319,31 @@ object DistributionPackage { | |
exitCode == 0 | ||
} | ||
|
||
/** Returns the index of the next argument after `--run`, if it exists. */ | ||
private def locateRunArgument(args: Seq[String]): Option[Int] = { | ||
val findRun = args.indexOf("--run") | ||
if (findRun >= 0 && findRun + 1 < args.size) { | ||
Some(findRun + 1) | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
/** Returns a file, only if the provided string represented a valid path. */ | ||
private def createFileIfValidPath(path: String): Option[File] = | ||
Try(new File(path)).toOption | ||
|
||
/** Looks for a parent directory that contains `package.yaml`. */ | ||
private def findProjectRoot(file: File): Option[File] = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. |
||
if (file.isDirectory && (file / "package.yaml").exists()) { | ||
Some(file) | ||
} else { | ||
findParentFile(file).flatMap(findProjectRoot) | ||
} | ||
|
||
private def findParentFile(file: File): Option[File] = | ||
Option(file.getParentFile) | ||
|
||
def runProjectManagerPackage( | ||
engineRoot: File, | ||
distributionRoot: File, | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My only concern is that because the CWD changes, if there were any other paths given as arguments, they may now become invalid.
But I don't think we often add paths to
runEngineDistribution
, do we? Maybe I should add a comment to be sure to prefer absolute paths?I was thinking of a 'heuristic' that will convent relative paths to absolute, but it would be too imprecise - is a
test
argument a path to the./test/
directory or a completely different thing? Impossible to tell without context.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the only path I really care about is after
--run
.