|
| 1 | +# Multiple Binary Input Example |
| 2 | + |
| 3 | +## Usage |
| 4 | +Set the `NUM_FILES` variable in the BUILD file to the desired input size. |
| 5 | + |
| 6 | +To generate the test files, build the `genbinary` library using the `genrule`: |
| 7 | +```sh |
| 8 | +bazel build //java/com/engflow/binaryinput:genbinary{1..<NUM_FILES>} |
| 9 | +``` |
| 10 | + |
| 11 | +Then, the program can be built with the following command: |
| 12 | +```sh |
| 13 | +bazel build //java/com/engflow/binaryinput:main |
| 14 | +``` |
| 15 | + |
| 16 | +## How It Works |
| 17 | + |
| 18 | +1. **Generation of Java Binaries:** |
| 19 | + - The `genrule` in the `BUILD` file generates a specified number of Java classes (`Hello1.java`, `Hello2.java`, ..., `HelloN.java`). |
| 20 | + - Each generated class contains a `greetNum` method that prints a unique message. |
| 21 | + - A java library is created for each file (`Hello1.jar`, `Hello2.jar`, ..., `HelloN.jar`). |
| 22 | + |
| 23 | +2. **Building the main target:** |
| 24 | + - The previously created libraries are added to the main class as dependencies through a for loop. |
| 25 | + - The consistent naming scheme of the libraries simplifies their inclusion in the build process. |
| 26 | + |
| 27 | +3. **Main Class Execution:** |
| 28 | + - The `Main.java` file in `binaryinput` dynamically loads each generated class using reflection. |
| 29 | + - It then invokes the `greetNum` method of each class, printing the corresponding message. |
| 30 | + |
| 31 | +## Configuration |
| 32 | + |
| 33 | +The number of generated files is controlled by the `NUM_FILES` variable in the `BUILD` file of the `binaryinput` package. Modify this variable to change the number of generated classes and observe the performance impact on Engflow's remote execution and caching service. |
| 34 | + |
| 35 | +## Example |
| 36 | + |
| 37 | +To generate and run the program with 10 input binary files: |
| 38 | + |
| 39 | +1. Set `NUM_FILES` to 10 in `java/com/engflow/binaryinput/BUILD`. |
| 40 | +2. Build the `genbinary` library: |
| 41 | + ```sh |
| 42 | + bazel build //java/com/engflow/binaryinput:genbinary{1..10} |
| 43 | + ``` |
| 44 | +3. Build the `main` binary: |
| 45 | + ```sh |
| 46 | + bazel build //java/com/engflow/binaryinput:main |
| 47 | + ``` |
| 48 | + |
| 49 | +This will generate 10 Java classes, build the `genbinary` library, and build the `main` binary. Using `bazel run` will also print messages from each generated class. |
0 commit comments