Boost logo

Boost :

From: Bjørn Roald (bjorn_at_[hidden])
Date: 2007-05-20 10:04:31


Bjørn Roald wrote:
> John Maddock wrote:
>
>> Bjørn Roald wrote:
>>
>>
>>> I have working code and will happily merge with 1.34.0 version of bcp
>>> and provide you a patch. Then you can use what you like, fix what
>>> you
>>> like to fix, and dump what you don't like :-)
>>>
>>>
>> OK :-)
>>
>> Cheers, John.
>>
>>
>
> Ok, I will post a patch here within 2 or 3 days.
>
I am testing a version of my bcp code merged with main cvs version of
bcp. It still has some rough edges and some TODOs, but it seems to be
working well. I still want to test some more, and clean up the TODOs
marked in the code. In addition I need to verify that I have not broken
any features in bcp. I have only tested the new features I have added.
But as of now, I hit the following problem while testing the new
--namespace option:

As I am testing against the regress tests in the 'status' directory of
the target area after running with --cvs --namespace=ost. I am hitting
a problem caused by bcp -cvs not copying all files in
"libs/numeric/ublas/test/CVS/Entries"

only these two files are copied:
/concepts.cpp/1.2/Thu Feb 2 18:43:09 2006//
/placement_new.cpp/1.8/Sun Jul 16 20:33:17 2006//

========= form of libs/numeric/ublas/test/CVS/Entries ==========
...
/Jamfile/1.5/Thu Jun 8 20:40:17 2006/-ko/
/Jamfile.v2/1.7/Thu Jun 8 20:40:17 2006/-ko/
/README/1.2/Thu Jun 8 20:24:59 2006/-ko/
/concepts.cpp/1.2/Thu Feb 2 18:43:09 2006//
/placement_new.cpp/1.8/Sun Jul 16 20:33:17 2006//
/test1.cpp/1.1/Thu Jun 8 20:40:17 2006/-kk/
/test1.hpp/1.1/Thu Jun 8 20:40:17 2006/-kk/
/test11.cpp/1.2/Sun Jul 16 20:33:17 2006/-kk/
...

======== from bcp/scan_cvs_tath.cpp =========
...
   static const boost::regex
file_expression("^(?:A\\s+)?/([^/\\n]+)/[^/\\n]*/[^/\\n]*/[^k/\\n]*(kb[^/\\n]*)?/[^/\\n]*");
...

Seems to me like the trouble is the "(kb[^/\\n]*)?" part of the regexp,
which does not match "/-kk/" or "/-ko/" part of each entry. I am not
familiar with the file format of the Entries file, so I wonder if this
is intentional?

As of the promised patch file; I am attaching a snapshot patch file of
my merged bcp sources and one new source file. You can use these to see
where I am heading. Any comments or suggestions are welcome.

Remaining known issues:

1.
Support custom file headers/footers to include in files treated with the
--namespace option. Currently a hard coded text is used.

2.
Fix logic so --unix-lines work in combination with --namespace and
--diff-mode work when --namespace is not used

3.
Special treatment, where necessary, of top level (BOOST_ROOT) jam
files: project-root.jam, Jamfile.v2, boost-build.jam. In these files
the general replace of the boost namespace is too general.

4.
Exclusion of some source from treatment of the --namespace feature all
together; e.g. too/jam/src.

5.
most lines with ending braces of boost namespace in the boost sources
seems to be marked with /* namespace boost */ or similar. Look into if
this can be a simple way of locating them and support nested namespaces.

6.
Verify that we have not broken standard bcp features.

7.
Check validity of the change in add_path.cpp seems unrelated, but I
could not find the code looking back a few versions in CVS. I guess I
had added it to avoid annoying warnings from bcp and that it does the
right thing?

I will most likely not be able to work more on this before next weekend.

-- 
Bjørn

This file contains notes regarding enhansements to BOOST_ROOT/tools/bcp
to support replacement of the boost namespace in sourcecode copied
from the boost distrubution.

