[package] use bazel-style glob matching for mock/extern (#49066)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/49066
This PR tweaks mock_module and extern_module. They are now renamed
mock and extern, and now only edit the package when a module matching
the pattern specified is required through dependency analysis.
save_extern_module and save_mock_module are added to explicitly modify
the package, but should not be needed by most users of the API unless they
are overriding require_package.
mock and extern now use bazel-style glob matching rules
(https://docs.bazel.build/versions/master/be/functions.html#glob).
i.e. `torch.**` matches `torch` and `torch.bar` but not `torchvision`.
mock and extern also now take an exclude list to filter out packages
that should not apply to the action.
Test Plan: Imported from OSS
Reviewed By: suo
Differential Revision: D25413935
Pulled By: zdevito
fbshipit-source-id: 5c06b417bee94ac8e72c13985b5ec42fcbe00817