[cmake-developers] [patch] One more pattern for extracting file name from URL

Ruslan Baratov ruslan_baratov at yahoo.com
Tue Jul 5 17:14:48 EDT 2016


On 05-Jul-16 23:26, Brad King wrote:
> On 07/05/2016 04:13 PM, Ruslan Baratov wrote:
>> Works fine on my tests.
> Thanks for testing!
>
>> However I still vote for using default value for 'fname' instead
>> of FATAL_ERROR.
> I think that behavior would be surprising.
Not such surprising as some error in internal CMake module with no 
detail description how it can be fixed. My point is that if it will work 
in most cases then why not? Most users will not even notice this.

>
>> If something bad will happen user always can use DOWNLOAD_NAME.
>>
>> Example of the test that will fail with current version but works
>> fine with default name:
>>
>>          URL "http://tinyurl.com/jn86pmc"
> In that case one can just use DOWNLOAD_NAME.  Auto-extraction of
> the filename from the URL is a convenience for a common case, but
> in principle DOWNLOAD_NAME could always be used.
The problem with DOWNLOAD_NAME is about generalizing code. If I have 100 
ExternalProject_Add commands with such URLs then I have to add 100 
DOWNLOAD_NAME. In my case I have a bunch of templates for 
ExternalProject_Add and to introduce this feature either I have:
* test URL for the pattern in similar way CMake do and predict the fact 
that CMake will fail to extract name (not stable, what if CMake logic 
changed? DRY violation)
* force some name unconditionally like archive.tar (most of the projects 
works fine and now for no reason archives will have another names)
* add about 20-30 lines of code to core modules, for each 
ExternalProject_Add template add parsing logic and 1 line for each 
package version declaration on user side

And all this without introducing any useful features, just to suppress 
CMake error for 0.01% of cases.

Anyway I've found workaround that I will use for such URLs. According to 
my tests most of the servers ignore fragments in URL and CMake can 
extract name from them. E.g. this works:

    cmake_minimum_required(VERSION 3.5)

    include(ExternalProject)

    ExternalProject_Add(
         foo
         URL "http://tinyurl.com/jn86pmc#a.tar"
         URL_HASH SHA1=9c29c30fff99b7c1479b2e9d4926dcc3f8d364e0
         CONFIGURE_COMMAND ""
         BUILD_COMMAND ""
         INSTALL_COMMAND ""
    )

Ruslo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160706/303ae9a8/attachment.html>


More information about the cmake-developers mailing list