==================== HOWTO ======================

A new option:

   --namespace=ns set a namespace that will replace 'boost'

is added to the bcp tool. This allow the user to specify a namespace
to use as replacement for boost in exported source code.

example use:

> cd ~/src/boost
> mkdir -p /tmp/testbcp/mylib
> tools/bcp/run/bcp -cvs -namespace=mylib filesystem /tmp/testbcp/mylib

later you can use

> tools/bcp/run/bcp -cvs --namespace=spoost --diff-only filesystem /tmp/testbcp/mylib

to only do the changes

You can add boost-build.jam Jamfile Jamrules to the module-list on the
bcp command line to get the top level build files needed to build
the exported code. If you change the following 2 lines in the exported Jamfile

        [ glob-tree $(BOOST_ROOT)/boost/compatibility/cpp_c_headers : c* ]
        [ glob-tree $(BOOST_ROOT)/boost : *.hpp *.ipp *.h *.inc ]

  to

        [ glob-tree $(BOOST_ROOT)/mylib/compatibility/cpp_c_headers : c* ]
        [ glob-tree $(BOOST_ROOT)/mylib : *.hpp *.ipp *.h *.inc ]

you can actually build the exported libraries with bjam. NOTE: see limitation
regarding Boost.Build

================== TODO =========================

1.
Support replacing namespace boost with nested namespace, e.g.

namespace boost ====> namespace mylib::boost

   or

namespace boost ====> namespace mylib::stuff::platform

2.
Better Boost.Build and Jamfile support in export

=============== LIMITATIONS ======================

1.
Only replacement of boost namespace with single level namespace
is suported. No replacement with nested namespace supported jet.

2.
Boost.Build export not suported properly. Buildfiles are still configured for
the "boost" name after export. E.g. libriaries built contain the string
"boost" in their filenames.


? bjornr_notes.txt
? replace_namespace.cpp
Index: Jamfile
===================================================================
RCS file: /cvsroot/boost/boost/tools/bcp/Jamfile,v
retrieving revision 1.3
diff -d -u -r1.3 Jamfile
--- Jamfile 16 Jul 2006 11:31:52 -0000 1.3
+++ Jamfile 20 May 2007 14:01:50 -0000
@@ -5,7 +5,8 @@
 subproject tools/bcp ;
 
 exe bcp
- : add_path.cpp bcp_imp.cpp copy_path.cpp file_types.cpp
+ : add_path.cpp bcp_imp.cpp copy_path.cpp
+ replace_namespace.cpp file_types.cpp
     fileview.cpp main.cpp path_operations.cpp scan_cvs_path.cpp
     licence_info.cpp scan_licence.cpp output_licence_info.cpp
   <lib>../../libs/filesystem/build/boost_filesystem
Index: Jamfile.v2
===================================================================
RCS file: /cvsroot/boost/boost/tools/bcp/Jamfile.v2,v
retrieving revision 1.4
diff -d -u -r1.4 Jamfile.v2
--- Jamfile.v2 16 Jul 2006 11:31:52 -0000 1.4
+++ Jamfile.v2 20 May 2007 14:01:50 -0000
@@ -7,6 +7,7 @@
     add_path.cpp bcp_imp.cpp copy_path.cpp file_types.cpp
     fileview.cpp main.cpp path_operations.cpp scan_cvs_path.cpp
     licence_info.cpp scan_licence.cpp output_licence_info.cpp
+ replace_namespace.cpp
     /boost/filesystem//boost_filesystem
     /boost/regex//boost_regex
     /boost/test//boost_prg_exec_monitor
Index: add_path.cpp
===================================================================
RCS file: /cvsroot/boost/boost/tools/bcp/add_path.cpp,v
retrieving revision 1.12
diff -d -u -r1.12 add_path.cpp
--- add_path.cpp 19 Feb 2006 16:19:02 -0000 1.12
+++ add_path.cpp 20 May 2007 14:01:50 -0000
@@ -123,6 +123,11 @@
          // or we'll get an error:
          if(s.compare(0, 2, "./") == 0)
             s.erase(0, 2);
