Skip to content

Commit 40f47bc

Browse files
committed
Update build.py with ifndef and other fixes
1 parent dffef8a commit 40f47bc

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

build.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
LINKS_RE = re.compile("(?:xref|link):([\./\w_-]*/?[\w_.-]*\.(?:html|adoc))?(#[\w_-]*)?(\[.*?\])", re.M | re.DOTALL)
2525
EXTERNAL_LINK_RE = re.compile("[\./]*([\w_-]+)/[\w_/-]*?([\w_.-]*\.(?:html|adoc))", re.DOTALL)
2626
INCLUDE_RE = re.compile("include::(.*?)\[(.*?)\]", re.M)
27-
IFDEF_RE = re.compile(r"^ifdef::(.*?)\[\]", re.M)
27+
IFDEF_RE = re.compile(r"^if(n?)def::(.*?)\[\]", re.M)
2828
ENDIF_RE = re.compile(r"^endif::(.*?)\[\]\r?\n", re.M)
2929
COMMENT_CONTENT_RE = re.compile(r"^^////$.*?^////$", re.M | re.DOTALL)
3030
TAG_CONTENT_RE = re.compile(r"//\s+tag::(.*?)\[\].*?// end::(.*?)\[\]", re.M | re.DOTALL)
@@ -410,7 +410,7 @@ def copy_file(info, book_src_dir, src_file, dest_dir, dest_file, include_check=T
410410

411411
# Check for any includes
412412
if include_check:
413-
cleaned_content = remove_conditional_content(content, info, tag=tag)
413+
cleaned_content = remove_conditional_content(content, info)
414414
include_iter = INCLUDE_RE.finditer(cleaned_content)
415415
for include in include_iter:
416416
include_text = include.group(0)
@@ -628,12 +628,20 @@ def remove_conditional_content(content, info, tag=None):
628628
# Remove any ifdef content
629629
ifdef = IFDEF_RE.search(content)
630630
while ifdef is not None:
631-
ifdef_distros = ifdef.group(1).split(",")
631+
is_not_def = ifdef.group(1) == "n"
632+
ifdef_distros = ifdef.group(2).split(",")
632633
pos = ifdef.start()
633634
end = ifdef.end()
634635

635-
# Distro isn't in the ifdef content, so remove it
636-
if info['distro'] not in ifdef_distros:
636+
# Determine if we should strip the conditional content, based on the distro
637+
strip_content = False
638+
if is_not_def and info['distro'] in ifdef_distros:
639+
strip_content = True
640+
elif not is_not_def and info['distro'] not in ifdef_distros:
641+
strip_content = True
642+
643+
# Remove the conditional content
644+
if strip_content:
637645
# Find the correct endif for the current ifdef
638646
search_pos = end
639647
endpos = len(content)

0 commit comments

Comments
 (0)