Skip to content

Commit

Permalink
div endringer
Browse files Browse the repository at this point in the history
  • Loading branch information
tempacc21 committed Nov 28, 2024
1 parent 0fa2628 commit 7ae32ac
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 40 deletions.
10 changes: 10 additions & 0 deletions workshop/case2/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ sh_test(
],
)

#sh_test(
# name = "try_this_acceptance_test",
# size = "small",
# srcs = ["hello_world_from_greeter_test.sh"],
# args = ["$(location :hello)"], # Pass the relative location of the :hello target as an argument
# data = [
# ":hello",
# ],
#)

java_junit5_test(
name = "greeter-test",
size = "small",
Expand Down
47 changes: 8 additions & 39 deletions workshop/case2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,49 +20,18 @@ This generates the `@maven//` namespace and the Starlark-targets for the depende
### Run the binary
`bazel run //workshop/case2:hello` - runs the hello target, which depends on the greeter-lib target and outputs the result.

### Modifying the different parts, and see what recompiles
If you modify the `Greeter.java` file and run `bazel run //workshop/case2:hello`, the `greeter-lib` target will recompile and then the `hello` will rebuild before executing.

If you modify the `HelloWorld.java` file and then run `bazel run //workshop/case2:hello`, the `hello` target will recompile.

You can see how many processes were needed before the build was complete by looking at the output:
```
bazel run //workshop/case2:hello
INFO: Invocation ID: 1ca27de2-08e0-4ff0-93b9-a83b6f518f70
INFO: Analyzed target //workshop/case2:hello (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //workshop/case2:hello up-to-date:
bazel-bin/workshop/case2/hello
bazel-bin/workshop/case2/hello.jar
INFO: Elapsed time: 0.712s, Critical Path: 0.56s
INFO: 2 processes: 1 internal, 1 worker.
INFO: Build completed successfully, 2 total actions
INFO: Running command line: bazel-bin/workshop/case2/hello
Hello, World!
```

Here you can see the line `INFO: 2 processes: 1 internal, 1 worker.` which shows that 2 processes were used to build the target.

If you run it again without modifying anything, you will see that the target is up-to-date and only 1 process are used:
```
INFO: 1 process: 1 internal.
```

## Additional things to try out

### Query Bazel for the dependency graph of the hello target:
`bazel query "deps(//workshop/case2:hello)"`
Here you can see the full dependency graph of the hello target (including all the tools etc bazel use)
![graph](case2_deps2.png)
### Get hello_world_from_greeter_test.sh to work

vs
### Make your own library and consume it in the hello target

`bazel query "deps('//workshop/case2:hello') intersect //..."`
Here you only see the dependencies that are part of the workspace (e.g //...)
### Query Bazel for the dependency graph of the hello target:
`bazel query "deps(//workshop/case2:greeter-test)"`

![graph](case2_deps3.png)
interne deps
`bazel query "deps(//workshop/case2:greeter-test) intersect //..."`

### Show files generated by a target:
`bazel cquery //workshop/case2:hello --output=files`
maven deps
`bazel query "deps(//workshop/case2:greeter-test) intersect @maven//..."`

### Create another library yourself and consume it in the `hello` target
13 changes: 13 additions & 0 deletions workshop/case2/hello_world_from_greeter_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# location of script is passed in as first argument from the target
result="$($1)"

expected="Hello, World! from Greeter"

if [ "$result" == "$expected" ]; then
exit 0
else
echo "Test failed, expected: '$expected', got: '$result'"
exit 1
fi
4 changes: 3 additions & 1 deletion workshop/case3/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ openapi_spring(
name = "openapi_spring",
package_name = "com.workshop.case3",
src = "api.yaml",
visibility = ["//visibility:public"],
visibility = [
"//workshop/case4:__subpackages__",
],
)

openapi_typescript(
Expand Down

0 comments on commit 7ae32ac

Please sign in to comment.