-
-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add docs for how to break out of Mill sandbox folder (#3518)
Fixes #3510 I decided to try and standardize on a `MILL_WORKSPACE_ROOT` environment variable that is present in both build files and tests, to try and provide a seamless experience to our users. `mill.api.WorkspaceRoot.workspaceRoot` and `T.workspace` are still there but perhaps we can get rid of them in 0.13.0 in favor of using `MILL_WORKSPACE_ROOT` everywhere. After all, accessing the workspace root should be inconvenient to discourage people from doing it unnecessarily, so providing short concise helper methods to do so may even be a net negative
- Loading branch information
Showing
11 changed files
with
103 additions
and
15 deletions.
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
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
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
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Mill's sandboxing approach is best effort: while it tries to guide you into using | ||
// isolated sandbox folders, Mill cannot guarantee it, and in fact provides the | ||
// `MILL_WORKSPACE_ROOT` environment variable to reference the project root folder | ||
// for scenarios where you may need it. This can be useful for a variety of reasons: | ||
// | ||
// * Migrating legacy applications that assume access to the workspace root | ||
// * Scenarios where writing the the original source repository is necessary: | ||
// code auto-formatters, auto-fixers, auto-updaters. etc. | ||
// | ||
// `MILL_WORKSPACE_ROOT` can be used both in tasks: | ||
package build | ||
import mill._, javalib._ | ||
|
||
def tWorkspaceTask = T { println(os.Path(sys.env("MILL_WORKSPACE_ROOT"))) } | ||
|
||
/** Usage | ||
> ./mill tWorkspaceTask | ||
*/ | ||
|
||
// `MILL_WORKSPACE_ROOT` as well as in tests: | ||
|
||
object foo extends JavaModule{ | ||
object test extends JavaTests with TestModule.Junit4 | ||
} | ||
|
||
/** See Also: foo/src/foo/Foo.java */ | ||
/** See Also: foo/test/src/foo/FooTests.java */ | ||
|
||
// Test suites can access the workspace root via the `MILL_WORKSPACE_ROOT` | ||
// environment variable: | ||
|
||
/** Usage | ||
> ./mill __.test | ||
*/ | ||
|
||
/** Usage | ||
|
||
> find . | grep .html | ||
... | ||
.../out/foo/test/test.dest/sandbox/foo.html | ||
|
||
> cat out/foo/test/test.dest/sandbox/foo.html | ||
<h1>foo</h1> | ||
|
||
*/ |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package foo; | ||
|
||
public class Foo { | ||
public static String generateHtml(String text) { | ||
return "<h1>" + text + "</h1>"; | ||
} | ||
} | ||
|
23 changes: 23 additions & 0 deletions
23
example/depth/sandbox/3-breaking/foo/test/src/foo/FooTests.java
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package foo; | ||
|
||
import java.util.stream.Collectors; | ||
import java.nio.file.*; | ||
import static org.junit.Assert.assertEquals; | ||
import org.junit.Test; | ||
|
||
public class FooTests { | ||
@Test | ||
public void simple() throws Exception { | ||
String workspaceRoot = System.getenv("MILL_WORKSPACE_ROOT"); | ||
|
||
for(Path subpath: Files.list(Paths.get(workspaceRoot)).collect(Collectors.toList())){ | ||
String result = Foo.generateHtml(subpath.getFileName().toString()); | ||
Path tmppath = Paths.get(subpath.getFileName() + ".html"); | ||
Files.write(tmppath, result.getBytes()); | ||
assertEquals( | ||
"<h1>" + subpath.getFileName() + "</h1>", | ||
Files.readString(tmppath) | ||
); | ||
} | ||
} | ||
} |
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
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
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
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
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