+ //
+ // if the name contain .html# , remove the html bookmark
+ // or we'll get warnings of none existing files
+ if(s.find(".html#") != std::string::npos)
+ s.erase(s.find(".html#")+5);
          if(s.find(':') == std::string::npos)
          {
             // only concatonate if it's a relative path
Index: bcp.hpp
===================================================================
RCS file: /cvsroot/boost/boost/tools/bcp/bcp.hpp,v
retrieving revision 1.7
diff -d -u -r1.7 bcp.hpp
--- bcp.hpp 10 Feb 2006 17:11:25 -0000 1.7
+++ bcp.hpp 20 May 2007 14:01:50 -0000
@@ -21,11 +21,13 @@
    virtual void enable_summary_list_mode() = 0;
    virtual void enable_cvs_mode() = 0;
    virtual void enable_unix_lines() = 0;
+ virtual void enable_diff_only_mode() = 0;
    virtual void enable_scan_mode() = 0;
    virtual void enable_license_mode() = 0;
    virtual void enable_bsl_convert_mode() = 0;
    virtual void enable_bsl_summary_mode() = 0;
    virtual void set_boost_path(const char* p) = 0;
+ virtual void set_replacement_namespace(const char* ns) = 0;
    virtual void set_destination(const char* p) = 0;
    virtual void add_module(const char* p) = 0;
 
Index: bcp_imp.cpp
===================================================================
RCS file: /cvsroot/boost/boost/tools/bcp/bcp_imp.cpp,v
retrieving revision 1.13
diff -d -u -r1.13 bcp_imp.cpp
--- bcp_imp.cpp 10 Feb 2006 17:11:25 -0000 1.13
+++ bcp_imp.cpp 20 May 2007 14:01:51 -0000
@@ -71,6 +71,11 @@
    m_unix_lines = true;
 }
 
+void bcp_implementation::enable_diff_only_mode()
+{
+ m_diff_only_mode = true;
+}
+
 void bcp_implementation::set_boost_path(const char* p)
 {
    m_boost_path = fs::path(p, fs::native);
Index: bcp_imp.hpp
===================================================================
RCS file: /cvsroot/boost/boost/tools/bcp/bcp_imp.hpp,v
retrieving revision 1.8
diff -d -u -r1.8 bcp_imp.hpp
--- bcp_imp.hpp 10 Feb 2006 17:11:25 -0000 1.8
+++ bcp_imp.hpp 20 May 2007 14:01:51 -0000
@@ -52,11 +52,13 @@
    void enable_summary_list_mode();
    void enable_cvs_mode();
    void enable_unix_lines();
+ void enable_diff_only_mode();
    void enable_scan_mode();
    void enable_license_mode();
    void enable_bsl_convert_mode();
    void enable_bsl_summary_mode();
    void set_boost_path(const char* p);
+ void set_replacement_namespace(const char* ns);
    void set_destination(const char* p);
    void add_module(const char* p);
 
@@ -68,10 +70,15 @@
    void add_directory(const fs::path& p);
    void add_file(const fs::path& p);
    void copy_path(const fs::path& p);
+ void replace_namespace(const fs::path& p);
+ fs::path destination_path(const fs::path p, std::string seperator = "/");
    void add_file_dependencies(const fs::path& p, bool scanfile);
    bool is_source_file(const fs::path& p);
    bool is_html_file(const fs::path& p);
    bool is_binary_file(const fs::path& p);
+ bool is_bjam_file(const fs::path& p);
+ bool diff_only_copy( const std::string& new_file,
+ fs::path destination_path );
    void add_dependent_lib(const std::string& libname, const fs::path& p);
    void create_path(const fs::path& p);
    // license code:
@@ -84,6 +91,8 @@
    bool m_license_mode; // generate license information for files listed
    bool m_cvs_mode; // check cvs for files
    bool m_unix_lines; // fix line endings
+ bool m_diff_only_mode; // diff only mode
+ bool m_replace_namespace; // replace the boost namespace
    bool m_scan_mode; // scan non-boost files.
    bool m_bsl_convert_mode; // try to convert to the BSL
    bool m_bsl_summary_mode; // summarise BSL issues only
Index: copy_path.cpp
===================================================================
RCS file: /cvsroot/boost/boost/tools/bcp/copy_path.cpp,v
retrieving revision 1.4
diff -d -u -r1.4 copy_path.cpp
--- copy_path.cpp 30 Nov 2003 13:02:14 -0000 1.4
+++ copy_path.cpp 20 May 2007 14:01:51 -0000
@@ -20,35 +20,50 @@
 void bcp_implementation::copy_path(const fs::path& p)
 {
    assert(!fs::is_directory(m_boost_path / p));
- if(fs::exists(m_dest_path / p))
- {
- std::cout << "Copying (and overwriting) file: " << p.string() << "\n";
- fs::remove(m_dest_path / p);
- }
- else
- std::cout << "Copying file: " << p.string() << "\n";
+ fs::path dest_p = destination_path( p );
+
    //
    // create the path to the new file if it doesn't already exist:
    //
- create_path(p.branch_path());
+ create_path(dest_p.branch_path());
    //
    // do text based copy if requested:
    //
- if(m_unix_lines && !is_binary_file(p))
+ if(m_replace_namespace && (is_source_file(p) || is_bjam_file(p)))
    {
- std::ifstream is((m_boost_path / p).native_file_string().c_str());
- std::istreambuf_iterator<char> isi(is);
- std::istreambuf_iterator<char> end;
-
- std::ofstream os((m_dest_path / p).native_file_string().c_str(), std::ios_base::binary | std::ios_base::out);
- std::ostreambuf_iterator<char> osi(os);
-
- std::copy(isi, end, osi);
+ replace_namespace(p);
    }
    else
    {
- // binary copy:
- fs::copy_file(m_boost_path / p, m_dest_path / p);
+
+ if( fs::exists(m_dest_path / dest_p))
+ {
+ // TODO: need some support for diff mode here, for now
+ // diff_mode is only supported within replace_namespace(p);
+
+ std::cout << "Copying (and overwriting) file: " << p.string() << "\n";
+ fs::remove(m_dest_path / dest_p );
+ }
+ else
+ std::cout << "Copying file: " << p.string() << "\n";
+
+ if(m_unix_lines && !is_binary_file(p))
+ {
+ std::ifstream is((m_boost_path / p).native_file_string().c_str());
+ std::istreambuf_iterator<char> isi(is);
+ std::istreambuf_iterator<char> end;
+
+ std::ofstream os( ( m_dest_path / dest_p ).native_file_string().c_str(),
+ std::ios_base::binary | std::ios_base::out);
+ std::ostreambuf_iterator<char> osi(os);
+
+ std::copy(isi, end, osi);
+ }
+ else
+ {
+ // binary copy:
+ fs::copy_file(m_boost_path / p, m_dest_path / dest_p);
+ }
    }
 }
 
Index: file_types.cpp
===================================================================
RCS file: /cvsroot/boost/boost/tools/bcp/file_types.cpp,v
retrieving revision 1.6
diff -d -u -r1.6 file_types.cpp
--- file_types.cpp 3 Nov 2005 12:12:37 -0000 1.6
+++ file_types.cpp 20 May 2007 14:01:51 -0000
@@ -9,6 +9,7 @@
  * void bcp_implementation::is_source_file(const fs::path& p)
  * void bcp_implementation::is_html_file(const fs::path& p)
  * void bcp_implementation::is_binary_file(const fs::path& p)
+ * void bcp_implementation::is_bjam_file(const fs::path& p)
  */
 
 #include "bcp_imp.hpp"
@@ -19,8 +20,8 @@
    static const boost::regex e(
       ".*\\."
       "(?:"
- "c|cxx|h|hxx|inc|.?pp|yy?"
- ")",
+ "c|cxx|h|hxx|inl|inc|.?pp|yy?"
+ ")",
       boost::regex::perl | boost::regex::icase
       );
    return boost::regex_match(p.string(), e);
@@ -45,13 +46,27 @@
       if(pos != m_cvs_paths.end()) return pos->second;
    }
    static const boost::regex e(
- ".*\\."
+ "(.*\\."
       "(?:"
          "c|cxx|cpp|h|hxx|hpp|inc|html?|css|mak|in"
       ")"
       "|"
- "(Jamfile|makefile|configure)",
+ "(Jamfile|Jamfile\\.v2|Jamrules|Jambase|makefile|configure)",
       boost::regex::perl | boost::regex::icase);
    return !boost::regex_match(p.leaf(), e);
 
 }
