This repository has been archived by the owner on Nov 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Facilitate removing FS access from AndroidResource transformation
Summary: Add an option to specify the inputs for `android_resource` as a map instead of passing the top-level directory as a source path so that we can avoid filesystem access during the target graph to action graph transformation. With this change, there are three possible ways resources and assets can be treated: # They are specified as a PathSourcePath. This used to be the most common way. In this case the contents of the directory are still traversed during the transformation, but then the filtered files are placed in a symlink tree to ensure the filtered out files are not used. # They are specified as a BuildTargetSourcePath. This was not as common and the behavior in this case does not change. There is no FS access and the output of the rule is used in whole. # They are specified as a map from relative path to source path. This is a new option that behaves similarly to the first case, except no FS access is necessary. Future plan is to migrate all users to cases 2 or 3 and then either disable case 1 or remove the filesystem access from it which will mean that no filtering will take case and rule keys might diverge if ignored files are present. Test Plan: * `buck test`. Reviewed By: Coneko fbshipit-source-id: 7af04c3
- Loading branch information
1 parent
9688ec3
commit 3319cd6
Showing
31 changed files
with
732 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
3319cd6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean that we can finally specify multiple resource/asset dirs per
android_resource
rule?because currently in the gradle world with flavors we can have
src/main/res
andsrc/flavor/res
.We generate two
android_resource
rules and add them as a dependency to theandroid_library
. But its a problem because in gradle they are treated as part of the sameandroid_resource
equivalent so resources in main can be accessed in flavor and vice versa. This cannot be possible in buck because it would create a cyclic dependency. It would be great with this change that we can just have multiple directories containing resources be consumed as part of the sameandroid_resource
rule3319cd6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @k21 @dreiss
3319cd6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably. The purpose of this change was actually just to make things faster while preserving our existing semantics, so it might not work exactly as you expect. Give it a shot and let us know how it goes.
3319cd6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok this sorta works.
The
android_resource
rule looks something likeThe only restriction seems to be that there cannot be a file with the same name inside both directories i.e there cannot be a
values/strings.xml
insrc/flavor/res
if that path also exists undersrc/main/res
. However if the file is renamed to something likesrc/flavor/res/values/flavor_strings.xml
, the resource rule builds fine. This seems to be a restriction imposed by the implementation ofsubdir_glob
as it seems that it was originally only intended for C/C++ header maps (https://buckbuild.com/function/subdir_glob.html)Maybe we can add an option to
subdir_glob
to lift this restriction and then we can finally have the ability to specify multiple res/assets directories per anandroid_resource
rule3319cd6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a quick proof of concept, I made the following changes to
src/com/facebook/buck/json/buck_parser/buck.py
This basically made the map key not be the same but prefixed the file name with the source folder flavor name automatically. This is of course not a final solution but just showing the possibility that we can add an option to
subdir_glob
to use some sane scheme for what to do about duplicate keys. If we can maybe add a numbered prefix before the duplicate key for example, that would achieve the same result without affecting the cache keys of the rule by a great deal3319cd6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@k21 @dreiss would appreciate some input on the above suggestions/changes. I can open a follow up issue for this
3319cd6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need to change the behaviour of
subdir_glob
, it's just a builtin function available in build files, there's nothing special about it.You can easily define your own globbing function that handles duplicate keys in a defs file you include and use that instead.
3319cd6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Coneko thanks for the suggestion. I have added support for the use case in uber/okbuck#361