Bazel is still in Beta and new releases may include backward incompatible changes. As we make changes and polish the extension mechanism, old features may be removed and new features that are not backward compatible may be added.
Backward incompatible changes are introduced gradually:
false.true. You can still use the flag to disable the change.To check if your code will be compatible with future releases you can:
--all_incompatible_changes. This flag enables all backward incompatible changes, and so you can ensure your code is compatible with upcoming changes.The following are the backward incompatible changes that are implemented and guarded behind flags in the current release:
We are removing the + operator on dictionaries. This includes the += form where the left-hand side is a dictionary. This is done to improve compatibility with Python. A possible workaround is to use the .update method instead.
--incompatible_disallow_dict_plusfalsePreviously, the load statement could appear anywhere in a .bzl file so long as it was at the top level. With this change, for .bzl files, load must appear at the beginning of the file, i.e. before any other non-load statement.
--incompatible_bzl_disallow_load_after_statementfalseWhen the flag is set to true, depset objects are not treated as iterable. If you need an iterable, call the .to_list() method. This affects for loops and many functions, e.g. list, tuple, min, max, sorted, all, and any. The goal of this change is to avoid accidental iteration on depset, which can be expensive.
deps = depset() [x.path for x in deps] # deprecated [x.path for x in deps.to_list()] # recommended sorted(deps) # deprecated sorted(deps.to_list()) # recommended
--incompatible_depset_is_not_iterablefalseTo merge two sets, the following examples used to be supported, but are now deprecated:
depset1 + depset2 # deprecated depset1 | depset2 # deprecated depset1.union(depset2) # deprecated
The recommended solution is to use the depset constructor:
depset(transtive=[depset1, depset2])
See the depset documentation for more information.
--incompatible_depset_unionfalseWhen the flag is set to true, string objects are not treated as iterable. This affects for loops and many functions, e.g. list, tuple, min, max, sorted, all, and any. String iteration has been a source of errors and confusion, such as this error:
def my_macro(name, srcs): for src in srcs: # do something with src # equivalent to: my_macro("hello", ["f", "o", "o", ".", "c", "c"]) my_macro( name = "hello", srcs = "foo.cc", )
String indexing and len are still allowed. If you need to iterate over a string, you may explicitly use:
my_string = "hello world" for i in range(len(my_string)): char = my_string[i] # do something with char
--incompatible_string_is_not_iterablefalse//Integer division operator is now // instead of /. This aligns with Python 3 and it highlights the fact it is a floor division.
x = 7 / 2 # deprecated x = 7 // 2 # x is 3
--incompatible_disallow_slash_operatorfalseThis change removes the old methods for registering actions within rules, and requires that you use the new methods instead. The deprecated methods and their replacements are as follows.
ctx.new_file(...) --> ctx.actions.declare_file(...)ctx.experimental_new_directory(...) --> ctx.actions.declare_directory(...)ctx.action(...) --> either ctx.actions.run(...) or ctx.actions.run_shell(...)ctx.file_action(...) --> ctx.actions.write(...)ctx.empty_action(...) --> ctx.actions.do_nothing(...)ctx.template_action(...) --> ctx.actions.expand_template(...)--incompatible_new_actions_apifalseWhen set, glob tracking is disabled. This is a legacy feature that we expect has no user-visible impact.
--incompatible_disable_glob_trackingtrue