Skip to content

Commit

Permalink
get rid of hard-coded paths with <filesystem> (#360)
Browse files Browse the repository at this point in the history
* put common #includes for PCH in a single file

* build check_valid_six

* use EXIT_* rather than 0/1

* getting rid of std::auto_ptr<> because it's gone in C++17

* build all projects with C++17

* use <filesystem> to remove hard-coded paths

* in Visual Studio, run check_valid_six with a pre-defined path

* tweak plugin dir
  • Loading branch information
J. Daniel Smith authored Oct 17, 2020
1 parent 165fb1d commit 67ee284
Show file tree
Hide file tree
Showing 16 changed files with 590 additions and 317 deletions.
34 changes: 6 additions & 28 deletions Test/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,37 +45,11 @@
#pragma warning(push)
#pragma warning(disable: 5220) // '...': a non - static data member with a volatile qualified type no longer implies
#pragma warning(disable: 5204) // 'Concurrency::details::_DefaultPPLTaskScheduler': class has virtual functions, but its trivial destructor is not virtual; instances of objects derived from this class may not be destructed correctly
#include <assert.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdarg.h>
#include <ctype.h>
#include <time.h>
#include <stdint.h>

#include <string>
#include <numeric>
#include <limits>
#include <memory>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <ios>
#include <iomanip>
#include <vector>
#include <map>
#include <utility>
#include <functional>
#include <mutex>
#include <atomic>
#include <future>

#include "six/modules/c++/cpp_pch.h"

#include <sys/File.h>

#include <windows.h>
#undef min
#undef max
#pragma warning(pop)

#include <sys/Conf.h>
Expand All @@ -100,6 +74,10 @@

#include <import/scene.h>
#include <import/six.h>
#include <import./six/sicd.h>
#include <import./six/sidd.h>
#include <import/cphd.h>
#include <import/cphd03.h>

#pragma comment(lib, "ws2_32")

Expand Down
98 changes: 95 additions & 3 deletions Test/six.sidd_test_read_sidd_legend.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,105 @@
#include "pch.h"

#include <filesystem>

#include "sidd_Test.h"

namespace fs = std::filesystem;

static bool is_x64_Configuration(const fs::path& path) // "Configuration" is typically "Debug" or "Release"
{
const std::string build_configuration =
#if defined(NDEBUG) // i.e., release
"Release";
#else
"Debug";
#endif

const auto Configuration = path.filename();
const auto path_parent_path = path.parent_path();
const auto x64 = path_parent_path.filename();
return (Configuration == build_configuration) && (x64 == "x64");
}

static bool is_install_unittests(const fs::path& path)
{
const auto unittests = path.filename();
const auto path_parent_path = path.parent_path();
const auto install = path_parent_path.filename();
return (unittests == "unittests") && (install == "install");
}
static bool is_install_tests(const fs::path& path)
{
const auto tests = path.filename();
const auto path_parent_path = path.parent_path();
const auto install = path_parent_path.filename();
return (tests == "tests") && (install == "install");
}

static fs::path buildSchemaDir()
{
const auto cwd = fs::current_path();

const sys::OS os;
const auto exec = fs::path(os.getCurrentExecutable());
const auto argv0 = exec.filename();
if (argv0 == "Test.exe")
{
// Running GTest unit-tests in Visual Studio on Windows
if (is_x64_Configuration(cwd))
{
const auto root_path = cwd.parent_path().parent_path();
return root_path / "six" / "modules" / "c++" / "six.sidd" / "conf" / "schema";
}
}

if (argv0 == "unittests.exe")
{
// stand-alone unittest executable on Windows (ends in .EXE)
const auto parent_path = exec.parent_path();
if (is_x64_Configuration(parent_path))
{
const auto parent_path_ = parent_path.parent_path().parent_path();
return parent_path_ / "dev" / "tests" / "images";
}
}

// stand-alone unit-test on Linux
const auto exec_dir = exec.parent_path();
if (is_install_unittests(exec_dir))
{
const auto install = exec_dir.parent_path();
return install / "unittests" / "data";
}
if (is_install_tests(exec_dir))
{
const auto install = exec_dir.parent_path();
return install / "unittests" / "data";
}

if (argv0 == "unittests")
{
// stand-alone unittest executable on Linux
const auto bin = exec.parent_path();
if (bin.filename() == "bin")
{
const auto unittests = bin.parent_path();
return unittests / "unittests" / "data";
}
}

//fprintf(stderr, "cwd = %s\n", cwd.c_str());
//fprintf(stderr, "exec = %s\n", exec.c_str());

return cwd;
}

struct sidd_test_read_sidd_legend : public ::testing::Test {
sidd_test_read_sidd_legend() {
// initialization code here
const std::string SIX_SCHEMA_PATH = R"(C:\Users\jdsmith\source\repos\six\six\modules\c++\six.sidd\conf\schema)";
const std::string putenv_ = "SIX_SCHEMA_PATH=" + SIX_SCHEMA_PATH;

//const std::string SIX_SCHEMA_PATH = R"(C:\Users\jdsmith\source\repos\six\six\modules\c++\six.sidd\conf\schema)";
const auto SIX_SCHEMA_PATH = buildSchemaDir();
const std::string putenv_ = "SIX_SCHEMA_PATH=" + SIX_SCHEMA_PATH.string();
_putenv(putenv_.c_str());
}

Expand Down
15 changes: 15 additions & 0 deletions six.sln
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Test\Test.vcxproj",
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XML_DATA_CONTENT", "externals\nitro\modules\c\nitf\XML_DATA_CONTENT.vcxproj", "{78849481-D356-4CC7-B182-31C21F857ED1}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3AD152C2-1F3D-4108-826C-79BA5011874F}"
ProjectSection(SolutionItems) = preProject
six\modules\c++\cpp_pch.h = six\modules\c++\cpp_pch.h
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "check_valid_six", "six\modules\c++\samples\check_valid_six\check_valid_six.vcxproj", "{F0E2C8FF-57D4-4331-9BD2-76FF01CB54EB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand Down Expand Up @@ -101,6 +108,14 @@ Global
{78849481-D356-4CC7-B182-31C21F857ED1}.Release|x64.ActiveCfg = Release|x64
{78849481-D356-4CC7-B182-31C21F857ED1}.Release|x64.Build.0 = Release|x64
{78849481-D356-4CC7-B182-31C21F857ED1}.Release|x86.ActiveCfg = Release|x64
{F0E2C8FF-57D4-4331-9BD2-76FF01CB54EB}.Debug|x64.ActiveCfg = Debug|x64
{F0E2C8FF-57D4-4331-9BD2-76FF01CB54EB}.Debug|x64.Build.0 = Debug|x64
{F0E2C8FF-57D4-4331-9BD2-76FF01CB54EB}.Debug|x86.ActiveCfg = Debug|Win32
{F0E2C8FF-57D4-4331-9BD2-76FF01CB54EB}.Debug|x86.Build.0 = Debug|Win32
{F0E2C8FF-57D4-4331-9BD2-76FF01CB54EB}.Release|x64.ActiveCfg = Release|x64
{F0E2C8FF-57D4-4331-9BD2-76FF01CB54EB}.Release|x64.Build.0 = Release|x64
{F0E2C8FF-57D4-4331-9BD2-76FF01CB54EB}.Release|x86.ActiveCfg = Release|Win32
{F0E2C8FF-57D4-4331-9BD2-76FF01CB54EB}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
30 changes: 2 additions & 28 deletions six/modules/c++/cphd/framework.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,37 +42,11 @@
#pragma warning(push)
#pragma warning(disable: 5220) // '...': a non - static data member with a volatile qualified type no longer implies
#pragma warning(disable: 5204) // 'Concurrency::details::_DefaultPPLTaskScheduler': class has virtual functions, but its trivial destructor is not virtual; instances of objects derived from this class may not be destructed correctly
#include <assert.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdarg.h>
#include <ctype.h>
#include <time.h>
#include <stdint.h>

#include <string>
#include <numeric>
#include <limits>
#include <memory>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <ios>
#include <iomanip>
#include <vector>
#include <map>
#include <utility>
#include <functional>
#include <mutex>
#include <atomic>
#include <future>

#include "../../cpp_pch.h"

#include <sys/File.h>

#include <windows.h>
#undef min
#undef max
#pragma warning(pop)

#include <sys/Conf.h>
Expand Down
30 changes: 2 additions & 28 deletions six/modules/c++/cphd03/framework.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,37 +42,11 @@
#pragma warning(push)
#pragma warning(disable: 5220) // '...': a non - static data member with a volatile qualified type no longer implies
#pragma warning(disable: 5204) // 'Concurrency::details::_DefaultPPLTaskScheduler': class has virtual functions, but its trivial destructor is not virtual; instances of objects derived from this class may not be destructed correctly
#include <assert.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdarg.h>
#include <ctype.h>
#include <time.h>
#include <stdint.h>

#include <string>
#include <numeric>
#include <limits>
#include <memory>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <ios>
#include <iomanip>
#include <vector>
#include <map>
#include <utility>
#include <functional>
#include <mutex>
#include <atomic>
#include <future>

#include "../../cpp_pch.h"

#include <sys/File.h>

#include <windows.h>
#undef min
#undef max
#pragma warning(pop)

#include <sys/Conf.h>
Expand Down
38 changes: 38 additions & 0 deletions six/modules/c++/cpp_pch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once

#pragma warning(push)
#pragma warning(disable: 5220) // '...': a non - static data member with a volatile qualified type no longer implies
#pragma warning(disable: 5204) // 'Concurrency::details::_DefaultPPLTaskScheduler': class has virtual functions, but its trivial destructor is not virtual; instances of objects derived from this class may not be destructed correctly
#include <assert.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdarg.h>
#include <ctype.h>
#include <time.h>
#include <stdint.h>
#include <stddef.h>

#include <string>
#include <numeric>
#include <limits>
#include <memory>
#include <algorithm>
#include <sstream>
#include <ostream>
#include <iostream>
#include <ios>
#include <iomanip>
#include <vector>
#include <map>
#include <utility>
#include <functional>
#include <mutex>
#include <atomic>
#include <future>
#include <complex>

#include <windows.h>
#undef min
#undef max
#pragma warning(pop)
Loading

0 comments on commit 67ee284

Please sign in to comment.