Skip to content

Commit

Permalink
{Packaging/Homebrew} Remove patch when upgrade (#12344)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengzhou-msft committed Feb 26, 2020
1 parent 5410c7f commit 539554b
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions scripts/release/homebrew/docker/formula_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


def main():
print('Generate formular for Azure CLI homebrew release.')
print('Generate formula for Azure CLI homebrew release.')

parser = argparse.ArgumentParser(prog='formula_generator.py')
parser.set_defaults(func=generate_formula)
Expand Down Expand Up @@ -131,25 +131,34 @@ 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)
if m is not None:
pack = m.group(1)
node_index_dict[pack] = idx
elif pack is not None:
if line.strip().startswith("url"):
if line.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"):
elif line.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.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

0 comments on commit 539554b

Please sign in to comment.