@@ -17,6 +17,7 @@ public class McfunctionProcessor extends Worker {
1717 private String currentPackId ;
1818 private Path dataPackRoot ;
1919 private List <Path > dependencyPaths = new ArrayList <>();
20+ private Path workspaceRoot ;
2021
2122 public static void main (String [] args ) throws Exception {
2223 new McfunctionProcessor ().run ();
@@ -26,22 +27,43 @@ public static void main(String[] args) throws Exception {
2627 protected int handleRequest (WorkRequest request , PrintWriter out ) {
2728 var args = request .arguments ();
2829 if (args .size () < 2 ) {
29- out .println ("Usage: McfunctionProcessor <input_file> <output_file> [dependency_files...]" );
30+ out .println ("Usage: McfunctionProcessor <input_file> <output_file> [workspace_root] [ dependency_files...]" );
3031 return 1 ;
3132 }
3233
3334 var inputFile = args .get (0 );
3435 var outputFile = args .get (1 );
3536
37+ // Optional workspace root argument (for Bazel sandbox environment)
38+ Path workspaceRoot = null ;
39+ int depStartIndex = 2 ;
40+
41+ if (args .size () >= 3 ) {
42+ String thirdArg = args .get (2 );
43+ // Check if the third argument looks like a path (not a dependency file)
44+ // Simple heuristic: if it contains "workspace" or doesn't end with .mcfunction or similar
45+ if (!thirdArg .endsWith (".mcfunction" ) && !thirdArg .endsWith (".json" ) && !thirdArg .endsWith (".zip" )) {
46+ workspaceRoot = Paths .get (thirdArg );
47+ depStartIndex = 3 ;
48+ out .println ("Using workspace root: " + workspaceRoot );
49+ }
50+ }
51+
3652 // 解析依赖文件路径
37- for (int i = 2 ; i < args .size (); i ++) {
53+ for (int i = depStartIndex ; i < args .size (); i ++) {
3854 Path depFilePath = Paths .get (args .get (i ));
3955 Path depDataPackRoot = findDataPackRoot (depFilePath );
4056 if (depDataPackRoot != null ) {
4157 dependencyPaths .add (depDataPackRoot );
4258 }
4359 }
4460
61+ // If workspace root is provided, use it as the project root
62+ if (workspaceRoot != null ) {
63+ // Store workspace root for use in findProjectRoot
64+ this .workspaceRoot = workspaceRoot ;
65+ }
66+
4567 try {
4668 processFile (inputFile , outputFile );
4769 } catch (IOException e ) {
@@ -334,6 +356,11 @@ private List<Path> getDataPackSearchPaths() {
334356 }
335357
336358 private Path findProjectRoot () {
359+ // If workspace root is provided, use it as the project root
360+ if (workspaceRoot != null ) {
361+ return workspaceRoot ;
362+ }
363+
337364 if (dataPackRoot == null ) {
338365 return null ;
339366 }
0 commit comments