-
Notifications
You must be signed in to change notification settings - Fork 51
Refactor Analytics swig logic #1108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5960a67
Refactor Analytics swig logic
a-maurice 8dd0b83
Merge branch 'main' into am-analytics_rewrite
a-maurice 4e151ab
Merge branch 'main' into am-analytics_rewrite
a-maurice 5155039
Merge branch 'main' into am-analytics_rewrite
a-maurice ee0af3d
Update CMakeLists.txt
a-maurice 21ff551
Merge branch 'main' into am-analytics_rewrite
a-maurice 05e055d
Add a deprecated ParameterGroupId
a-maurice cb8862d
Add generated headers to the doc only logic
a-maurice 84bbaab
Update generate_constants.py
a-maurice File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| # Copyright 2024 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Convert C++ headers of Analytics constants to C# files.""" | ||
|
|
||
| import datetime | ||
| import os | ||
| import re | ||
| import subprocess | ||
|
|
||
| from absl import app | ||
| from absl import flags | ||
|
|
||
| FLAGS = flags.FLAGS | ||
|
|
||
| # Required args | ||
| flags.DEFINE_string('cpp_header', '', 'C++ header file containing a ' | ||
| 'set of constants to convert to C#.') | ||
| flags.register_validator( | ||
| 'cpp_header', | ||
| lambda x: x and os.path.exists(x), | ||
| message=('Must reference an existing C++ header file')) | ||
| flags.DEFINE_string('csharp_file', '', 'Full path of the C# file to write ' | ||
| 'out.') | ||
| flags.register_validator( | ||
| 'csharp_file', lambda x: x, message='Output C# file must be specified') | ||
|
|
||
| CPP_NAMESPACE = 'namespace analytics' | ||
|
|
||
| DOC_REPLACEMENTS = [ | ||
| ('static const char\*const k', 'public static string ') | ||
| ] | ||
|
|
||
|
|
||
| def main(unused_argv): | ||
| """Convert the C++ file into C#, going line-by-line to edit it.""" | ||
| with open(FLAGS.cpp_header) as input_file: | ||
| with open(FLAGS.csharp_file, 'w') as output_file: | ||
| # Write the initial lines at the top | ||
| output_file.write('// Copyright %s Google Inc. All Rights Reserved.\n\n' % | ||
| str(datetime.date.today().year)) | ||
| output_file.write('namespace Firebase.Analytics {\n\n') | ||
| output_file.write('public static partial class FirebaseAnalytics {\n\n') | ||
|
|
||
| found_namespace = False | ||
| for line in input_file: | ||
| line = line.rstrip() | ||
|
|
||
| # Ignore everything in the C++ file until inside the namespaces | ||
| if not found_namespace: | ||
| if re.search(CPP_NAMESPACE, line): | ||
| found_namespace = True | ||
| continue | ||
| # Stop copying when finding the next namespace (we assume it is closing) | ||
| if re.search(CPP_NAMESPACE, line): | ||
| break | ||
|
|
||
| for replace_from, replace_to in DOC_REPLACEMENTS: | ||
| if (re.search(replace_from, line)): | ||
| line = re.sub(replace_from, replace_to, line) | ||
| output_file.write(line + '\n') | ||
|
|
||
| # Write the lines at the end | ||
| # Close the class | ||
| output_file.write('}\n\n') | ||
| # close the namespace | ||
| output_file.write('}\n') | ||
|
|
||
| return 0 | ||
|
|
||
| if __name__ == '__main__': | ||
| app.run(main) | ||
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* | ||
| * Copyright 2024 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| namespace Firebase.Analytics { | ||
|
|
||
| /// @brief The type of consent to set. | ||
| /// | ||
| /// Supported consent types are mapped to corresponding constants in the Android | ||
| /// and iOS SDKs. Omitting a type retains its previous status. | ||
| public enum ConsentType { | ||
| AdStorage = 0, | ||
| AnalyticsStorage, | ||
| AdUserData, | ||
| AdPersonalization | ||
| } | ||
|
|
||
| /// @brief The status value of the consent type. | ||
| /// | ||
| /// Supported statuses are ConsentStatus.Granted and ConsentStatus.Denied. | ||
| public enum ConsentStatus { | ||
| Granted = 0, | ||
| Denied | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.