Skip to content
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

Debug Appveyor errors #403

Merged
merged 11 commits into from
Jul 17, 2020
Merged
26 changes: 11 additions & 15 deletions cibuildwheel/bashlex_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,22 @@ def evaluate_node(node: bashlex.ast.node, context: NodeExecutionContext) -> str:


def evaluate_word_node(node: bashlex.ast.node, context: NodeExecutionContext) -> str:
word_start = node.pos[0]
word_end = node.pos[1]
word_string = context.input[word_start:word_end]
letters = list(word_string)
value = node.word

for part in node.parts:
part_start = part.pos[0] - word_start
part_end = part.pos[1] - word_start
part_string = context.input[part.pos[0]:part.pos[1]]
part_value = evaluate_node(part, context=context)

# Set all the characters in the part to None
for i in range(part_start, part_end):
letters[i] = ''
if part_string not in value:
raise RuntimeError(
'bash parse failed. part "{}" not found in "{}". Word was "{}". Full input was "{}"'.format(
part_string, value, node.word, context.input,
)
)

letters[part_start] = evaluate_node(part, context=context)
value = value.replace(part_string, part_value, 1)

# remove the None letters and concat
value = ''.join(letters)

# apply bash-like quotes/whitespace treatment
return ' '.join(word.strip() for word in shlex.split(value))
return value


def evaluate_command_node(node: bashlex.ast.node, context: NodeExecutionContext) -> str:
Expand Down
3 changes: 2 additions & 1 deletion test/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def test_overridden_path(tmp_path, capfd):
(new_path / 'python').touch(mode=0o777)

utils.cibuildwheel_run(project_dir, output_dir=output_dir, add_env={
'CIBW_ENVIRONMENT': f'''PATH="{new_path}{os.pathsep}$PATH"''',
'NEW_PATH': str(new_path),
'CIBW_ENVIRONMENT': f'''PATH="$NEW_PATH{os.pathsep}$PATH"''',
})

assert len(os.listdir(output_dir)) == 0
Expand Down
20 changes: 20 additions & 0 deletions unit_test/environment_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,23 @@ def test_operators_inside_eval():
environment_dict = environment_recipe.as_dictionary(os.environ.copy())

assert environment_dict.get('SOMETHING') == 'a\nb\nc'


def test_substitution_with_backslash():
environment_recipe = parse_environment('PATH2="somewhere_else;$PATH1"')

# pass the existing process env so PATH is available
environment_dict = environment_recipe.as_dictionary(prev_environment={
'PATH1': 'c:\\folder\\'
})

assert environment_dict.get('PATH2') == 'somewhere_else;c:\\folder\\'


def test_awkwardly_quoted_variable():
environment_recipe = parse_environment('VAR2=something"like this""$VAR1"$VAR1$(echo "theres more")"$(echo "and more!")"')

# pass the existing process env so PATH is available
environment_dict = environment_recipe.as_dictionary({'VAR1': 'but wait'})

assert environment_dict.get('VAR2') == 'somethinglike thisbut waitbut waittheres moreand more!'