Disable error prone in bazel - bazel

I have a project with a lot of code. Some of this code doesn't pass error-prone inspections turned on by default in Bazel. I want to disable error-prone in bazel. Is it possible to do it without adding a command line argument via the WORKSPACE file?
P.S. Disabling via command line works well

As Xiao Liang mentioned, you can add --javacopt="-XepDisableAllChecks" to your bazelrc, or you can also add it to tools/bazel.rc inside your workspace so that it can be checked in with the source code. Note though that this will disable error prone for all java builds in the workspace. You can instead use java_binary.javacopts or java_library.javacopts to disable error prone for specific binaries or libraries, which would allow error prone to run on other parts of the build.

Related

How can I turn off line length violations for an entire project when using SwiftLint

I just installed swiftlint and after running it, a lot of my warnings and errors are line length violations. I don't particularly care for how long my lines are. I'm just using SwiftLint to remove more important errors.
Now to be clear, I know I can use a comment like // swiftlint:disable to disable it in one file but I want to disable it across my project. I did have some trouble with the configuration file as well, if you can give me the code for the config, that works too.
Add the line_length rule into the disabled_rules section of your .swiftlint.yml config file
disabled_rules:
- line_length

Is there a way to add native rules to Bazel?

I would like a set of rules from my_package.bzl to be accessible to all BUILD files of a workspace without having to load my_package.bzl in the BUILD files. Basically I want the rules in the package to look like native rules. How can I achieve this?
I was thinking maybe there's a line I could add to one of the .bazelrcs or to the WORKSPACE file of the the project.
This can be achieved by adding a prelude_bazel file at //tools/build_rules:prelude_bazel (this must be a package, so tools/build_rules must contain a BUILD file).
This will be loaded and prepended to all BUILD files loaded by Bazel.
However, there are a few things to consider before going this route. It's currently undocumented, and while doing some searching to find any info on this feature, it's unclear if it will remain a part of Bazel.
It may also have performance / scaling problems. If the prelude were to change (or any of its dependencies), every BUILD file would have to be reloaded, and this may take some time depending on the size of the build graph.

Produce all possible errors with Clang/Ninja / Keep going with Ninja / Ninja equivalent of make -k

I am compiling a fairly large library with many outside dependencies that I need to pull in. Each time I attempt a compilation I get a new error about a missing header file. I then have to go and track down where to find that header/library and add it to the project includes. This process of compilation-then-find-header/source is repeated and takes a lot of time.
I would like the compiler to continue trying to build and output all missing headers in one error list. Is this possible using Clang and if so how can I control it? On a related note, once I have all headers is it possible to tell Clang to report all linker errors/undefined references, so I don't have to repeat this process with source files?
I am looking for compiler flags to print out all possible errors (missing headers) and all undefined references. In other words, I want the compilation to continue passed the first file with errors and attempt to compile all files in the project. The compiler is Clang (C/C++) version 8.0.2. The make tool is ninja (1.5.3). Make files are generated with CMake (3.6.4).
Update:
Looking back, my original question was asking for a solution in the wrong tool. Instead of passing a flag to Clang, I needed to pass a flag to my make tool, Ninja.
From ninja --help:
-k N keep going until N jobs fail [default=1]
so i'd run ninja command like:
ninja -k 100
to continue until 100 errors are found or the build succeeds. One thing to note is that some errors may just stop the entire build if the erroneous file is necessary to continue the build process.

Optional file dependencies in Bazel?

Is there a way to specify optional dependencies in Bazel?
I'd like to make a rule to somewhat mirror Kitware's ExternalData, but I would like to see if I can enable workflows where the developer edits the file in-tree, ideally without needing to modify the BUILD file.
Ideal Workflow
Define a rule, external_data, which can fetch a file from a given server given its SHA-512.
If the file already exists, check it's SHA-512.
If that is what is requested, symlink / copy this file (ensuring that no tests can modify the original file).
If it is different, print a warning, but proceed as normal, to allow for developers to quickly modify the large files as they need.
I would like to do this such that Bazel can switch between the file being present and not, and be robust to false-positives on caching. An example scenario that I would like to avoid, if I were to not include it as an optional dependency:
In a prior run, the file was in the workspace, Bazel built the target, everything's fine and dandy.
Developer removes the file from the workspace after uploading, satisfied with their changes and wanting to test the download process.
When running the downstream target, Bazel doesn't care about the change in the workspace since it's not an explicit dependency, and the symlink is invalidated, and the test crashes and burns.
To me, it seems like I'd run into this if I tried to implement a repository_rule rule which manually checks for the file existence, and conditionally executes (I'm not sure if analysis would retrigger this rule being "evaluated" if Step 2 happens.).
Workaround
My current thought for an alternative workflow is to have an explicit option for external_data, use_workspace: if False, it will download the file; if True, it will just mirror exports_files([]). The developer can then set this when modifying files.
(Ideally, I'd like to optionally include a file which indicates the SHA (${file}.sha512), but this seems to go back to the original ask.)
One workaround is to use Bazel's glob(...) method to effectively check for file existence.
If you have a file, say basic.bin.sha512, and you want a rule to switch modes based on that file's existence, you can use glob(["basic.bin.sha512"]), which will either match the package file exactly or return an empty list.
I had tinkered around with using this on larger sets of files, and it appears to work. However, for the time being, I've erred to having a sort-of explicit "development" mode for the target definition to keep the Bazel build relatively consistent, regardless of what files may be checked out.
Here's an example usage:
https://github.com/EricCousineau-TRI/external_data_bazel/blob/4bf1dff/WORKFLOWS.md#edit-files-in-a-sha512-group

Dynamically loading erlang header files

I know that you can dynamically load erlang beam files in an erlang node using "l(module_name).". My question is is it possible to load ".hrl" files the same way or some such similar without having to restart an erlang node
I am not sure this is possible, but just based on understanding, when you try to define an macro in url and you want to modify it, the compiler replaces the macro during the compilation of the erlang file by replacing the the macros that are defined in header.
Logically you should rebuilding you code and deploy it again. I don't understand a reason why you need hrl files to be loaded dynamically if you have an option for replacing the entire code dynamically. IMHO all you need to do is rebuild and upgrade and this also can be done without restarting erlang node.
".hrl" files - used only by compiler on compile sources. It is not is runtime files.
You can use popular auto-reloader by Mochi team
https://github.com/mochi/mochiweb/blob/master/src/reloader.erl
put them in your src/ folder and add to your exec erl -s reloader option

Resources