Skip to content

Add prebuild script to use additional build options #8095

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

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
set build option file modification time as sketch modification time o…
…r users build options file
  • Loading branch information
brainelectronics committed Jun 4, 2021
commit b49484de2e2af642aa26176f58685320e9b76079
89 changes: 84 additions & 5 deletions tools/prebuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,97 @@


def create_sketch_dir(build_path):
"""
Create the sketch directory

:param build_path: The path to the build directory
:type build_path: str
"""
sketch_build_path = os.path.join(build_path, "sketch")

if not os.path.exists(sketch_build_path):
os.makedirs(sketch_build_path)


def create_build_options_file(source_path, build_path):
file_source_path = os.path.join(source_path, "build_opt.h")
file_build_path = os.path.join(build_path, "sketch", "build_opt.h")
def create_build_options_file(source_path, build_path, build_opt_name="build_opt.h"):
"""
Create the build options file in the build directory.

The modification time of the build options file is set to the sketch
modification time in case the file did not exist or the users build options
modification time to reflect changes which require a recompilation

:param source_path: The path to the source directory
:type source_path: str
:param build_path: The path to the build directory
:type build_path: str
:param build_opt_name: The build option file name
:type build_opt_name: str, optional
"""
build_opt_source_path = os.path.join(source_path, build_opt_name)
build_opt_build_path = os.path.join(build_path, "sketch", build_opt_name)
build_opt_ctime = get_creation_time(build_opt_build_path)

if not os.path.exists(build_opt_source_path):
# create empty file
open(build_opt_build_path, 'a').close()

# set build_opt.h file modification time to the same time as the sketch
# modification time to avoid rebuilding libraries
sketch_path = get_full_sketch_path(source_path)
sketch_mtime = get_modification_time(sketch_path)
os.utime(build_opt_build_path, (build_opt_ctime, sketch_mtime))
else:
# set build option file modification time to the same time as the users
# build option file modification time to reflect changes which require
# a recompilation
build_opt_mtime = get_modification_time(build_opt_source_path)
os.utime(build_opt_build_path, (build_opt_ctime, build_opt_mtime))


def get_full_sketch_path(source_path):
"""
Get the full sketch path.

:param source_path: The source path
:type source_path: str

:returns: The full sketch path including the '.ino' extension.
:rtype: str
"""
dir_name = os.path.dirname(source_path)
base_name = os.path.basename(dir_name)

sketch_path = os.path.join(dir_name, base_name + '.ino')

return sketch_path


def get_modification_time(file_path):
"""
Get the modification time of a file.

:param file_path: The file path
:type file_path: str

:returns: The modification time.
:rtype: float
"""

return os.path.getmtime(file_path)


def get_creation_time(file_path):
"""
Gets the creation time if a file.

:param file_path: The file path
:type file_path: str

if not os.path.exists(file_source_path):
open(file_build_path, 'a').close()
:returns: The creation time.
:rtype: float
"""
return os.path.getctime(file_path)


def main():
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy