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

Always remove package folder in conan create #4918

Merged
merged 6 commits into from
Apr 29, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
22 changes: 14 additions & 8 deletions conans/client/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,12 @@ def _get_build_folder(self, conanfile, package_layout, pref, keep_build, recorde
return build_folder, skip_build

def _prepare_sources(self, conanfile, pref, package_layout, conanfile_path, source_folder,
build_folder, package_folder, remotes):
build_folder, remotes):
export_folder = package_layout.export()
export_source_folder = package_layout.export_sources()

complete_recipe_sources(self._remote_manager, self._cache, conanfile, pref.ref, remotes)
try:
rmdir(build_folder)
rmdir(package_folder)
except OSError as e:
raise ConanException("%s\n\nCouldn't remove folder, might be busy or open\n"
"Close any app using it, and retry" % str(e))
remove_folder_raising(build_folder)

config_source(export_folder, export_source_folder, source_folder,
conanfile, self._output, conanfile_path, pref.ref,
Expand Down Expand Up @@ -140,6 +135,7 @@ def _build(self, conanfile, pref, build_folder):

def _package(self, conanfile, pref, package_layout, conanfile_path, build_folder,
package_folder):

# FIXME: Is weak to assign here the recipe_hash
manifest = package_layout.recipe_manifest()
conanfile.info.recipe_hash = manifest.summary_hash
Expand Down Expand Up @@ -190,10 +186,12 @@ def build_package(self, node, keep_build, recorder, remotes):
with package_layout.conanfile_write_lock(self._output):
set_dirty(build_folder)
self._prepare_sources(conanfile, pref, package_layout, conanfile_path, source_folder,
build_folder, package_folder, remotes)
build_folder, remotes)

# BUILD & PACKAGE
with package_layout.conanfile_read_lock(self._output):
remove_folder_raising(package_folder)
mkdir(package_folder)
danimtb marked this conversation as resolved.
Show resolved Hide resolved
mkdir(build_folder)
os.chdir(build_folder)
self._output.info('Building your package in %s' % build_folder)
Expand Down Expand Up @@ -227,6 +225,14 @@ def build_package(self, node, keep_build, recorder, remotes):
return node.pref


def remove_folder_raising(folder):
danimtb marked this conversation as resolved.
Show resolved Hide resolved
try:
rmdir(folder)
except OSError as e:
raise ConanException("%s\n\nCouldn't remove folder, might be busy or open\n"
"Close any app using it, and retry" % str(e))
danimtb marked this conversation as resolved.
Show resolved Hide resolved


def _handle_system_requirements(conan_file, pref, cache, out):
""" check first the system_reqs/system_requirements.txt existence, if not existing
check package/sha1/
Expand Down
77 changes: 57 additions & 20 deletions conans/test/functional/command/create_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import os
import textwrap
import unittest

from parameterized.parameterized import parameterized

from conans.client import tools
from conans.test.utils.tools import TestClient
from conans.model.ref import ConanFileReference, PackageReference
from conans.test.utils.tools import TestClient, NO_SETTINGS_PACKAGE_ID
from conans.util.files import load


Expand Down Expand Up @@ -68,29 +70,34 @@ def test(self):
@parameterized.expand([(True, ), (False, )])
def keep_build_test(self, with_test):
client = TestClient()
conanfile = """from conans import ConanFile
class MyPkg(ConanFile):
exports_sources = "*.h"
def source(self):
self.output.info("mysource!!")
def build(self):
self.output.info("mybuild!!")
def package(self):
self.output.info("mypackage!!")
self.copy("*.h")
"""
conanfile = textwrap.dedent("""
from conans import ConanFile

class MyPkg(ConanFile):
exports_sources = "*.h"
def source(self):
self.output.info("mysource!!")
def build(self):
self.output.info("mybuild!!")
def package(self):
self.output.info("mypackage!!")
self.copy("*.h")
""")
if with_test:
client.save({"conanfile.py": conanfile,
"header.h": ""})
else:
test_conanfile = """from conans import ConanFile
class MyPkg(ConanFile):
def test(self):
pass
"""
test_conanfile = textwrap.dedent("""
from conans import ConanFile
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If using dedent, better really indent the contents one more indent, so it is not aligned with test_conanfile.


class MyPkg(ConanFile):
def test(self):
pass
""")
client.save({"conanfile.py": conanfile,
"header.h": "",
"test_package/conanfile.py": test_conanfile})
else:
client.save({"conanfile.py": conanfile,
"header.h": ""})

danimtb marked this conversation as resolved.
Show resolved Hide resolved
client.run("create . Pkg/0.1@lasote/testing")
self.assertIn("Pkg/0.1@lasote/testing: mysource!!", client.out)
self.assertIn("Pkg/0.1@lasote/testing: mybuild!!", client.out)
Expand Down Expand Up @@ -135,6 +142,36 @@ class MyPkg(ConanFile):
client.run("create . Pkg/0.1@lasote/testing --keep-build", assert_error=True)
self.assertIn("ERROR: --keep-build specified, but build folder not found", client.out)

def keep_build_package_folder_test(self):
"""
Package folder should be deleted always before a new conan create command, even with
--keep-build
"""
client = TestClient()
conanfile = textwrap.dedent("""
from conans import ConanFile

class MyPkg(ConanFile):
exports_sources = "*.h", "*.cpp"
def package(self):
self.copy("*.h")
""")
client.save({"conanfile.py": conanfile,
"header.h": "",
"source.cpp": ""})
client.run("create . pkg/0.1@danimtb/testing")
ref = ConanFileReference("pkg", "0.1", "danimtb", "testing")
pref = PackageReference(ref, NO_SETTINGS_PACKAGE_ID)
package_files = os.listdir(client.cache.package(pref))
self.assertIn("header.h", package_files)
self.assertNotIn("source.cpp", package_files)
client.save({"conanfile.py": conanfile.replace("self.copy(\"*.h\")",
"self.copy(\"*.cpp\")")})
client.run("create . pkg/0.1@danimtb/testing -kb")
package_files = os.listdir(client.cache.package(pref))
self.assertNotIn("header.h", package_files)
self.assertIn("source.cpp", package_files)

danimtb marked this conversation as resolved.
Show resolved Hide resolved
def create_test(self):
client = TestClient()
client.save({"conanfile.py": """from conans import ConanFile
Expand Down