Skip to content
Merged
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
Next Next commit
{Homebrew} remove patch when upgrade
  • Loading branch information
fengzhou-msft committed Feb 25, 2020
commit 368a4d6dc82280929f6171b75bdff8a4e2537678
12 changes: 11 additions & 1 deletion scripts/release/homebrew/docker/formula_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ def update_formula() -> str:
packs_to_remove = set()
lines = text.split('\n')
node_index_dict = OrderedDict()
line_idx_to_remove = set()
upgrade = False
for idx, line in enumerate(lines):
if line.strip().startswith("resource"):
m = re.search(r'resource "(.*)" do', line)
Expand All @@ -141,15 +143,22 @@ def update_formula() -> str:
if line.strip().startswith("url"):
#update the url of package
if pack in nodes.keys():
lines[idx] = re.sub('url ".*"', 'url "{}"'.format(nodes[pack]['url']), line, 1)
url_match = re.search(r'url "(.*)"', line)
if url_match is not None and nodes[pack]['url'] != url_match.group(1):
lines[idx] = re.sub('url ".*"', 'url "{}"'.format(nodes[pack]['url']), line, 1)
upgrade = True
else:
packs_to_remove.add(pack)
elif line.strip().startswith("sha256"):
#update the sha256 of package
if pack in nodes.keys():
lines[idx] = re.sub('sha256 ".*"', 'sha256 "{}"'.format(nodes[pack]['checksum']), line, 1)
del nodes[pack]
elif line.strip().startswith(" end"):
pack = None
upgrade = False
elif upgrade: # In case of upgrading, remove any patch following url and sha256 but before end
line_idx_to_remove.add(idx)
elif line.strip().startswith('def install'):
if nodes:
# add new dependency packages
Expand All @@ -159,6 +168,7 @@ def update_formula() -> str:
line_idx = list(node_index_dict.items())[i][1]
resource = RESOURCE_TEMPLATE.render(resource=node)
lines[line_idx] = resource + '\n\n' + lines[line_idx]
lines = [line for idx, line in enumerate(lines) if idx not in line_idx_to_remove]
new_text = "\n".join(lines)

# remove dependency packages that are no longer needed
Expand Down