build.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env python3
  2. ## Copyright (c) 2024 caryoscelus
  3. ##
  4. ## zeronet-conservancy is free software: you can redistribute it and/or modify it under the
  5. ## terms of the GNU General Public License as published by the Free Software
  6. ## Foundation, either version 3 of the License, or (at your option) any later version.
  7. ##
  8. ## zeronet-conservancy is distributed in the hope that it will be useful, but
  9. ## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  11. ## details.
  12. ##
  13. ## You should have received a copy of the GNU General Public License along with
  14. ## zeronet-conservancy. If not, see <https://www.gnu.org/licenses/>.
  15. ##
  16. """Simple build/bundle script
  17. """
  18. import argparse
  19. def write_to(args, target):
  20. branch = args.branch
  21. commit = args.commit
  22. if branch is None or commit is None:
  23. from src.util import Git
  24. branch = branch or Git.branch() or 'unknown'
  25. commit = commit or Git.commit() or 'unknown'
  26. target.write('\n'.join([
  27. f"build_type = {args.type!r}",
  28. f"branch = {branch!r}",
  29. f"commit = {commit!r}",
  30. f"version = {args.version!r}",
  31. f"platform = {args.platform!r}",
  32. ]))
  33. def main():
  34. parser = argparse.ArgumentParser()
  35. parser.add_argument('--type', default='source')
  36. parser.add_argument('--version')
  37. parser.add_argument('--branch')
  38. parser.add_argument('--commit')
  39. parser.add_argument('--platform', default='source')
  40. parser.add_argument('--stdout', action=argparse.BooleanOptionalAction, default=False)
  41. args = parser.parse_args()
  42. if args.stdout:
  43. import sys
  44. target = sys.stdout
  45. else:
  46. target = open('src/Build.py', 'w')
  47. write_to(args, target)
  48. if __name__ == '__main__':
  49. main()