Skip to content

Commit

Permalink
Start writing version status files
Browse files Browse the repository at this point in the history
still need to take it into account in `setup.py`
  • Loading branch information
mara004 committed Sep 13, 2022
1 parent a472366 commit e5ed0ba
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 37 deletions.
20 changes: 6 additions & 14 deletions setupsrc/pl_setup/build_pdfium.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
Host,
SB_Dir,
DataTree,
VerNamespace,
PDFium_URL,
DepotTools_URL,
MainLibnames,
LibnameForSystem,
VerStatusFileName,
PlatformNames,
run_cmd,
call_ctypesgen,
set_version,
)


Expand Down Expand Up @@ -115,22 +114,15 @@ def get_version_info():

def update_version(head_commit, tag_commit, tag):

# TODO(#136@geisserml) Write version status file and handle the changes in `setup.py`.

is_sourcebuild = VerNamespace["IS_SOURCEBUILD"]
curr_libversion = VerNamespace["V_LIBPDFIUM"]

print("Current head %s, latest tagged commit %s (%s)" % (head_commit, tag_commit, tag))
if head_commit == tag_commit:
new_libversion = tag
v_libpdfium = tag
else:
new_libversion = head_commit
v_libpdfium = head_commit

if not is_sourcebuild:
print("Switching from pre-built binaries to source build.")
set_version("IS_SOURCEBUILD", True)
if curr_libversion != new_libversion:
set_version("V_LIBPDFIUM", new_libversion)
ver_file = join(DataTree, PlatformNames.sourcebuild, VerStatusFileName)
with open(ver_file, "w") as fh:
fh.write(v_libpdfium)


def _apply_patchset(patchset):
Expand Down
3 changes: 2 additions & 1 deletion setupsrc/pl_setup/packaging_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
BinaryTargetVar = "PDFIUM_BINARY"
BinaryTarget_None = "none"
BinaryTarget_Auto = "auto"
BindingsFileName = "_pypdfium.py"
BindingsFileName = "_pypdfium.py"
VerStatusFileName = ".pdfium_version.txt"
HomeDir = expanduser("~")
SourceTree = dirname(dirname(dirname(abspath(__file__))))
DataTree = join(SourceTree, "data")
Expand Down
31 changes: 9 additions & 22 deletions setupsrc/pl_setup/update_pdfium.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,16 @@
from pl_setup.packaging_base import (
Host,
DataTree,
VerNamespace,
VerStatusFileName,
ReleaseNames,
BinaryPlatforms,
ReleaseURL,
BinaryTarget_Auto,
set_version,
get_latest_version,
call_ctypesgen,
)


def handle_versions(latest):

# TODO(#136@geisserml) Write version status file and handle the changes in `setup.py`.

v_libpdfium = VerNamespace["V_LIBPDFIUM"]
is_sourcebuild = VerNamespace["IS_SOURCEBUILD"]

if is_sourcebuild:
print("Switching from sourcebuild to pre-built binaries.")
set_version("IS_SOURCEBUILD", False)
if v_libpdfium != latest:
set_version("V_LIBPDFIUM", latest)


def clear_data(download_files):
for pl_name in download_files:
pl_dir = join(DataTree, pl_name)
Expand Down Expand Up @@ -93,7 +78,7 @@ def unpack_archives(archives):
os.remove(file_path)


def generate_bindings(archives):
def generate_bindings(archives, latest_ver):

for pl_name in archives.keys():

Expand All @@ -114,9 +99,12 @@ def generate_bindings(archives):

items = os.listdir(bin_dir)
assert len(items) == 1

shutil.move(join(bin_dir, items[0]), join(pl_dir, target_name))

ver_file = join(DataTree, pl_name, VerStatusFileName)
with open(ver_file, "w") as fh:
fh.write(latest_ver)

call_ctypesgen(pl_dir, join(build_dir, "include"))
shutil.rmtree(build_dir)

Expand All @@ -129,13 +117,12 @@ def main(platforms, robust=False):
platforms = platforms.copy()
platforms[platforms.index(BinaryTarget_Auto)] = Host.platform

latest = get_latest_version()
handle_versions(str(latest))
latest_ver = str( get_latest_version() )
clear_data(platforms)

archives = download_releases(latest, platforms, robust)
archives = download_releases(latest_ver, platforms, robust)
unpack_archives(archives)
generate_bindings(archives)
generate_bindings(archives, latest_ver)


def parse_args(argv):
Expand Down

0 comments on commit e5ed0ba

Please sign in to comment.