Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.
Upstream: https://github.com/ARMmbed/DAPLink
tools/pre_build_script.py@0:01f31e923fe2, 2020-04-07 (annotated)
- Committer:
- Pawel Zarembski
- Date:
- Tue Apr 07 12:55:42 2020 +0200
- Revision:
- 0:01f31e923fe2
hani: DAPLink with reset workaround
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Pawel Zarembski |
0:01f31e923fe2 | 1 | # |
Pawel Zarembski |
0:01f31e923fe2 | 2 | # DAPLink Interface Firmware |
Pawel Zarembski |
0:01f31e923fe2 | 3 | # Copyright (c) 2009-2019, ARM Limited, All Rights Reserved |
Pawel Zarembski |
0:01f31e923fe2 | 4 | # SPDX-License-Identifier: Apache-2.0 |
Pawel Zarembski |
0:01f31e923fe2 | 5 | # |
Pawel Zarembski |
0:01f31e923fe2 | 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
Pawel Zarembski |
0:01f31e923fe2 | 7 | # not use this file except in compliance with the License. |
Pawel Zarembski |
0:01f31e923fe2 | 8 | # You may obtain a copy of the License at |
Pawel Zarembski |
0:01f31e923fe2 | 9 | # |
Pawel Zarembski |
0:01f31e923fe2 | 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
Pawel Zarembski |
0:01f31e923fe2 | 11 | # |
Pawel Zarembski |
0:01f31e923fe2 | 12 | # Unless required by applicable law or agreed to in writing, software |
Pawel Zarembski |
0:01f31e923fe2 | 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
Pawel Zarembski |
0:01f31e923fe2 | 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Pawel Zarembski |
0:01f31e923fe2 | 15 | # See the License for the specific language governing permissions and |
Pawel Zarembski |
0:01f31e923fe2 | 16 | # limitations under the License. |
Pawel Zarembski |
0:01f31e923fe2 | 17 | # |
Pawel Zarembski |
0:01f31e923fe2 | 18 | |
Pawel Zarembski |
0:01f31e923fe2 | 19 | from __future__ import absolute_import |
Pawel Zarembski |
0:01f31e923fe2 | 20 | from __future__ import print_function |
Pawel Zarembski |
0:01f31e923fe2 | 21 | |
Pawel Zarembski |
0:01f31e923fe2 | 22 | import sys |
Pawel Zarembski |
0:01f31e923fe2 | 23 | import os |
Pawel Zarembski |
0:01f31e923fe2 | 24 | import argparse |
Pawel Zarembski |
0:01f31e923fe2 | 25 | from subprocess import check_output, CalledProcessError |
Pawel Zarembski |
0:01f31e923fe2 | 26 | |
Pawel Zarembski |
0:01f31e923fe2 | 27 | VERSION_GIT_FILE_TEMPLATE = """ |
Pawel Zarembski |
0:01f31e923fe2 | 28 | /** |
Pawel Zarembski |
0:01f31e923fe2 | 29 | * @file version_git.h |
Pawel Zarembski |
0:01f31e923fe2 | 30 | * @brief GIT version info |
Pawel Zarembski |
0:01f31e923fe2 | 31 | * |
Pawel Zarembski |
0:01f31e923fe2 | 32 | * DAPLink Interface Firmware |
Pawel Zarembski |
0:01f31e923fe2 | 33 | * Copyright (c) 2009-2016, ARM Limited, All Rights Reserved |
Pawel Zarembski |
0:01f31e923fe2 | 34 | * SPDX-License-Identifier: Apache-2.0 |
Pawel Zarembski |
0:01f31e923fe2 | 35 | * |
Pawel Zarembski |
0:01f31e923fe2 | 36 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
Pawel Zarembski |
0:01f31e923fe2 | 37 | * not use this file except in compliance with the License. |
Pawel Zarembski |
0:01f31e923fe2 | 38 | * You may obtain a copy of the License at |
Pawel Zarembski |
0:01f31e923fe2 | 39 | * |
Pawel Zarembski |
0:01f31e923fe2 | 40 | * http://www.apache.org/licenses/LICENSE-2.0 |
Pawel Zarembski |
0:01f31e923fe2 | 41 | * |
Pawel Zarembski |
0:01f31e923fe2 | 42 | * Unless required by applicable law or agreed to in writing, software |
Pawel Zarembski |
0:01f31e923fe2 | 43 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
Pawel Zarembski |
0:01f31e923fe2 | 44 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Pawel Zarembski |
0:01f31e923fe2 | 45 | * See the License for the specific language governing permissions and |
Pawel Zarembski |
0:01f31e923fe2 | 46 | * limitations under the License. |
Pawel Zarembski |
0:01f31e923fe2 | 47 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 48 | #ifndef VERSION_GIT_H |
Pawel Zarembski |
0:01f31e923fe2 | 49 | #define VERSION_GIT_H |
Pawel Zarembski |
0:01f31e923fe2 | 50 | |
Pawel Zarembski |
0:01f31e923fe2 | 51 | #define GIT_COMMIT_SHA \"%s\" |
Pawel Zarembski |
0:01f31e923fe2 | 52 | #define GIT_LOCAL_MODS %d |
Pawel Zarembski |
0:01f31e923fe2 | 53 | |
Pawel Zarembski |
0:01f31e923fe2 | 54 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 55 | |
Pawel Zarembski |
0:01f31e923fe2 | 56 | """ |
Pawel Zarembski |
0:01f31e923fe2 | 57 | |
Pawel Zarembski |
0:01f31e923fe2 | 58 | |
Pawel Zarembski |
0:01f31e923fe2 | 59 | |
Pawel Zarembski |
0:01f31e923fe2 | 60 | def generate_version_file(version_git_dir): |
Pawel Zarembski |
0:01f31e923fe2 | 61 | |
Pawel Zarembski |
0:01f31e923fe2 | 62 | output_file = os.path.join(os.path.normpath(version_git_dir),'version_git.h') |
Pawel Zarembski |
0:01f31e923fe2 | 63 | print("#> Pre-build script start") |
Pawel Zarembski |
0:01f31e923fe2 | 64 | |
Pawel Zarembski |
0:01f31e923fe2 | 65 | # Get the git SHA. |
Pawel Zarembski |
0:01f31e923fe2 | 66 | print("#> Getting git SHA") |
Pawel Zarembski |
0:01f31e923fe2 | 67 | try: |
Pawel Zarembski |
0:01f31e923fe2 | 68 | git_sha = check_output("git rev-parse --verify HEAD", shell=True) |
Pawel Zarembski |
0:01f31e923fe2 | 69 | git_sha = git_sha.decode().strip() |
Pawel Zarembski |
0:01f31e923fe2 | 70 | except: |
Pawel Zarembski |
0:01f31e923fe2 | 71 | print("#> ERROR: Failed to get git SHA, do you have git.exe in your PATH environment variable?") |
Pawel Zarembski |
0:01f31e923fe2 | 72 | return 1 |
Pawel Zarembski |
0:01f31e923fe2 | 73 | |
Pawel Zarembski |
0:01f31e923fe2 | 74 | # Check are there any local, uncommitted modifications. |
Pawel Zarembski |
0:01f31e923fe2 | 75 | print("#> Checking for local changes") |
Pawel Zarembski |
0:01f31e923fe2 | 76 | try: |
Pawel Zarembski |
0:01f31e923fe2 | 77 | check_output("git diff --no-ext-diff --quiet --exit-code", shell=True) |
Pawel Zarembski |
0:01f31e923fe2 | 78 | except (CalledProcessError, OSError): |
Pawel Zarembski |
0:01f31e923fe2 | 79 | git_has_changes = 1 |
Pawel Zarembski |
0:01f31e923fe2 | 80 | else: |
Pawel Zarembski |
0:01f31e923fe2 | 81 | git_has_changes = 0 |
Pawel Zarembski |
0:01f31e923fe2 | 82 | |
Pawel Zarembski |
0:01f31e923fe2 | 83 | |
Pawel Zarembski |
0:01f31e923fe2 | 84 | # Create the version file. Only overwrite an existing file if it changes. |
Pawel Zarembski |
0:01f31e923fe2 | 85 | version_text = VERSION_GIT_FILE_TEMPLATE % (git_sha, git_has_changes) |
Pawel Zarembski |
0:01f31e923fe2 | 86 | try: |
Pawel Zarembski |
0:01f31e923fe2 | 87 | with open(output_file, 'r') as version_file: |
Pawel Zarembski |
0:01f31e923fe2 | 88 | current_version_text = version_file.read() |
Pawel Zarembski |
0:01f31e923fe2 | 89 | except IOError: |
Pawel Zarembski |
0:01f31e923fe2 | 90 | current_version_text = '' |
Pawel Zarembski |
0:01f31e923fe2 | 91 | if version_text != current_version_text: |
Pawel Zarembski |
0:01f31e923fe2 | 92 | print("#> Writing git version file") |
Pawel Zarembski |
0:01f31e923fe2 | 93 | with open(output_file, 'w+') as version_file: |
Pawel Zarembski |
0:01f31e923fe2 | 94 | version_file.write(version_text) |
Pawel Zarembski |
0:01f31e923fe2 | 95 | else: |
Pawel Zarembski |
0:01f31e923fe2 | 96 | print("#> Keeping git version file since it didn't need to change") |
Pawel Zarembski |
0:01f31e923fe2 | 97 | |
Pawel Zarembski |
0:01f31e923fe2 | 98 | print("#> Pre-build script completed written %s" % output_file ) |
Pawel Zarembski |
0:01f31e923fe2 | 99 | |
Pawel Zarembski |
0:01f31e923fe2 | 100 | return 0 |
Pawel Zarembski |
0:01f31e923fe2 | 101 | |
Pawel Zarembski |
0:01f31e923fe2 | 102 | if __name__ == "__main__": |
Pawel Zarembski |
0:01f31e923fe2 | 103 | parser = argparse.ArgumentParser(description='git version generator') |
Pawel Zarembski |
0:01f31e923fe2 | 104 | parser.add_argument("--version_git_dir", type=str, default='../../../source/daplink/', help="directory to output version_git.h file") |
Pawel Zarembski |
0:01f31e923fe2 | 105 | args = parser.parse_args() |
Pawel Zarembski |
0:01f31e923fe2 | 106 | exit(generate_version_file(args.version_git_dir)) |