Skip to content

Commit b1c8d09

Browse files
fixed genfile path error
1 parent 33ce4db commit b1c8d09

File tree

5 files changed

+67
-34
lines changed

5 files changed

+67
-34
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Set Inputs Example
2+
3+
## Overview
4+
5+
The goal of this example project is to test the performance of Engflow's remote execution and caching service for different input sizes. The project contains a genrule that writes a set number of `.txt` files in the `genfile` directory. The content of this files is then read and printed out with the `Reader` class.
6+
7+
## Project Structure
8+
9+
- `java/com/engflow/internship/setinput/genfile`: Directory where the `.txt` files generated by the genrule are stored.
10+
- `java/com/engflow/internship/varyinginputs/main`: Contains the `Main` class which orchestrates the reading process.
11+
- `java/com/engflow/internship/varyinginputs/reader`: Contains the `Reader` class responsible for reading the files.
12+
13+
## Usage
14+
15+
To generate the test files, build the filegroup target:
16+
```sh
17+
bazel build //java/com/engflow/internship/setinput/genfile
18+
```
19+
20+
Then, the program can be run with the following command:
21+
22+
```sh
23+
bazel run //java/com/engflow/internship/varyinginputs/main
24+
```
25+
26+
To modify the amount of files generated, change the value of the `NUM_FILES` in the `BUILD` file inside the `genfile` directory.
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
NUM_FILES = 10
1+
NUM_FILES = 16
22

33
[genrule(
44
name = "benchmark_test_file" + str(x),
@@ -8,6 +8,5 @@ NUM_FILES = 10
88

99
filegroup(
1010
name = "genfile",
11-
srcs = glob(["genfile/benchmark_test_file*.txt"]),
12-
visibility = ["//visibility:public"],
11+
srcs = [":benchmark_test_file" + str(x) for x in range(1,NUM_FILES+1)],
1312
)

java/com/engflow/internship/setinput/genreader/GenReader.java

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,28 @@
88
public class GenReader {
99

1010
/**
11-
* Reads the content of all files in the specified directory and prints it to the console.
11+
* Reads the content of the specified file and prints it to the console.
1212
* @param inputPath
1313
*/
1414
public void readFiles(String inputPath) {
15-
File directory = new File(inputPath);
15+
File file = new File(inputPath);
1616

17-
// Check if the directory exists and is a directory
18-
if (!directory.exists() || !directory.isDirectory()) {
19-
System.out.println("Invalid directory path: " + inputPath);
17+
// Check if the file exists and is a file
18+
if (!file.exists() || !file.isFile()) {
19+
System.out.println("Invalid file path: " + inputPath + "\n Absolute path: " + file.getAbsolutePath()+
20+
"\n File: " + file);
2021
return;
2122
}
2223

23-
// List all files in the directory and check if there are any
24-
File[] files = directory.listFiles();
25-
if (files == null || files.length == 0) {
26-
System.out.println("No files found in the directory: " + inputPath);
27-
return;
28-
}
29-
30-
// Read the content of each file and print it to the console
31-
for (File file : files) {
32-
if (file.isFile()) {
33-
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
34-
String line;
35-
System.out.println("Reading file: " + file.getName());
36-
while ((line = reader.readLine()) != null) {
37-
System.out.println(line);
38-
}
39-
} catch (IOException e) {
40-
e.printStackTrace();
41-
}
24+
// Read the content of the file and print it to the console
25+
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
26+
String line;
27+
System.out.println("Reading file: " + file.getName());
28+
while ((line = reader.readLine()) != null) {
29+
System.out.println(line);
4230
}
31+
} catch (IOException e) {
32+
e.printStackTrace();
4333
}
4434
}
45-
}
35+
}

java/com/engflow/internship/setinput/main/BUILD

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ java_binary(
66
deps = [
77
"//java/com/engflow/internship/setinput/genreader",
88
],
9-
data = [
10-
"//java/com/engflow/internship/setinput/genfile:genfile",
11-
],
9+
data = glob(["java/com/engflow/internship/setinput/genfile/*.txt"]),
1210
main_class = "com.engflow.internship.setinput.main.Main",
1311
)

java/com/engflow/internship/setinput/main/Main.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,33 @@
22

33
import com.engflow.internship.setinput.genreader.GenReader;
44

5+
import java.nio.file.Paths;
6+
import java.nio.file.Files;
7+
import java.io.IOException;
8+
59
public class Main {
610

711
public static void main(String[] args) {
8-
GenReader reader = new GenReader();
12+
String genfilePath = "java/com/engflow/internship/setinput/genfile"; // Path relative to bazel-bin
13+
String workspacePath = System.getenv("BUILD_WORKING_DIRECTORY");
14+
//System.out.println("Workspace path: " + workspacePath);
915

10-
String filePath = "//java/com/engflow/internship/setinput/genfile:genfile";
16+
if (workspacePath == null) {
17+
System.out.println("Workspace path could not be determined.");
18+
return;
19+
}
1120

12-
reader.readFiles(filePath);
21+
String bazelBinPath = Paths.get(workspacePath, "bazel-bin").toString();
22+
//System.out.println("Bazel-bin path: " + bazelBinPath);
23+
String fullPath = Paths.get(bazelBinPath, genfilePath).toString();
24+
25+
GenReader reader = new GenReader();
26+
try {
27+
Files.list(Paths.get(fullPath))
28+
.filter(Files::isRegularFile)
29+
.forEach(file -> reader.readFiles(file.toString()));
30+
} catch (IOException e) {
31+
e.printStackTrace();
32+
}
1333
}
1434
}

0 commit comments

Comments
 (0)