Skip to content

Commit 811af18

Browse files
heliocastronnobelis
authored andcommitted
refactor: Use environments to install Conan
- Move previous conan/conan2 naming approach to Python environment solution. A wrapper that detects CONAN_SERIES environment var switchis between the two release series. Defaults to CONAN_SERIES=2. - Enable profile creation support by default Passing environment var CONAN_CREATE_PROFILE=false will prevent to generate a default profile. Signed-off-by: Helio Chissini de Castro <[email protected]> Signed-off-by: Nicolas Nobelis <[email protected]>
1 parent f105df0 commit 811af18

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

Dockerfile

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ ARG PYTHON_VERSION
136136
ARG PYENV_GIT_TAG
137137

138138
ENV PYENV_ROOT=/opt/python
139-
ENV PATH=$PATH:$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PYENV_ROOT/conan2/bin
139+
ENV PATH=$PATH:$PYENV_ROOT/shims:$PYENV_ROOT/bin
140140
RUN curl -kSs https://pyenv.run | bash \
141141
&& pyenv install -v $PYTHON_VERSION \
142142
&& pyenv global $PYTHON_VERSION
@@ -170,18 +170,26 @@ RUN pip install --no-cache-dir -U \
170170
wheel \
171171
&& pip install --no-cache-dir -U \
172172
Mercurial \
173-
conan=="$CONAN_VERSION" \
174173
pipenv=="$PYTHON_PIPENV_VERSION" \
175174
poetry=="$PYTHON_POETRY_VERSION" \
176175
poetry-plugin-export=="$PYTHON_POETRY_PLUGIN_EXPORT_VERSION" \
177176
python-inspector=="$PYTHON_INSPECTOR_VERSION" \
178177
setuptools=="$PYTHON_SETUPTOOLS_VERSION"
179-
RUN mkdir /tmp/conan2 && cd /tmp/conan2 \
180-
&& wget https://github.com/conan-io/conan/releases/download/$CONAN2_VERSION/conan-$CONAN2_VERSION-linux-x86_64.tgz \
181-
&& tar -xvf conan-$CONAN2_VERSION-linux-x86_64.tgz\
182-
# Rename the Conan 2 executable to "conan2" to be able to call both Conan version from the package manager.
183-
&& mkdir $PYENV_ROOT/conan2 && mv /tmp/conan2/bin $PYENV_ROOT/conan2/ \
184-
&& mv $PYENV_ROOT/conan2/bin/conan $PYENV_ROOT/conan2/bin/conan2
178+
179+
# Create conan environments
180+
COPY scripts/setup_conan.sh ${PYENV_ROOT}/bin/conan
181+
RUN eval "$(pyenv init - bash)" \
182+
&& eval "$(pyenv virtualenv-init -)" \
183+
&& pyenv virtualenv conan \
184+
&& pyenv activate conan \
185+
&& pip install conan==${CONAN_VERSION} \
186+
&& pyenv deactivate \
187+
&& pyenv virtualenv conan2 \
188+
&& pyenv activate conan2 \
189+
&& pip install conan==${CONAN2_VERSION} \
190+
&& pyenv deactivate \
191+
&& sudo chmod +x ${PYENV_ROOT}/bin/conan
192+
185193

186194
FROM scratch AS python
187195
COPY --from=pythonbuild /opt/python /opt/python
@@ -484,7 +492,7 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
484492

485493
# Python
486494
ENV PYENV_ROOT=/opt/python
487-
ENV PATH=$PATH:$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PYENV_ROOT/conan2/bin
495+
ENV PATH=$PATH:$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PYENV_ROOT/plugins/pyenv-virtualenv/shims
488496
COPY --from=python --chown=$USER:$USER $PYENV_ROOT $PYENV_ROOT
489497

490498
# NodeJS

plugins/package-managers/conan/src/main/kotlin/Conan.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ internal class ConanCommand(private val useConan2: Boolean = false) : CommandLin
7878
override fun getVersionRequirement(): RangesList = RangesListFactory.create(">=1.44.0 <3.0")
7979

8080
override fun run(vararg args: CharSequence, workingDir: File?, environment: Map<String, String>) =
81-
super.run(args = args, workingDir, environment + ("CONAN_NON_INTERACTIVE" to "1"))
81+
super.run(args = args, workingDir, environment + mapOf("CONAN_NON_INTERACTIVE" to "1", "CONAN_SERIES" to "1"))
8282
}
8383

8484
data class ConanConfig(

scripts/setup_conan.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
conan_option=${CONAN_SERIES:-2}
4+
5+
# Since this script is installed with the name "conan", there is a risk of infinite recursion if pyenv is not available
6+
# on the PATH, which can occur when setting up a development environment. To prevent this, check for recursive calls.
7+
if [[ "$CONAN_RECURSIVE_CALL" -eq 1 ]]; then
8+
echo "Recursive call detected. Exiting."
9+
exit 1
10+
fi
11+
12+
# Setup pyenv
13+
eval "$(pyenv init - bash)"
14+
eval "$(pyenv virtualenv-init -)"
15+
16+
# Setting up Conan 1.x
17+
if [[ "$conan_option" -eq 1 ]]; then # Setting up Conan 1.x series
18+
pyenv activate conan
19+
# Docker has modern libc
20+
CONAN_RECURSIVE_CALL=1 conan profile update settings.compiler.libcxx=libstdc++11 ort-default
21+
elif [[ "$conan_option" -eq 2 ]]; then # Setting up Conan 2.x series
22+
pyenv activate conan2
23+
fi
24+
25+
# Runs conan from activated profile
26+
CONAN_RECURSIVE_CALL=1 conan "$@"
27+

0 commit comments

Comments
 (0)