+
+bool bcp_implementation::is_bjam_file(const fs::path& p)
+{
+ static const boost::regex e(
+ ".*\\."
+ "(?:"
+ "jam"
+ ")"
+ "|"
+ "(Jamfile|Jamfile\\.v2|Jamrules|Jambase)",
+ boost::regex::perl | boost::regex::icase);
+ return boost::regex_match(p.leaf(), e);
+
+}
Index: main.cpp
===================================================================
RCS file: /cvsroot/boost/boost/tools/bcp/main.cpp,v
retrieving revision 1.8
diff -d -u -r1.8 main.cpp
--- main.cpp 10 Feb 2006 17:11:25 -0000 1.8
+++ main.cpp 20 May 2007 14:01:51 -0000
@@ -33,10 +33,12 @@
       "\n"
       "Options:\n"
       " --boost=path sets the location of the boost tree to path\n"
- " --scan treat the module list as a list of (possibly non-boost)\n"
+ " --namespace=ns set namespace 'ns' that will replace 'boost'\n"
+ " --scan treat the module list as a list of (possibly non-boost)\n"
       " files to scan for boost dependencies\n"
       " --cvs only copy files under cvs version control\n"
       " --unix-lines make sure that all copied files use Unix style line endings\n"
+ " --diff-only only overwrite files when new file differs from existing original\n"
       "\n"
       "module-list: a list of boost files or library names to copy\n"
       "html-file: the name of a html file to which the report will be written\n"
@@ -123,12 +125,21 @@
       {
          papp->enable_unix_lines();
       }
+ else if(0 == std::strcmp("--diff-only", argv[i]))
+ {
+ papp->enable_diff_only_mode();
+ }
       else if(0 == std::strncmp("--boost=", argv[i], 8))
       {
          papp->set_boost_path(argv[i] + 8);
       }
+ else if(0 == std::strncmp("--namespace=", argv[i], 12))
+ {
+ papp->set_replacement_namespace(argv[i] + 12);
+ }
       else if(argv[i][0] == '-')
       {
+ std::cout << "wrong argument: " << argv[i] << std::endl;
          show_usage();
          return 1;
       }
Index: scan_cvs_path.cpp
===================================================================
RCS file: /cvsroot/boost/boost/tools/bcp/scan_cvs_path.cpp,v
retrieving revision 1.4
diff -d -u -r1.4 scan_cvs_path.cpp
--- scan_cvs_path.cpp 3 Nov 2005 12:12:37 -0000 1.4
+++ scan_cvs_path.cpp 20 May 2007 14:01:51 -0000
@@ -29,7 +29,7 @@
    static const boost::regex dir_expression("^(?:A\\s+)?D/([^/\\n]+)/");
    static const int file_subs[] = {1,2,};
 
- for(int entry = 0; entry < sizeof(file_list)/sizeof(file_list[0]); ++entry)
+ for(unsigned int entry = 0; entry < sizeof(file_list)/sizeof(file_list[0]); ++entry)
    {
       fs::path entries(m_boost_path / p / file_list[entry]);
       if(fs::exists(entries))



Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk